This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-87: Request handling improvements
- Fix type in name of AuthorizationRefreshRequest - Add handler for authentication requests - Add handler for response errors - Add helper for reading response content streams
- Loading branch information
1 parent
61be241
commit 0a749cd
Showing
8 changed files
with
1,049 additions
and
271 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
411 changes: 411 additions & 0 deletions
411
Source/Lib/TraktApiSharp/Requests/Handler/AuthenticationRequestHandler.cs
Large diffs are not rendered by default.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
Source/Lib/TraktApiSharp/Requests/Handler/IAuthenticationRequestHandler.cs
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,32 @@ | ||
namespace TraktApiSharp.Requests.Handler | ||
{ | ||
using Authentication; | ||
using Objects.Authentication; | ||
using Responses; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Utils; | ||
|
||
internal interface IAuthenticationRequestHandler | ||
{ | ||
string CreateAuthorizationUrl(string clientId, string redirectUri, string state); | ||
|
||
string CreateAuthorizationUrlWithDefaultState(string clientId, string redirectUri); | ||
|
||
Task<Pair<bool, TraktResponse<ITraktAuthorization>>> CheckIfAuthorizationIsExpiredOrWasRevokedAsync(bool autoRefresh = false, CancellationToken cancellationToken = default); | ||
|
||
Task<Pair<bool, TraktResponse<ITraktAuthorization>>> CheckIfAuthorizationIsExpiredOrWasRevokedAsync(ITraktAuthorization authorization, bool autoRefresh = false, CancellationToken cancellationToken = default); | ||
|
||
Task<bool> CheckIfAccessTokenWasRevokedOrIsNotValidAsync(string accessToken, CancellationToken cancellationToken = default); | ||
|
||
Task<TraktResponse<ITraktDevice>> GetDeviceAsync(DeviceRequest request, CancellationToken cancellationToken = default); | ||
|
||
Task<TraktResponse<ITraktAuthorization>> GetAuthorizationAsync(AuthorizationRequest request, CancellationToken cancellationToken = default); | ||
|
||
Task<TraktResponse<ITraktAuthorization>> PollForAuthorizationAsync(AuthorizationPollRequest request, CancellationToken cancellationToken = default); | ||
|
||
Task<TraktResponse<ITraktAuthorization>> RefreshAuthorizationAsync(AuthorizationRefreshRequest request, CancellationToken cancellationToken = default); | ||
|
||
Task<TraktNoContentResponse> RevokeAuthorizationAsync(AuthorizationRevokeRequest request, string clientId, CancellationToken cancellationToken = default); | ||
} | ||
} |
277 changes: 8 additions & 269 deletions
277
Source/Lib/TraktApiSharp/Requests/Handler/RequestHandler.cs
Large diffs are not rendered by default.
Oops, something went wrong.
538 changes: 538 additions & 0 deletions
538
Source/Lib/TraktApiSharp/Requests/Handler/ResponseErrorHandler.cs
Large diffs are not rendered by default.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
Source/Lib/TraktApiSharp/Requests/Handler/ResponseErrorParameters.cs
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,36 @@ | ||
namespace TraktApiSharp.Requests.Handler | ||
{ | ||
using Base; | ||
using System.Net; | ||
|
||
internal sealed class ResponseErrorParameters | ||
{ | ||
public string Url { get; set; } | ||
|
||
public string RequestBody { get; set; } | ||
|
||
public string ResponseBody { get; set; } | ||
|
||
public string ServerReasonPhrase { get; set; } | ||
|
||
public HttpStatusCode StatusCode { get; set; } | ||
|
||
public RequestObjectType RequestObjectType { get; set; } | ||
|
||
public string ObjectId { get; set; } | ||
|
||
public uint SeasonNumber { get; set; } | ||
|
||
public uint EpisodeNumber { get; set; } | ||
|
||
public bool IsCheckinRequest { get; set; } | ||
|
||
public bool IsDeviceRequest { get; set; } | ||
|
||
public bool IsInAuthorizationPolling { get; set; } | ||
|
||
public bool IsAuthorizationRequest { get; set; } | ||
|
||
public bool IsAuthorizationRevoke { get; set; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Source/Lib/TraktApiSharp/Requests/Handler/ResponseMessageHelper.cs
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,17 @@ | ||
namespace TraktApiSharp.Requests.Handler | ||
{ | ||
using Core; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
internal static class ResponseMessageHelper | ||
{ | ||
internal static async Task<Stream> GetResponseContentStreamAsync(HttpResponseMessage responseMessage) | ||
{ | ||
Stream responseContentStream = responseMessage.Content != null ? await responseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false) : default; | ||
DebugAsserter.AssertResponseContentStreamIsNotNull(responseContentStream); | ||
return responseContentStream; | ||
} | ||
} | ||
} |
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