Skip to content

Commit

Permalink
Merge pull request #51 from bluebery/issue-30
Browse files Browse the repository at this point in the history
Issue 30 - /3/person/latest and /3/person/popular
  • Loading branch information
LordMike committed Sep 16, 2014
2 parents a37514e + 839c3cf commit eeaf8ba
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 0 deletions.
42 changes: 42 additions & 0 deletions TMDbLib/Client/TMDbClientPeople.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RestSharp;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.People;
using TMDbLib.Objects.General;
using TMDbLib.Utilities;
using Credits = TMDbLib.Objects.People.Credits;

Expand Down Expand Up @@ -90,5 +91,46 @@ public List<Change> GetPersonChanges(int personId, DateTime? startDate = null, D
ChangesContainer changesContainer = GetPersonMethod<ChangesContainer>(personId, PersonMethods.Changes, startDate: startDate, endDate: endDate, dateFormat: "yyyy-MM-dd HH:mm:ss UTC");
return changesContainer.Changes;
}

public SearchContainer<PersonResult> GetPersonList(PersonListType type, int page = 0)
{
RestRequest req;
switch (type)
{
case PersonListType.Popular:
req = new RestRequest("person/popular");
break;
default:
throw new ArgumentOutOfRangeException("type");
}

if (page >= 1)
req.AddParameter("page", page.ToString());

req.DateFormat = "yyyy-MM-dd";

IRestResponse<SearchContainer<PersonResult>> resp = _client.Get<SearchContainer<PersonResult>>(req);

return resp.Data;
}

public Person GetPersonItem(PersonItemType type)
{
RestRequest req;
switch (type)
{
case PersonItemType.Latest:
req = new RestRequest("person/latest");
break;
default:
throw new ArgumentOutOfRangeException("type");
}

req.DateFormat = "yyyy-MM-dd";

IRestResponse<Person> resp = _client.Get<Person>(req);

return resp.Data;
}
}
}
12 changes: 12 additions & 0 deletions TMDbLib/Objects/General/MediaKnownFor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;

namespace TMDbLib.Objects.General
{
public class MediaKnownFor
{
public int Id { get; set; }
public string Title { get; set; }
public MediaType Type { get; set; }
}
}
9 changes: 9 additions & 0 deletions TMDbLib/Objects/General/MediaType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TMDbLib.Objects.General
{
public enum MediaType
{
Movie,
TVShow,
Unknown
}
}
16 changes: 16 additions & 0 deletions TMDbLib/Objects/General/PersonResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

namespace TMDbLib.Objects.General
{
public class PersonResult
{
public bool Adult { get; set; }
public int Id { get; set; }
public List<MediaKnownFor> KnownFor { get; set; }
public string Name { get; set; }
public string Bson_Id { get; set; }
public string ProfilePath { get; set; }
public string Url { get; set; }
}
}
7 changes: 7 additions & 0 deletions TMDbLib/Objects/People/PersonItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TMDbLib.Objects.People
{
public enum PersonItemType
{
Latest
}
}
7 changes: 7 additions & 0 deletions TMDbLib/Objects/People/PersonListType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TMDbLib.Objects.People
{
public enum PersonListType
{
Popular
}
}
5 changes: 5 additions & 0 deletions TMDbLib/TMDbLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Client\TMDbClientTvShows.cs" />
<Compile Include="Objects\Account\AccountDetails.cs" />
<Compile Include="Objects\Find\FindExternalSource.cs" />
<Compile Include="Objects\General\MediaType.cs" />
<Compile Include="Objects\General\PostReply.cs">
<SubType>Code</SubType>
</Compile>
Expand Down Expand Up @@ -88,6 +89,7 @@
<Compile Include="Objects\Movies\MovieAccountState.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Objects\General\MediaKnownFor.cs" />
<Compile Include="Objects\Movies\MovieListType.cs" />
<Compile Include="Client\TMDbClientChanges.cs" />
<Compile Include="Client\TMDbClientKeywords.cs" />
Expand Down Expand Up @@ -129,8 +131,11 @@
<Compile Include="Objects\People\Credits.cs" />
<Compile Include="Objects\People\MovieJob.cs" />
<Compile Include="Objects\People\MovieRole.cs" />
<Compile Include="Objects\People\PersonItemType.cs" />
<Compile Include="Objects\People\PersonListType.cs" />
<Compile Include="Objects\People\Person.cs" />
<Compile Include="Objects\People\PersonMethods.cs" />
<Compile Include="Objects\General\PersonResult.cs" />
<Compile Include="Objects\People\ProfileImages.cs" />
<Compile Include="Objects\Search\SearchResultCollection.cs" />
<Compile Include="Objects\Search\SearchMovie.cs" />
Expand Down
40 changes: 40 additions & 0 deletions TMDbLibTests/ClientPersonTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TMDbLib.Objects.Movies;
using TMDbLib.Objects.People;
using TMDbLib.Objects.General;
using TMDbLibTests.Helpers;
using Credits = TMDbLib.Objects.People.Credits;

Expand Down Expand Up @@ -149,5 +150,44 @@ public void TestPersonsImages()

TestImagesHelpers.TestImages(_config, images);
}

[TestMethod]
public void TestPersonsList()
{
foreach (PersonListType type in Enum.GetValues(typeof(PersonListType)).OfType<PersonListType>())
{
SearchContainer<PersonResult> list = _config.Client.GetPersonList(type);

Assert.IsNotNull(list);
Assert.IsTrue(list.Results.Count > 0);
Assert.AreEqual(1, list.Page);

SearchContainer<PersonResult> listPage2 = _config.Client.GetPersonList(type, 2);

Assert.IsNotNull(listPage2);
Assert.IsTrue(listPage2.Results.Count > 0);
Assert.AreEqual(2, listPage2.Page);

SearchContainer<PersonResult> list2 = _config.Client.GetPersonList(type);

Assert.IsNotNull(list2);
Assert.IsTrue(list2.Results.Count > 0);
Assert.AreEqual(1, list2.Page);

// At least one person should differ
Assert.IsTrue(list.Results.Any(s => list2.Results.Any(x => x.Name != s.Name)));
}
}

[TestMethod]
public void TestPersonsItem()
{
foreach (PersonItemType type in Enum.GetValues(typeof(PersonItemType)).OfType<PersonItemType>())
{
Person item = _config.Client.GetPersonItem(type);

Assert.IsNotNull(item);
}
}
}
}

0 comments on commit eeaf8ba

Please sign in to comment.