Skip to content

Instantly share code, notes, and snippets.

@liesen
Created July 13, 2010 18:10
Show Gist options
  • Save liesen/474269 to your computer and use it in GitHub Desktop.
Save liesen/474269 to your computer and use it in GitHub Desktop.
draft of a js api for libspotify
/**
* @namespace
*/
spotify = {};
/**
* @enum {number}
*/
spotify.Error = {
OK: 0,
BAD_API_VERSION: 1,
API_INITIALIZATION_FAILED: 2
};
/**
* @interface
*/
spotify.Resource;
/**
* @type {boolean}
*/
spotify.Resource.prototype.isLoaded;
/**
* @type {?string}
*/
spotify.Resource.prototype.name;
/**
* @interface
* @implements {spotify.Resource}
*/
spotify.MediaResource;
/**
* @field
* @const
* @type {!boolean}
*/
spotify.MediaResource.prototype.isAvailable;
/**
* @interface
* @implements {spotify.MediaResource}
*/
spotify.Artist;
/**
* @interface
* @implements {spotify.MediaResource}
*/
spotify.Track;
/**
* @field
* @const
* @type {!spotify.Error}
*/
spotify.Track.prototype.error;
/**
* @field
* @const
* @type {!Array.<spotify.Artist>}
*/
spotify.Track.prototype.artists;
/**
* @field
* @const
* @type {!boolean}
*/
spotify.Track.prototype.album;
/**
* @field
* @const
* @type {!number}
*/
spotify.Track.prototype.duration;
/**
* @field
* @const
* @type {!number}
*/
spotify.Track.prototype.popularity;
/**
* @field
* @const
* @type {!number}
*/
spotify.Track.prototype.disc;
/**
* @field
* @const
* @type {!number}
*/
spotify.Track.prototype.index;
/**
* @interface
* @implements {spotify.Resource}
*/
spotify.Playlist;
/**
* @field
* @const
* @type {!Object}
*/
spotify.Playlist.prototype.owner;
/**
* @field
* @const
* @type {!boolean}
*/
spotify.Playlist.prototype.hasPendingChanges;
/**
* @field
* @type {string}
*/
spotify.Playlist.prototype.name;
/**
* @field
* @type {!boolean}
*/
spotify.Playlist.prototype.collaborative;
/**
* @field
* @type {!Array.<spotify.Track>}
*/
spotify.Playlist.prototype.tracks;
/**
* @interface
*/
spotify.PlaylistContainer;
/**
* @enum {!string}
*/
spotify.PlaylistContainer.Events = {
PLAYLIST_ADDED: "playlist_added",
PLAYLIST_REMOVED: "playlist_removed",
PLAYLIST_MOVED: "playlist_moved",
CONTAINER_LOADED: "container_loaded"
};
/**
* @type {!Array.<spotify.Playlist>}
*/
spotify.PlaylistContainer.prototype.playlists;
/**
* @param {!spotify.PlaylistContainer.Events} event
*/
spotify.PlaylistContainer.prototype.addListener = function(event) {};
/**
* @enum {!number}
*/
spotify.ConnectionState = {
LOGGED_IN: 0,
LOGGED_OUT: 1,
DISCONNECTED: 2,
UNDEFINED: 3
};
/**
* @interface
*/
spotify.Session;
/**
* @enum {!string}
*/
spotify.Session.Events = {
LOGGED_OUT: "logged_out",
METADATA_UPDATED: "metadata_updated",
CONNECTION_ERROR: "connection_error",
MESSAGE_TO_USER: "message_to_user",
LOG_MESSAGE: "log_message"
};
/**
* @field
* @const
* @type {Object} The user
*/
spotify.Session.prototype.user;
/**
* @field
* @const
* @type {!spotify.ConnectionState}
*/
spotify.Session.prototype.connectionState;
/**
* @param {!spotify.Session} session
*/
spotify.Session.prototype.logout = function(session) {};
/**
* @param {!string} event
* @param {!function(!spotify.Session)} callback
*/
spotify.Session.prototype.addListener = function(event, callback) {};
/**
* @param {spotify.Session} session
* @param {spotify.PlaylistContainer} playlistContainer
*/
spotify.Session.prototype.playlistContainer = function(session, playlistContainer) {};
/**
* @interface
*/
spotify.Spotify;
/**
* @static
* @param {!string} application_key Application key
* @return {spotify.LoginFunction} Spotify login function
*/
spotify.withApplicationKey = function(application_key) {};
/**
* @typedef {function(string,
* string,
* function(spotify.Session),
* function(spotify.Error)}
*/
// @param {!string} username
// @param {!string} password
// @param {function(spotify.Error)} onError Function called on error
// @param {function(spotify.Session)} onSession Function called on successful login
spotify.LoginFunction;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment