Beispiel #1
0
        private async Task <TModel> GetItemDetailAsync <TModel>(int id)
        {
            ApiRequestTypeAttribute attribute = GetAttribute <ApiRequestTypeAttribute>(typeof(TModel));

            ApiRequestType requestType = attribute.RequestType;

            if (!requestType.GetUriString().Contains(Parameters.Id))
            {
                throw new ArgumentException("This Model requires ID.");
            }

            MovieDatabaseApiRequest request = new MovieDatabaseApiRequest(_apiKey, requestType);

            request.AddQueryParameter("language", Settings.CultureInfo.TwoLetterISOLanguageName);
            request.AddPathParameter(Parameters.Id, id.ToString());

            string responseString = await request.GetResponseAsync();

            return(JsonConvert.DeserializeObject <TModel>(responseString, _jsonSettings));
        }
Beispiel #2
0
        /// <summary>
        /// Searches asynchronously Api for the query. Returns <see cref="MediaSearchResult"/> that contains ID required to get a detail model of the media.
        /// </summary>
        /// <param name="query">Search query</param>
        /// <returns><see cref="MediaSearchResult"/> that contains ID required to get a detail model of the media.</returns>
        public async Task <List <MediaSearchResult> > SearchMultiByQueryAsync(string query)
        {
            List <MediaSearchResult> mediaList = new List <MediaSearchResult>();

            MovieDatabaseApiRequest request = new MovieDatabaseApiRequest(_apiKey, ApiRequestType.SearchMulti);

            request.AddQueryParameter("query", query);
            request.AddQueryParameter("language", Settings.CultureInfo.TwoLetterISOLanguageName);

            string responseString = await request.GetResponseAsync();

            SearchResponse response = JsonConvert.DeserializeObject <SearchResponse>(responseString, _jsonSettings);

            foreach (SearchResult result in response.Results)
            {
                if (result.MediaType != MediaType.Person)
                {
                    mediaList.Add(result);
                }
            }

            return(mediaList);
        }