Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit 07a12a0

Browse files
[v2] Add TMDB response type (#153 #158)
1 parent d9f4d6f commit 07a12a0

File tree

3 files changed

+99
-36
lines changed

3 files changed

+99
-36
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System.Net;
2+
using System.Net.Http.Headers;
3+
4+
namespace TraktNET
5+
{
6+
public partial class TMDBResponse<TResponseContentType>
7+
{
8+
internal static TMDBResponse<TResponseContentType> Create(HttpStatusCode statusCode, TResponseContentType? content,
9+
HttpResponseHeaders? headers, HttpContentHeaders? contentHeaders)
10+
=> new()
11+
{
12+
Headers = headers,
13+
StatusCode = statusCode,
14+
Content = content,
15+
ContentHeaders = contentHeaders
16+
};
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#if NET6_0_OR_GREATER
2+
using System.Diagnostics.CodeAnalysis;
3+
#endif
4+
5+
using System.Net;
6+
using System.Net.Http.Headers;
7+
8+
namespace TraktNET
9+
{
10+
/// <summary>A TMDB response with content of type <typeparamref name="TResponseContentType" />.</summary>
11+
/// <typeparam name="TResponseContentType">The content type.</typeparam>
12+
public partial class TMDBResponse<TResponseContentType>
13+
{
14+
/// <summary>The headers of the response message.</summary>
15+
public HttpResponseHeaders? Headers { get; internal set; }
16+
17+
/// <summary>The status code of the response message.</summary>
18+
public HttpStatusCode StatusCode { get; internal set; }
19+
20+
/// <summary>Gets, whether the request for this response was successful.</summary>
21+
#if NET6_0_OR_GREATER
22+
[MemberNotNullWhen(true, nameof(Headers))]
23+
#endif
24+
public bool IsSuccess => (int)StatusCode >= 200 && (int)StatusCode <= 299;
25+
26+
/// <summary>Gets, whether this response has a content value set.</summary>
27+
#if NET6_0_OR_GREATER
28+
[MemberNotNullWhen(true, nameof(Content))]
29+
[MemberNotNullWhen(true, nameof(ContentHeaders))]
30+
#endif
31+
public bool HasValue => Content != null;
32+
33+
/// <summary>The content of the response.</summary>
34+
public TResponseContentType? Content { get; internal set; }
35+
36+
/// <summary>The headers of the response messsage content.</summary>
37+
public HttpContentHeaders? ContentHeaders { get; internal set; }
38+
39+
/// <summary>Implicit conversion to bool for this response.</summary>
40+
/// <param name="response">The <see cref="TMDBResponse{TResponseContentType}" /> instance, which will be converted to bool.</param>
41+
public static implicit operator bool(TMDBResponse<TResponseContentType> response) => response.IsSuccess;
42+
}
43+
}
Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,115 @@
1+
using System.Net;
2+
13
namespace TraktNET
24
{
35
public static class TraktTMDBExtensions
46
{
5-
public static async Task<TMDBMovieImages> GetTMDBImagesAsync(this TraktMovieMinimal traktMovie, CancellationToken cancellationToken = default)
7+
public static async Task<TMDBResponse<TMDBMovieImages>> GetTMDBImagesAsync(this TraktMovieMinimal traktMovie, CancellationToken cancellationToken = default)
68
{
79
// TODO
8-
return await Task.FromResult(new TMDBMovieImages());
10+
return await Task.FromResult(TMDBResponse<TMDBMovieImages>.Create(HttpStatusCode.OK, null, null, null));
911
}
1012

11-
public static async Task<TMDBMovieImages> GetTMDBImagesAsync(this TraktMovie traktMovie, CancellationToken cancellationToken = default)
13+
public static async Task<TMDBResponse<TMDBMovieImages>> GetTMDBImagesAsync(this TraktMovie traktMovie, CancellationToken cancellationToken = default)
1214
{
1315
// TODO
14-
return await Task.FromResult(new TMDBMovieImages());
16+
return await Task.FromResult(TMDBResponse<TMDBMovieImages>.Create(HttpStatusCode.OK, null, null, null));
1517
}
1618

17-
public static async Task<TMDBShowImages> GetTMDBImagesAsync(this TraktShowMinimal traktShow, CancellationToken cancellationToken = default)
19+
public static async Task<TMDBResponse<TMDBShowImages>> GetTMDBImagesAsync(this TraktShowMinimal traktShow, CancellationToken cancellationToken = default)
1820
{
1921
// TODO
20-
return await Task.FromResult(new TMDBShowImages());
22+
return await Task.FromResult(TMDBResponse<TMDBShowImages>.Create(HttpStatusCode.OK, null, null, null));
2123
}
2224

23-
public static async Task<TMDBShowImages> GetTMDBImagesAsync(this TraktShow traktShow, CancellationToken cancellationToken = default)
25+
public static async Task<TMDBResponse<TMDBShowImages>> GetTMDBImagesAsync(this TraktShow traktShow, CancellationToken cancellationToken = default)
2426
{
2527
// TODO
26-
return await Task.FromResult(new TMDBShowImages());
28+
return await Task.FromResult(TMDBResponse<TMDBShowImages>.Create(HttpStatusCode.OK, null, null, null));
2729
}
2830

29-
public static async Task<TMDBSeasonImages> GetTMDBImagesAsync(this TraktSeasonMinimal traktSeason, CancellationToken cancellationToken = default)
31+
public static async Task<TMDBResponse<TMDBSeasonImages>> GetTMDBImagesAsync(this TraktSeasonMinimal traktSeason, CancellationToken cancellationToken = default)
3032
{
3133
// TODO
32-
return await Task.FromResult(new TMDBSeasonImages());
34+
return await Task.FromResult(TMDBResponse<TMDBSeasonImages>.Create(HttpStatusCode.OK, null, null, null));
3335
}
3436

35-
public static async Task<TMDBSeasonImages> GetTMDBImagesAsync(this TraktSeason traktSeason, CancellationToken cancellationToken = default)
37+
public static async Task<TMDBResponse<TMDBSeasonImages>> GetTMDBImagesAsync(this TraktSeason traktSeason, CancellationToken cancellationToken = default)
3638
{
3739
// TODO
38-
return await Task.FromResult(new TMDBSeasonImages());
40+
return await Task.FromResult(TMDBResponse<TMDBSeasonImages>.Create(HttpStatusCode.OK, null, null, null));
3941
}
4042

41-
public static async Task<TMDBEpisodeImages> GetTMDBImagesAsync(this TraktEpisodeMinimal traktEpisode, CancellationToken cancellationToken = default)
43+
public static async Task<TMDBResponse<TMDBEpisodeImages>> GetTMDBImagesAsync(this TraktEpisodeMinimal traktEpisode, CancellationToken cancellationToken = default)
4244
{
4345
// TODO
44-
return await Task.FromResult(new TMDBEpisodeImages());
46+
return await Task.FromResult(TMDBResponse<TMDBEpisodeImages>.Create(HttpStatusCode.OK, null, null, null));
4547
}
4648

47-
public static async Task<TMDBEpisodeImages> GetTMDBImagesAsync(this TraktEpisode traktEpisode, CancellationToken cancellationToken = default)
49+
public static async Task<TMDBResponse<TMDBEpisodeImages>> GetTMDBImagesAsync(this TraktEpisode traktEpisode, CancellationToken cancellationToken = default)
4850
{
4951
// TODO
50-
return await Task.FromResult(new TMDBEpisodeImages());
52+
return await Task.FromResult(TMDBResponse<TMDBEpisodeImages>.Create(HttpStatusCode.OK, null, null, null));
5153
}
5254

53-
public static async Task<TMDBPersonImages> GetTMDBImagesAsync(this TraktPersonMinimal traktPerson, CancellationToken cancellationToken = default)
55+
public static async Task<TMDBResponse<TMDBPersonImages>> GetTMDBImagesAsync(this TraktPersonMinimal traktPerson, CancellationToken cancellationToken = default)
5456
{
5557
// TODO
56-
return await Task.FromResult(new TMDBPersonImages());
58+
return await Task.FromResult(TMDBResponse<TMDBPersonImages>.Create(HttpStatusCode.OK, null, null, null));
5759
}
5860

59-
public static async Task<TMDBPersonImages> GetTMDBImagesAsync(this TraktPerson traktPerson, CancellationToken cancellationToken = default)
61+
public static async Task<TMDBResponse<TMDBPersonImages>> GetTMDBImagesAsync(this TraktPerson traktPerson, CancellationToken cancellationToken = default)
6062
{
6163
// TODO
62-
return await Task.FromResult(new TMDBPersonImages());
64+
return await Task.FromResult(TMDBResponse<TMDBPersonImages>.Create(HttpStatusCode.OK, null, null, null));
6365
}
6466

65-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktMovieMinimal traktMovie, CancellationToken cancellationToken = default)
67+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktMovieMinimal traktMovie, CancellationToken cancellationToken = default)
6668
{
6769
// TODO
68-
return await Task.FromResult(new TMDBVideos());
70+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
6971
}
7072

71-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktMovie traktMovie, CancellationToken cancellationToken = default)
73+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktMovie traktMovie, CancellationToken cancellationToken = default)
7274
{
7375
// TODO
74-
return await Task.FromResult(new TMDBVideos());
76+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
7577
}
7678

77-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktShowMinimal traktShow, CancellationToken cancellationToken = default)
79+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktShowMinimal traktShow, CancellationToken cancellationToken = default)
7880
{
7981
// TODO
80-
return await Task.FromResult(new TMDBVideos());
82+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
8183
}
8284

