This repository has been archived by the owner on Mar 24, 2020. It is now read-only.
forked from bodrick/Ember-MM
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added FanartTV and RottenTomatoes API Libraries
Not yet used by Ember but in this way you can have fun. you need to request and API from both. Will add to the new scraper soon :) On RottenTomatoes I just added the calls we may need.
- Loading branch information
m.savazzi
committed
Feb 22, 2013
1 parent
18e0a32
commit 70d2d9d
Showing
34 changed files
with
1,720 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using RestSharp; | ||
using System.Net; | ||
|
||
namespace FanartTV.V1 | ||
{ | ||
public partial class FanartTV | ||
{ | ||
#region Process Execution | ||
|
||
private void ProcessAsyncRequest<T>(RestRequest request, Action<FanartTVAsyncResult<T>> callback) | ||
where T : new() | ||
{ | ||
var client = new RestClient(BASE_URL); | ||
client.AddHandler("application/json", new WatJsonDeserializer()); | ||
client.AddHandler("application/json charset=utf-8", new WatJsonDeserializer()); | ||
|
||
if (Timeout.HasValue) | ||
client.Timeout = Timeout.Value; | ||
|
||
#if !WINDOWS_PHONE | ||
if (Proxy != null) | ||
client.Proxy = Proxy; | ||
#endif | ||
|
||
Error = null; | ||
|
||
//request.AddHeader("Accept", "application/json"); | ||
//request.AddParameter("api_key", ApiKey); | ||
|
||
++AsyncCount; | ||
var asyncHandle = client.ExecuteAsync<T>(request, resp => | ||
{ | ||
--AsyncCount; | ||
var result = new FanartTVAsyncResult<T> | ||
{ | ||
Data = resp.Data != null ? resp.Data : default(T), | ||
UserState = request.UserState | ||
}; | ||
ResponseContent = resp.Content; | ||
ResponseHeaders = resp.Headers.ToDictionary(k => k.Name, v => v.Value); | ||
if (resp.ResponseStatus != ResponseStatus.Completed) | ||
{ | ||
if (resp.Content.Contains("status_message")) | ||
result.Error = resp.Content ; | ||
else if (resp.ErrorException != null) | ||
throw resp.ErrorException; | ||
else | ||
result.Error = resp.Content ; | ||
} | ||
Error = result.Error; | ||
callback(result); | ||
}); | ||
} | ||
|
||
|
||
#endregion | ||
|
||
private static bool CheckQuery<T>(string query, object userState, Action<FanartTVAsyncResult<T>> callback) | ||
where T : class | ||
{ | ||
if (string.IsNullOrEmpty(query)) | ||
{ | ||
callback(new FanartTVAsyncResult<T> | ||
{ | ||
Data = null, | ||
Error = "Search cannot be empty", | ||
UserState = userState | ||
}); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
#region Movie Info | ||
|
||
/// <summary> | ||
/// Retrieve all the basic movie information for a particular movie by FanartTV reference. | ||
/// http://fanart.tv/api-docs/movie-api/ | ||
/// </summary> | ||
/// <param name="apikey">FanartTV movie id</param> | ||
/// <param name="id">optional - ISO 639-1 language code</param> | ||
/// The following parameters are optional but if you want to change any from the default value you must specify all optional parameters before the one you are changing (so if you are changing just format you don’t have to specify type, but if you want to change the sort you MUST also specify the format and type)</param> | ||
/// <param name="format">Returns the results in the requested format - json (default) / php (returns a php serialized object)</param> | ||
/// <param name="type">Returns the requested image types - all (default) / movielogo / movieart / moviedisc</param> | ||
/// <param name="sort">1 – Sorted by most popular image then newest(default) / 2 – Sorted by newest uploaded image / 3 – Sorted by oldest uploaded image</param> | ||
/// <param name="limit">Value is either 1 (1 image) or 2 (all images – default), for example, when automatically downloading images you might only want to return the first result so the user doesn’t have to provide input, whereas with a manual download you might want the user to see all the options.</param> | ||
/// <returns></returns> | ||
public void GetMovieInfo(FanartTVRequest Request, Action<FanartTVAsyncResult<FanartTVMovie>> callback) | ||
{ | ||
//ProcessAsyncRequest<FanartTVMovie>(BuildGetMovieInfoRequest(MovieID, language, UserState), callback); | ||
ProcessAsyncRequest<FanartTVMovie>(Generator.GetMovieInfo(Request), callback); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using RestSharp; | ||
using System.Net; | ||
|
||
namespace FanartTV.V1 | ||
{ | ||
public partial class FanartTV | ||
{ | ||
#region Process Execution | ||
|
||
private T ProcessRequest<T>(RestRequest request) | ||
where T : new() | ||
{ | ||
var client = new RestClient(BASE_URL); | ||
client.AddHandler("application/json", new WatJsonDeserializer()); | ||
client.AddHandler("application/json charset=utf-8", new WatJsonDeserializer()); | ||
|
||
if (Timeout.HasValue) | ||
client.Timeout = Timeout.Value; | ||
|
||
#if !WINDOWS_PHONE | ||
if (Proxy != null) | ||
client.Proxy = Proxy; | ||
#endif | ||
|
||
var resp = client.Execute<T>(request); | ||
|
||
ResponseContent = resp.Content; | ||
ResponseHeaders = resp.Headers.ToDictionary(k => k.Name, v => v.Value); | ||
|
||
if (resp.ResponseStatus == ResponseStatus.Completed) | ||
{ | ||
if (resp.Content.Contains("status_message")) | ||
Error = resp.Content; | ||
|
||
return resp.Data; | ||
} | ||
else | ||
{ | ||
if (resp.Content.Contains("status_message")) | ||
Error = resp.Content; | ||
else if (resp.ErrorException != null) | ||
throw resp.ErrorException; | ||
else | ||
Error = resp.ErrorMessage; | ||
} | ||
|
||
return default(T); | ||
} | ||
|
||
#endregion | ||
|
||
|
||
#region Movie Info | ||
/// <summary> | ||
/// Retrieve all the basic movie information for a particular movie by FanartTV reference. | ||
/// http://fanart.tv/api-docs/movie-api/ | ||
/// </summary> | ||
/// <param name="apikey">FanartTV movie id</param> | ||
/// <param name="id">optional - ISO 639-1 language code</param> | ||
/// The following parameters are optional but if you want to change any from the default value you must specify all optional parameters before the one you are changing (so if you are changing just format you don’t have to specify type, but if you want to change the sort you MUST also specify the format and type)</param> | ||
/// <param name="format">Returns the results in the requested format - json (default) / php (returns a php serialized object)</param> | ||
/// <param name="type">Returns the requested image types - all (default) / movielogo / movieart / moviedisc</param> | ||
/// <param name="sort">1 – Sorted by most popular image then newest(default) / 2 – Sorted by newest uploaded image / 3 – Sorted by oldest uploaded image</param> | ||
/// <param name="limit">Value is either 1 (1 image) or 2 (all images – default), for example, when automatically downloading images you might only want to return the first result so the user doesn’t have to provide input, whereas with a manual download you might want the user to see all the options.</param> | ||
/// <returns></returns> | ||
public FanartTVMovie GetMovieInfo(FanartTVRequest Request) | ||
{ | ||
//return ProcessRequest<FanartTVMovie>(BuildGetMovieInfoRequest(MovieID, language)); | ||
return ProcessRequest<FanartTVMovie>(Generator.GetMovieInfo(Request)); | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using RestSharp.Deserializers; | ||
using System.Net; | ||
using RestSharp; | ||
using FanartTV.Utilities; | ||
|
||
namespace FanartTV.V1 | ||
{ | ||
public partial class FanartTV | ||
{ | ||
private const string BASE_URL = "http://api.fanart.tv/webservice/"; | ||
|
||
public FanartTV(string apiKey) | ||
{ | ||
ApiKey = apiKey; | ||
Error = null; | ||
Timeout = null; | ||
|
||
Deserializer = new JsonDeserializer(); | ||
Generator = new RequestGenerator(apiKey); | ||
} | ||
|
||
#region Properties | ||
|
||
private RequestGenerator Generator { get; set; } | ||
|
||
private RequestGenerator ETagGenerator { get; set; } | ||
|
||
private string ApiKey { get; set; } | ||
|
||
private string Language { get; set; } | ||
|
||
private JsonDeserializer Deserializer; | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// Current count of outstanding Async calls awaiting callback response | ||
/// </summary> | ||
public int AsyncCount = 0; | ||
|
||
/// <summary> | ||
/// Error message | ||
/// </summary> | ||
public string Error { get; set; } | ||
|
||
/// <summary> | ||
/// String representation of response content | ||
/// </summary> | ||
public string ResponseContent { get; set; } | ||
|
||
/// <summary> | ||
/// Dictionary of Header values in response | ||
/// http://fanart.tv/api-docs/movie-api/ | ||
/// </summary> | ||
public Dictionary<string, object> ResponseHeaders { get; set; } | ||
|
||
|
||
#if !WINDOWS_PHONE | ||
/// <summary> | ||
/// Proxy to use for requests made. Passed on to underying WebRequest if set. | ||
/// </summary> | ||
public IWebProxy Proxy { get; set; } | ||
#endif | ||
/// <summary> | ||
/// Timeout in milliseconds to use for requests made. | ||
/// </summary> | ||
public int? Timeout { get; set; } | ||
|
||
|
||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>8.0.30703</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{70F651C6-6BB4-4E4D-AD6C-25C36CA1E9E6}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>FanartTVAPI</RootNamespace> | ||
<AssemblyName>FanartTVAPI</AssemblyName> | ||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> | ||
<RestorePackages>true</RestorePackages> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="RestSharp"> | ||
<HintPath>..\packages\RestSharp.104.1\lib\net35\RestSharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="V1\FanartTVRequest.cs" /> | ||
<Compile Include="V1\FanartTVAsyncResult.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="FanartTV\FanartTV.Async.cs" /> | ||
<Compile Include="FanartTV\FanartTV.cs" /> | ||
<Compile Include="FanartTV\FanartTV.Sync.cs" /> | ||
<Compile Include="Utilities\Constants.cs" /> | ||
<Compile Include="Utilities\RequestBuilder.cs" /> | ||
<Compile Include="Utilities\RequestGenerator.cs" /> | ||
<Compile Include="Utilities\Utility.cs" /> | ||
<Compile Include="V1\FanartTVError.cs" /> | ||
<Compile Include="V1\FanartTVMovie.cs" /> | ||
<Compile Include="V1\WatJsonDeserializer.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="$(SolutionDir)\.nuget\nuget.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Oops, something went wrong.