diff options
| author | Eric Reed <ebr@mediabrowser3.com> | 2013-04-22 11:27:23 -0400 |
|---|---|---|
| committer | Eric Reed <ebr@mediabrowser3.com> | 2013-04-22 11:27:23 -0400 |
| commit | 49cc12c4f56ceb51d1e03d405146ab2112411122 (patch) | |
| tree | c0076d970df935a724c1ad1b7fbfb9800d0682e3 /MediaBrowser.WebDashboard/ApiClient.js | |
| parent | 8aa9a5ec63ff6c744c456bd0a2bb11d9da5b74e6 (diff) | |
| parent | a55999b780367dfa344bb0dfc754b5172b0b195a (diff) | |
Merge branch 'master' of https://github.com/MediaBrowser/MediaBrowser
Diffstat (limited to 'MediaBrowser.WebDashboard/ApiClient.js')
| -rw-r--r-- | MediaBrowser.WebDashboard/ApiClient.js | 364 |
1 files changed, 321 insertions, 43 deletions
diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index fe676abaf..759fb0dc4 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/ApiClient.js @@ -862,13 +862,19 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { /** * Gets a studio */ - self.getStudio = function (name) { + self.getStudio = function (name, userId) { if (!name) { throw new Error("null name"); } - var url = self.getUrl("Studios/" + encodeName(name)); + var options = {}; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("Studios/" + encodeName(name), options); return self.ajax({ type: "GET", @@ -880,13 +886,43 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { /** * Gets a genre */ - self.getGenre = function (name) { + self.getGenre = function (name, userId) { if (!name) { throw new Error("null name"); } - var url = self.getUrl("Genres/" + encodeName(name)); + var options = {}; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("Genres/" + encodeName(name), options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + + /** + * Gets an artist + */ + self.getArtist = function (name, userId) { + + if (!name) { + throw new Error("null name"); + } + + var options = {}; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("Artists/" + encodeName(name), options); return self.ajax({ type: "GET", @@ -898,13 +934,19 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { /** * Gets a year */ - self.getYear = function (year) { + self.getYear = function (yea, userId) { - if (!year) { - throw new Error("null year"); + if (!name) { + throw new Error("null name"); + } + + var options = {}; + + if (userId) { + options.userId = userId; } - var url = self.getUrl("Years/" + year); + var url = self.getUrl("Years/" + encodeName(name), options); return self.ajax({ type: "GET", @@ -916,13 +958,19 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { /** * Gets a Person */ - self.getPerson = function (name) { + self.getPerson = function (name, userId) { if (!name) { throw new Error("null name"); } - var url = self.getUrl("Persons/" + encodeName(name)); + var options = {}; + + if (userId) { + options.userId = userId; + } + + var url = self.getUrl("Persons/" + encodeName(name), options); return self.ajax({ type: "GET", @@ -1132,6 +1180,41 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** + * Constructs a url for a artist image + * @param {String} name + * @param {Object} options + * Options supports the following properties: + * width - download the image at a fixed width + * height - download the image at a fixed height + * maxWidth - download the image at a maxWidth + * maxHeight - download the image at a maxHeight + * quality - A scale of 0-100. This should almost always be omitted as the default will suffice. + * For best results do not specify both width and height together, as aspect ratio might be altered. + */ + self.getArtistImageUrl = function (name, options) { + + if (!name) { + throw new Error("null name"); + } + + options = options || { + + }; + + var url = "Artists/" + encodeName(name) + "/Images/" + options.type; + + if (options.index != null) { + url += "/" + options.index; + } + + // Don't put these on the query string + delete options.type; + delete options.index; + + return self.getUrl(url, options); + }; + + /** * Constructs a url for a studio image * @param {String} name * @param {Object} options @@ -1525,6 +1608,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** + Gets artists from an item + */ + self.getArtists = function (userId, options) { + + if (!userId) { + throw new Error("null userId"); + } + + options = options || {}; + options.userId = userId; + + var url = self.getUrl("Artists", options); + + return self.ajax({ + type: "GET", + url: url, + dataType: "json" + }); + }; + + /** Gets genres from an item */ self.getGenres = function (userId, options) { @@ -1533,12 +1637,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null userId"); } - var parentId = options.parentId || "root"; - - // Don't put these on the query string - delete options.parentId; + options = options || {}; + options.userId = userId; - var url = self.getUrl("Users/" + userId + "/Items/" + parentId + "/Genres", options); + var url = self.getUrl("Genres", options); return self.ajax({ type: "GET", @@ -1556,12 +1658,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null userId"); } - var parentId = options.parentId || "root"; - - // Don't put these on the query string - delete options.parentId; + options = options || {}; + options.userId = userId; - var url = self.getUrl("Users/" + userId + "/Items/" + parentId + "/Persons", options); + var url = self.getUrl("Persons", options); return self.ajax({ type: "GET", @@ -1579,12 +1679,10 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null userId"); } - var parentId = options.parentId || "root"; - - // Don't put these on the query string - delete options.parentId; + options = options || {}; + options.userId = userId; - var url = self.getUrl("Users/" + userId + "/Items/" + parentId + "/Studios", options); + var url = self.getUrl("Studios", options); return self.ajax({ type: "GET", @@ -1722,7 +1820,67 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { * @param {String} name * @param {Boolean} isFavorite */ - self.updateItemByNameFavoriteStatus = function (userId, name, isFavorite) { + self.updateFavoriteArtistStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Favorites/Artists/" + encodeName(name)); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url + }); + }; + + self.updateFavoritePersonStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Favorites/Persons/" + encodeName(name)); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url + }); + }; + + self.updateFavoriteStudioStatus = function (userId, name, isFavorite) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Favorites/Studios/" + encodeName(name)); + + var method = isFavorite ? "POST" : "DELETE"; + + return self.ajax({ + type: method, + url: url + }); + }; + + self.updateFavoriteGenreStatus = function (userId, name, isFavorite) { if (!userId) { throw new Error("null userId"); @@ -1732,7 +1890,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/ItemsByName/Favorites/" + encodeName(name)); + var url = self.getUrl("Users/" + userId + "/Favorites/Genres/" + encodeName(name)); var method = isFavorite ? "POST" : "DELETE"; @@ -1748,7 +1906,27 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { * @param {String} name * @param {Boolean} likes */ - self.updateItemByNameRating = function (userId, name, likes) { + self.updateArtistRating = function (userId, name, likes) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Artists/" + encodeName(name), { + likes: likes + }); + + return self.ajax({ + type: "POST", + url: url + }); + }; + + self.updatePersonRating = function (userId, name, likes) { if (!userId) { throw new Error("null userId"); @@ -1758,7 +1936,47 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/ItemsByName/" + encodeName(name) + "/Rating", { + var url = self.getUrl("Users/" + userId + "/Ratings/Persons/" + encodeName(name), { + likes: likes + }); + + return self.ajax({ + type: "POST", + url: url + }); + }; + + self.updateStudioRating = function (userId, name, likes) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Studios/" + encodeName(name), { + likes: likes + }); + + return self.ajax({ + type: "POST", + url: url + }); + }; + + self.updateGenreRating = function (userId, name, likes) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Genres/" + encodeName(name), { likes: likes }); @@ -1773,7 +1991,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { * @param {String} userId * @param {String} name */ - self.clearItemByNameRating = function (userId, name) { + self.clearArtistRating = function (userId, name) { if (!userId) { throw new Error("null userId"); @@ -1783,7 +2001,61 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/ItemsByName/" + encodeName(name) + "/Rating"); + var url = self.getUrl("Users/" + userId + "/Ratings/Artists/" + encodeName(name)); + + return self.ajax({ + type: "DELETE", + url: url + }); + }; + + self.clearPersonRating = function (userId, name) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Persons/" + encodeName(name)); + + return self.ajax({ + type: "DELETE", + url: url + }); + }; + + self.clearStudioRating = function (userId, name) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Studios/" + encodeName(name)); + + return self.ajax({ + type: "DELETE", + url: url + }); + }; + + self.clearGenreRating = function (userId, name) { + + if (!userId) { + throw new Error("null userId"); + } + + if (!name) { + throw new Error("null name"); + } + + var url = self.getUrl("Users/" + userId + "/Ratings/Genres/" + encodeName(name)); return self.ajax({ type: "DELETE", @@ -1792,11 +2064,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** - * Gets the full user data object for an item by name. - * @param {String} userId - * @param {String} name + Gets a variety of item counts that a person appears in */ - self.getItembyNameUserData = function (userId, name) { + self.getPersonItemCounts = function (userId, name) { if (!userId) { throw new Error("null userId"); @@ -1806,7 +2076,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/ItemsByName/" + encodeName(name) + "/UserData"); + var url = self.getUrl("Persons/" + encodeName(name) + "/Counts", { + userId: userId + }); return self.ajax({ type: "GET", @@ -1816,9 +2088,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** - Gets a variety of item counts that a person appears in + Gets a variety of item counts that a genre appears in */ - self.getPersonItemCounts = function (userId, name) { + self.getGenreItemCounts = function (userId, name) { if (!userId) { throw new Error("null userId"); @@ -1828,7 +2100,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/Persons/" + encodeName(name) + "/Counts"); + var url = self.getUrl("Genres/" + encodeName(name) + "/Counts", { + userId: userId + }); return self.ajax({ type: "GET", @@ -1838,9 +2112,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { }; /** - Gets a variety of item counts that a genre appears in + Gets a variety of item counts that an artist appears in */ - self.getGenreItemCounts = function (userId, name) { + self.getArtistItemCounts = function (userId, name) { if (!userId) { throw new Error("null userId"); @@ -1850,7 +2124,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/Genres/" + encodeName(name) + "/Counts"); + var url = self.getUrl("Artists/" + encodeName(name) + "/Counts", { + userId: userId + }); return self.ajax({ type: "GET", @@ -1872,7 +2148,9 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) { throw new Error("null name"); } - var url = self.getUrl("Users/" + userId + "/Studios/" + encodeName(name) + "/Counts"); + var url = self.getUrl("Studios/" + encodeName(name) + "/Counts", { + userId: userId + }); return self.ajax({ type: "GET", |