83-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktShow traktShow, CancellationToken cancellationToken = default)
85+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktShow traktShow, CancellationToken cancellationToken = default)
8486
{
8587
// TODO
86-
return await Task.FromResult(new TMDBVideos());
88+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
8789
}
8890

89-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktSeasonMinimal traktSeason, CancellationToken cancellationToken = default)
91+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktSeasonMinimal traktSeason, CancellationToken cancellationToken = default)
9092
{
9193
// TODO
92-
return await Task.FromResult(new TMDBVideos());
94+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
9395
}
9496

95-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktSeason traktSeason, CancellationToken cancellationToken = default)
97+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktSeason traktSeason, CancellationToken cancellationToken = default)
9698
{
9799
// TODO
98-
return await Task.FromResult(new TMDBVideos());
100+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
99101
}
100102

101-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktEpisodeMinimal traktEpisode, CancellationToken cancellationToken = default)
103+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktEpisodeMinimal traktEpisode, CancellationToken cancellationToken = default)
102104
{
103105
// TODO
104-
return await Task.FromResult(new TMDBVideos());
106+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
105107
}
106108

107-
public static async Task<TMDBVideos> GetTMDBVideosAsync(this TraktEpisode traktEpisode, CancellationToken cancellationToken = default)
109+
public static async Task<TMDBResponse<TMDBVideos>> GetTMDBVideosAsync(this TraktEpisode traktEpisode, CancellationToken cancellationToken = default)
108110
{
109111
// TODO
110-
return await Task.FromResult(new TMDBVideos());
112+
return await Task.FromResult(TMDBResponse<TMDBVideos>.Create(HttpStatusCode.OK, null, null, null));
111113
}
112114
}
113115
}

0 commit comments

Comments
 (0)