From 89b9b310271ee82a55501f940f2a87b6da3ac020 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 2 Jun 2013 20:21:35 -0400 Subject: [PATCH] Added IApiClient to the model --- MediaBrowser.Model/ApiClient/IApiClient.cs | 614 +++++++++++++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 17 +- MediaBrowser.Model/packages.config | 3 + MediaBrowser.ServerApplication/App.config | 8 + 4 files changed, 641 insertions(+), 1 deletion(-) create mode 100644 MediaBrowser.Model/ApiClient/IApiClient.cs diff --git a/MediaBrowser.Model/ApiClient/IApiClient.cs b/MediaBrowser.Model/ApiClient/IApiClient.cs new file mode 100644 index 000000000..c7d584f81 --- /dev/null +++ b/MediaBrowser.Model/ApiClient/IApiClient.cs @@ -0,0 +1,614 @@ +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Dto; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.Plugins; +using MediaBrowser.Model.Querying; +using MediaBrowser.Model.Serialization; +using MediaBrowser.Model.Session; +using MediaBrowser.Model.System; +using MediaBrowser.Model.Tasks; +using MediaBrowser.Model.Weather; +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; + +namespace MediaBrowser.ApiInteraction +{ + public interface IApiClient : IDisposable + { + /// + /// Gets an image stream based on a url + /// + /// The URL. + /// Task{Stream}. + /// url + Task GetImageStreamAsync(string url); + + /// + /// Gets a BaseItem + /// + /// The id. + /// The user id. + /// Task{BaseItemDto}. + /// id + Task GetItemAsync(string id, string userId); + + /// + /// Gets the intros async. + /// + /// The item id. + /// The user id. + /// Task{System.String[]}. + /// id + Task GetIntrosAsync(string itemId, string userId); + + /// + /// Gets a BaseItem + /// + /// The user id. + /// Task{BaseItemDto}. + /// userId + Task GetRootFolderAsync(string userId); + + /// + /// Gets all Users + /// + /// Task{UserDto[]}. + Task GetAllUsersAsync(); + + /// + /// Gets active client sessions. + /// + /// Task{SessionInfoDto[]}. + Task GetClientSessionsAsync(); + + /// + /// Queries for items + /// + /// The query. + /// Task{ItemsResult}. + /// query + Task GetItemsAsync(ItemQuery query); + + /// + /// Gets the people async. + /// + /// The query. + /// Task{ItemsResult}. + /// userId + Task GetPeopleAsync(PersonsQuery query); + + /// + /// Gets the artists. + /// + /// The query. + /// Task{ItemsResult}. + /// userId + Task GetArtistsAsync(ArtistsQuery query); + + /// + /// Gets a studio + /// + /// The name. + /// Task{BaseItemDto}. + /// userId + Task GetStudioAsync(string name); + + /// + /// Gets a genre + /// + /// The name. + /// Task{BaseItemDto}. + /// userId + Task GetGenreAsync(string name); + + /// + /// Gets the artist async. + /// + /// The name. + /// Task{BaseItemDto}. + /// name + Task GetArtistAsync(string name); + + /// + /// Restarts the kernel or the entire server if necessary + /// If the server application is restarting this request will fail to return, even if + /// the operation is successful. + /// + /// Task. + Task PerformPendingRestartAsync(); + + /// + /// Gets the system status async. + /// + /// Task{SystemInfo}. + Task GetSystemInfoAsync(); + + /// + /// Gets a person + /// + /// The name. + /// Task{BaseItemDto}. + /// userId + Task GetPersonAsync(string name); + + /// + /// Gets a year + /// + /// The year. + /// Task{BaseItemDto}. + /// userId + Task GetYearAsync(int year); + + /// + /// Gets a list of plugins installed on the server + /// + /// Task{PluginInfo[]}. + Task GetInstalledPluginsAsync(); + + /// + /// Gets the current server configuration + /// + /// Task{ServerConfiguration}. + Task GetServerConfigurationAsync(); + + /// + /// Gets the scheduled tasks. + /// + /// Task{TaskInfo[]}. + Task GetScheduledTasksAsync(); + + /// + /// Gets the scheduled task async. + /// + /// The id. + /// Task{TaskInfo}. + /// id + Task GetScheduledTaskAsync(Guid id); + + /// + /// Gets a user by id + /// + /// The id. + /// Task{UserDto}. + /// id + Task GetUserAsync(string id); + + /// + /// Gets the parental ratings async. + /// + /// Task{List{ParentalRating}}. + Task> GetParentalRatingsAsync(); + + /// + /// Gets weather information for the default location as set in configuration + /// + /// Task{WeatherInfo}. + Task GetWeatherInfoAsync(); + + /// + /// Gets weather information for a specific location + /// Location can be a US zipcode, or "city,state", "city,state,country", "city,country" + /// It can also be an ip address, or "latitude,longitude" + /// + /// The location. + /// Task{WeatherInfo}. + /// location + Task GetWeatherInfoAsync(string location); + + /// + /// Gets local trailers for an item + /// + /// The user id. + /// The item id. + /// Task{ItemsResult}. + /// query + Task GetLocalTrailersAsync(string userId, string itemId); + + /// + /// Gets special features for an item + /// + /// The user id. + /// The item id. + /// Task{BaseItemDto[]}. + /// userId + Task GetSpecialFeaturesAsync(string userId, string itemId); + + /// + /// Gets the cultures async. + /// + /// Task{CultureDto[]}. + Task GetCulturesAsync(); + + /// + /// Gets the countries async. + /// + /// Task{CountryInfo[]}. + Task GetCountriesAsync(); + + /// + /// Marks an item as played or unplayed. + /// This should not be used to update playstate following playback. + /// There are separate playstate check-in methods for that. This should be used for a + /// separate option to reset playstate. + /// + /// The item id. + /// The user id. + /// if set to true [was played]. + /// Task. + /// itemId + Task UpdatePlayedStatusAsync(string itemId, string userId, bool wasPlayed); + + /// + /// Updates the favorite status async. + /// + /// The item id. + /// The user id. + /// if set to true [is favorite]. + /// Task. + /// itemId + Task UpdateFavoriteStatusAsync(string itemId, string userId, bool isFavorite); + + /// + /// Reports to the server that the user has begun playing an item + /// + /// The item id. + /// The user id. + /// Task{UserItemDataDto}. + /// itemId + Task ReportPlaybackStartAsync(string itemId, string userId); + + /// + /// Reports playback progress to the server + /// + /// The item id. + /// The user id. + /// The position ticks. + /// if set to true [is paused]. + /// Task{UserItemDataDto}. + /// itemId + Task ReportPlaybackProgressAsync(string itemId, string userId, long? positionTicks, bool isPaused); + + /// + /// Reports to the server that the user has stopped playing an item + /// + /// The item id. + /// The user id. + /// The position ticks. + /// Task{UserItemDataDto}. + /// itemId + Task ReportPlaybackStoppedAsync(string itemId, string userId, long? positionTicks); + + /// + /// Instructs antoher client to browse to a library item. + /// + /// The session id. + /// The id of the item to browse to. + /// The name of the item to browse to. + /// The type of the item to browse to. + /// Optional ui context (movies, music, tv, games, etc). The client is free to ignore this. + /// Task. + Task SendBrowseCommandAsync(string sessionId, string itemId, string itemName, string itemType, string context); + + /// + /// Sends the play command async. + /// + /// The session id. + /// The request. + /// Task. + /// + /// sessionId + /// or + /// request + /// + Task SendPlayCommandAsync(string sessionId, PlayRequest request); + + /// + /// Clears a user's rating for an item + /// + /// The item id. + /// The user id. + /// Task{UserItemDataDto}. + /// itemId + Task ClearUserItemRatingAsync(string itemId, string userId); + + /// + /// Updates a user's rating for an item, based on likes or dislikes + /// + /// The item id. + /// The user id. + /// if set to true [likes]. + /// Task. + /// itemId + Task UpdateUserItemRatingAsync(string itemId, string userId, bool likes); + + /// + /// Authenticates a user and returns the result + /// + /// The user id. + /// The sha1 hash. + /// Task. + /// userId + Task AuthenticateUserAsync(string userId, byte[] sha1Hash); + + /// + /// Updates the server configuration async. + /// + /// The configuration. + /// Task. + /// configuration + Task UpdateServerConfigurationAsync(ServerConfiguration configuration); + + /// + /// Updates the scheduled task triggers. + /// + /// The id. + /// The triggers. + /// Task{RequestResult}. + /// id + Task UpdateScheduledTaskTriggersAsync(Guid id, TaskTriggerInfo[] triggers); + + /// + /// Gets the display preferences. + /// + /// The id. + /// Task{BaseItemDto}. + Task GetDisplayPreferencesAsync(string id); + + /// + /// Updates display preferences for a user + /// + /// The id. + /// The display preferences. + /// Task{DisplayPreferences}. + /// userId + Task UpdateDisplayPreferencesAsync(DisplayPreferences displayPreferences); + + /// + /// Posts a set of data to a url, and deserializes the return stream into T + /// + /// + /// The URL. + /// The args. + /// Task{``0}. + Task PostAsync(string url, Dictionary args) + where T : class; + + /// + /// This is a helper around getting a stream from the server that contains serialized data + /// + /// The URL. + /// Task{Stream}. + Task GetSerializedStreamAsync(string url); + + /// + /// Gets the json serializer. + /// + /// The json serializer. + IJsonSerializer JsonSerializer { get; set; } + + /// + /// Gets or sets the server host name (myserver or 192.168.x.x) + /// + /// The name of the server host. + string ServerHostName { get; set; } + + /// + /// Gets or sets the port number used by the API + /// + /// The server API port. + int ServerApiPort { get; set; } + + /// + /// Gets or sets the type of the client. + /// + /// The type of the client. + string ClientName { get; set; } + + /// + /// Gets or sets the name of the device. + /// + /// The name of the device. + string DeviceName { get; set; } + + /// + /// Gets or sets the device id. + /// + /// The device id. + string DeviceId { get; set; } + + /// + /// Gets or sets the current user id. + /// + /// The current user id. + string CurrentUserId { get; set; } + + /// + /// Gets the image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The Id of the item + /// The options. + /// System.String. + /// itemId + string GetImageUrl(string itemId, ImageOptions options); + + /// + /// Gets the user image URL. + /// + /// The user. + /// The options. + /// System.String. + /// user + string GetUserImageUrl(UserDto user, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The Id of the user + /// The options. + /// System.String. + /// userId + string GetUserImageUrl(string userId, ImageOptions options); + + /// + /// Gets the person image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetPersonImageUrl(BaseItemPerson item, ImageOptions options); + + /// + /// Gets the person image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetPersonImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name of the person + /// The options. + /// System.String. + /// name + string GetPersonImageUrl(string name, ImageOptions options); + + /// + /// Gets the year image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetYearImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The year. + /// The options. + /// System.String. + string GetYearImageUrl(int year, ImageOptions options); + + /// + /// Gets the genre image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetGenreImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name. + /// The options. + /// System.String. + /// name + string GetGenreImageUrl(string name, ImageOptions options); + + /// + /// Gets the studio image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + string GetStudioImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets an image url that can be used to download an image from the api + /// + /// The name. + /// The options. + /// System.String. + /// name + string GetStudioImageUrl(string name, ImageOptions options); + + /// + /// Gets the artist image URL. + /// + /// The item. + /// The options. + /// System.String. + /// item + /// or + /// options + string GetArtistImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets the artist image URL. + /// + /// The name. + /// The options. + /// System.String. + /// name + string GetArtistImageUrl(string name, ImageOptions options); + + /// + /// This is a helper to get a list of backdrop url's from a given ApiBaseItemWrapper. If the actual item does not have any backdrops it will return backdrops from the first parent that does. + /// + /// A given item. + /// The options. + /// System.String[][]. + /// item + string[] GetBackdropImageUrls(BaseItemDto item, ImageOptions options); + + /// + /// This is a helper to get the logo image url from a given ApiBaseItemWrapper. If the actual item does not have a logo, it will return the logo from the first parent that does, or null. + /// + /// A given item. + /// The options. + /// System.String. + /// item + string GetLogoImageUrl(BaseItemDto item, ImageOptions options); + + /// + /// Gets the url needed to stream an audio file + /// + /// The options. + /// System.String. + /// options + string GetAudioStreamUrl(StreamOptions options); + + /// + /// Gets the url needed to stream a video file + /// + /// The options. + /// System.String. + /// options + string GetVideoStreamUrl(VideoStreamOptions options); + + /// + /// Formulates a url for streaming audio using the HLS protocol + /// + /// The options. + /// System.String. + /// options + string GetHlsAudioStreamUrl(StreamOptions options); + + /// + /// Formulates a url for streaming video using the HLS protocol + /// + /// The options. + /// System.String. + /// options + string GetHlsVideoStreamUrl(VideoStreamOptions options); + } +} \ No newline at end of file diff --git a/MediaBrowser.Model/MediaBrowser.Model.csproj b/MediaBrowser.Model/MediaBrowser.Model.csproj index bc70dbc13..7d56e4743 100644 --- a/MediaBrowser.Model/MediaBrowser.Model.csproj +++ b/MediaBrowser.Model/MediaBrowser.Model.csproj @@ -10,11 +10,12 @@ MediaBrowser.Model MediaBrowser.Model v4.0 - Profile4 + Profile104 512 {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ..\ true + 10.0 true @@ -40,6 +41,7 @@ Properties\SharedVersion.cs + @@ -138,9 +140,21 @@ + + ..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll + + + ..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll + ..\packages\PropertyChanged.Fody.1.32.2.0\lib\portable-net4+sl4+wp7+win8\PropertyChanged.dll + + ..\packages\Microsoft.Bcl.1.0.19\lib\portable-net40+sl4+win8+wp71\System.Runtime.dll + + + ..\packages\Microsoft.Bcl.1.0.19\lib\portable-net40+sl4+win8+wp71\System.Threading.Tasks.dll + @@ -160,4 +174,5 @@ xcopy "$(TargetPath)" "$(SolutionDir)\Nuget\dlls\" /y /d /r /i --> + \ No newline at end of file diff --git a/MediaBrowser.Model/packages.config b/MediaBrowser.Model/packages.config index b79466fc4..ee6dea0eb 100644 --- a/MediaBrowser.Model/packages.config +++ b/MediaBrowser.Model/packages.config @@ -1,4 +1,7 @@  + + + \ No newline at end of file diff --git a/MediaBrowser.ServerApplication/App.config b/MediaBrowser.ServerApplication/App.config index 36292f967..e461d8c9e 100644 --- a/MediaBrowser.ServerApplication/App.config +++ b/MediaBrowser.ServerApplication/App.config @@ -37,6 +37,14 @@ + + + + + + + +