-
Notifications
You must be signed in to change notification settings - Fork 9
/
TheMovieDbPerson.cs
80 lines (76 loc) · 2.76 KB
/
TheMovieDbPerson.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TmdbWrapper.Cache;
using TmdbWrapper.Persons;
using TmdbWrapper.Utilities;
namespace TmdbWrapper
{
/// <summary>
/// Enumeration of extras that should be prefilled on retrieving the person info
/// </summary>
[Flags]
public enum PersonExtras
{
/// <summary>
/// Retrieve the credits
/// </summary>
Credits = 1
}
public static partial class TheMovieDb
{
/// <summary>
/// Gets the information of the specified person.
/// </summary>
/// <param name="personId">The id of the person.</param>
/// <param name="extras">Indicates which parts should be prefetched.</param>
/// <returns>The person.</returns>
public static async Task<Person> GetPersonAsync(int personId, PersonExtras extras = 0)
{
var result = DatabaseCache.GetObject<Person>(personId);
if (result == null)
{
var request = new Request<Person>("person/" + personId);
if (extras != 0)
{
request.AddParameter("append_to_response", extras.ToString().Replace(" ", ""));
}
result = await request.ProcesRequestAsync();
DatabaseCache.SetObject(personId, result);
}
return result;
}
/// <summary>
/// Get the credits of a specific movie.
/// </summary>
/// <param name="personId">The id of the person.</param>
/// <returns>The credits.</returns>
public static async Task<Credit> GetPersonCreditsAsync(int personId)
{
var credits = DatabaseCache.GetObject<Credit>(personId);
if (credits == null)
{
var request = new Request<Credit>("person/" + personId + "/credits");
credits = await request.ProcesRequestAsync();
DatabaseCache.SetObject(personId, credits);
}
return credits;
}
/// <summary>
/// The images of a specific person.
/// </summary>
/// <param name="personId">The id of the specified person.</param>
/// <returns>A list of images</returns>
public static async Task<IReadOnlyList<Profile>> GetImageAsync(int personId)
{
var profile = DatabaseCache.GetObject<IReadOnlyList<Profile>>(personId);
if (profile == null)
{
var request = new Request<Profile>("person/" + personId + "/images");
profile = await request.ProcesRequestListAsync("profiles");
DatabaseCache.SetObject(personId, profile);
}
return profile;
}
}
}