You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi.TheMovieDbApi/TheMovieDbApi.cs

95 lines
4.1 KiB

8 years ago
using System.Collections.Generic;
using System.Net.Http;
8 years ago
using System.Threading.Tasks;
8 years ago
using AutoMapper;
using Ombi.Api.TheMovieDb.Models;
8 years ago
using Ombi.Helpers;
8 years ago
using Ombi.TheMovieDbApi.Models;
8 years ago
namespace Ombi.Api.TheMovieDb
8 years ago
{
public class TheMovieDbApi : IMovieDbApi
8 years ago
{
public TheMovieDbApi(IMapper mapper, IApi api)
8 years ago
{
Api = api;
8 years ago
Mapper = mapper;
8 years ago
}
8 years ago
private IMapper Mapper { get; }
8 years ago
private readonly string ApiToken = "b8eabaf5608b88d0298aa189dd90bf00";
8 years ago
private static readonly string BaseUri ="http://api.themoviedb.org/3/";
private IApi Api { get; }
8 years ago
8 years ago
public async Task<MovieResponseDto> GetMovieInformation(int movieId)
8 years ago
{
8 years ago
var request = new Request($"movie/{movieId}", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
8 years ago
var result = await Api.Request<MovieResponse>(request);
return Mapper.Map<MovieResponseDto>(result);
8 years ago
}
public async Task<List<MovieSearchResult>> 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<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
public async Task<MovieResponseDto> GetMovieInformationWithExtraInfo(int movieId)
8 years ago
{
8 years ago
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");
8 years ago
var result = await Api.Request<MovieResponse>(request);
return Mapper.Map<MovieResponseDto>(result);
8 years ago
}
8 years ago
public async Task<List<MovieSearchResult>> SearchMovie(string searchTerm)
8 years ago
{
8 years ago
var request = new Request($"search/movie", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
request.FullUri = request.FullUri.AddQueryParameter("query", searchTerm);
8 years ago
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
8 years ago
}
8 years ago
public async Task<List<MovieSearchResult>> PopularMovies()
{
8 years ago
var request = new Request($"movie/popular", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
8 years ago
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
8 years ago
public async Task<List<MovieSearchResult>> TopRated()
{
8 years ago
var request = new Request($"movie/top_rated", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
8 years ago
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
8 years ago
public async Task<List<MovieSearchResult>> Upcoming()
{
8 years ago
var request = new Request($"movie/upcoming", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
8 years ago
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
8 years ago
public async Task<List<MovieSearchResult>> NowPlaying()
{
8 years ago
var request = new Request($"movie/now_playing", BaseUri, HttpMethod.Get);
request.FullUri = request.FullUri.AddQueryParameter("api_key", ApiToken);
8 years ago
var result = await Api.Request<TheMovieDbContainer<SearchResult>>(request);
return Mapper.Map<List<MovieSearchResult>>(result.results);
}
8 years ago
}
}