using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; using AutoMapper; using Ombi.Api.TheMovieDb.Models; using Ombi.Helpers; using Ombi.TheMovieDbApi.Models; namespace Ombi.Api.TheMovieDb { public class TheMovieDbApi : IMovieDbApi { public TheMovieDbApi(IMapper mapper, IApi api) { Api = api; Mapper = mapper; } private IMapper Mapper { get; } private readonly string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00"; private static readonly string BaseUri ="http://api.themoviedb.org/3/"; private IApi Api { get; } public async Task GetMovieInformation(int movieId) { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request(request); return Mapper.Map(result); } public async Task> SimilarMovies(int movieId) { var request = new Request($"movie/{movieId}/similar", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request>(request); return Mapper.Map>(result.results); } public async Task GetMovieInformationWithExtraInfo(int movieId) { var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("append_to_response", "videos,release_dates"); var result = await Api.Request(request); return Mapper.Map(result); } public async Task> SearchMovie(string searchTerm) { var request = new Request($"search/movie", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm); var result = await Api.Request>(request); return Mapper.Map>(result.results); } public async Task> PopularMovies() { var request = new Request($"movie/popular", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request>(request); return Mapper.Map>(result.results); } public async Task> TopRated() { var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request>(request); return Mapper.Map>(result.results); } public async Task> Upcoming() { var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request>(request); return Mapper.Map>(result.results); } public async Task> NowPlaying() { var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get); request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken); var result = await Api.Request>(request); return Mapper.Map>(result.results); } } }