Skip to content

Commit

Permalink
Updated MovieInfoApp
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolavn committed Aug 25, 2016
1 parent 98cb795 commit dfc93d9
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ActorTests
private static ActorModel actorInfo;
private static CreditsModel credits;
private static string creditsId;
private static SeriesInfo seriesInfo;
private static SeriesInfoModel seriesInfo;
private static List<EpisodeModel> episodes;
private static List<SeasonModel> seasons;

Expand Down
3 changes: 3 additions & 0 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/.bin/git.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
SET PATH=%~dp0;%PATH%
"%~dp0node" "%~dp0..\..\packages\NoGit.0.0.8\node_modules\nogit\bin\git.js" %*
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
SET PATH=%PATH%;%~dp0
"%~dp0..\..\packages\Node.js.0.10.28\node.exe" %*
45 changes: 45 additions & 0 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/ActorInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace MovieInfoApp
{
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

using Models;
using Newtonsoft.Json;

public class ActorInfo
{
private static ActorInfo retrieve;

private ActorInfo(HttpClient client, string endpoint)
{
this.PrepareEndpoint(client, endpoint);
}

public static async Task<ActorModel> GetActorInfoByName(HttpClient client,string actorName)
{
string responseData;
string escapedName = Uri.EscapeUriString(actorName);

client.BaseAddress = client.BaseAddress.AddParameter("query", escapedName);

Task<string> response = client.GetStringAsync("");
responseData = await response;

var actors = JsonConvert.DeserializeObject<ActorSearchResultsModel>(responseData);

return actors.Results.FirstOrDefault();
}

private Uri PrepareEndpoint(HttpClient client, string endpoint)
{
UriBuilder targetUrl = new UriBuilder(client.BaseAddress);
targetUrl.Path = endpoint;

client.BaseAddress = targetUrl.Uri;

return targetUrl.Uri;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Newtonsoft.Json;
using System.Collections.Generic;

public class ActorSearchResults
public class ActorSearchResultsModel
{
[JsonProperty("results")]
public List<ActorModel> Results { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;

public class CreditsSearchResults
public class CreditsSearchResultsModel
{
[JsonProperty("cast")]
public List<CreditsModel> Credits { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using Newtonsoft.Json;

public class SeriesInfo
public class SeriesInfoModel
{
[JsonProperty("episodes")]
public List<EpisodeModel> Episodes { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
public class SeriesSearchResults
{
[JsonProperty("media")]
public SeriesInfo SeriesInfo { get; set; }
public SeriesInfoModel SeriesInfo { get; set; }
}
}
49 changes: 44 additions & 5 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/MovieDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,53 @@
using Models;
using System.Threading.Tasks;

public static class MovieDb
public class MovieDb
{
private static readonly Uri BaseUrl = new Uri("https://api.themoviedb.org/");
//private static readonly Uri BaseUrl = new Uri("https://api.themoviedb.org/");
private static readonly string PeopleEndpoint = "3/search/person";
private static readonly string TVCreditsEndpointFormat = "3/person/{0}/tv_credits";
private static readonly string CreditDetailsEndpointFormat = "3/credit/{0}";
private const string ApiKey = "8e44e41d1573ab3d390b11fc6d35d95e";
private Uri baseUrl;
private HttpClient client;
private static MovieDb instance;

private MovieDb()
{

}

public static MovieDb Instance
{
get
{
if(instance == null)
{
instance = new MovieDb();
}

return instance;
}
}

public Uri BaseUrl
{
get { return this.baseUrl; }
set { this.baseUrl = value; }
}

public HttpClient Client
{
get { return this.client; }
set { this.client = value; }
}

public void Connect(HttpClient client, Uri baseUrl, string apiKey)
{
this.Client = client;
this.BaseUrl = baseUrl.AddParameter("api_key",apiKey);
client.BaseAddress = this.BaseUrl;
}

public static async Task<ActorModel> GetActorInfoByName(string name)
{
Expand All @@ -36,7 +75,7 @@ public static async Task<ActorModel> GetActorInfoByName(string name)
Task<string> response = client.GetStringAsync("");
responseData = await response;

var actors = JsonConvert.DeserializeObject<ActorSearchResults>(responseData);
var actors = JsonConvert.DeserializeObject<ActorSearchResultsModel>(responseData);

return actors.Results.FirstOrDefault();
}
Expand All @@ -55,12 +94,12 @@ public static async Task<List<CreditsModel>> GetTVCreditsByActorId(int actorId)
Task<string> response = client.GetStringAsync("");
responseData = await response;

var credits = JsonConvert.DeserializeObject<CreditsSearchResults>(responseData);
var credits = JsonConvert.DeserializeObject<CreditsSearchResultsModel>(responseData);

return credits.Credits;
}

public static async Task<SeriesInfo> GetTVSeriesDetailsByCreditsId(string creditsId)
public static async Task<SeriesInfoModel> GetTVSeriesDetailsByCreditsId(string creditsId)
{
string responseData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,28 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActorInfo.cs" />
<Compile Include="Models\ActorModel.cs" />
<Compile Include="Models\ActorSearchResults.cs" />
<Compile Include="Models\ActorSearchResultsModel.cs" />
<Compile Include="Models\CreditsModel.cs" />
<Compile Include="Models\CreditsSearchResults.cs" />
<Compile Include="Models\CreditsSearchResultsModel.cs" />
<Compile Include="Models\EpisodeModel.cs" />
<Compile Include="Models\SeasonModel.cs" />
<Compile Include="Models\SeriesInfo.cs" />
<Compile Include="Models\SeriesInfoModel.cs" />
<Compile Include="Models\SeriesSearchResults.cs" />
<Compile Include="MovieDb.cs" />
<Compile Include="Startup.cs" />
<Compile Include="UriExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include=".bin\git.cmd" />
<None Include=".bin\node.cmd" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Folder Include="Contracts\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.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.
Expand Down
3 changes: 3 additions & 0 deletions Web Services And Cloud/MovieInfoApp/MovieInfoApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public static void Main()
var creditsId = credits.Result.FirstOrDefault().CreditsId;
var seriesInfo = MovieDb.GetTVSeriesDetailsByCreditsId(creditsId);

MovieDb.Instance.Connect(new System.Net.Http.HttpClient(), new Uri("https://api.themoviedb.org/"), "8e44e41d1573ab3d390b11fc6d35d95e");


Console.WriteLine(creditsId);
Console.WriteLine(seriesInfo.Result.Episodes);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" />
<package id="Node.js" version="0.10.28" targetFramework="net45" />
<package id="NoGit" version="0.0.8" targetFramework="net45" />
</packages>

0 comments on commit dfc93d9

Please sign in to comment.