-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-33: Implement missing json readers for authentication objects
- Loading branch information
1 parent
9c5bb5a
commit e371e98
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Source/Lib/Trakt.NET/Objects/Authentication/Json/Reader/AuthorizationArrayJsonReader.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,34 @@ | ||
namespace TraktNet.Objects.Authentication.Json.Reader | ||
{ | ||
using Newtonsoft.Json; | ||
using Objects.Json; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal class AuthorizationArrayJsonReader : AArrayJsonReader<ITraktAuthorization> | ||
{ | ||
public override async Task<IEnumerable<ITraktAuthorization>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) | ||
{ | ||
if (jsonReader == null) | ||
return await Task.FromResult(default(IEnumerable<ITraktAuthorization>)); | ||
|
||
if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) | ||
{ | ||
var authorizationReader = new AuthorizationObjectJsonReader(); | ||
var authorizations = new List<ITraktAuthorization>(); | ||
ITraktAuthorization authorization = await authorizationReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
|
||
while (authorization != null) | ||
{ | ||
authorizations.Add(authorization); | ||
authorization = await authorizationReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
} | ||
|
||
return authorizations; | ||
} | ||
|
||
return await Task.FromResult(default(IEnumerable<ITraktAuthorization>)); | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Source/Lib/Trakt.NET/Objects/Authentication/Json/Reader/DeviceArrayJsonReader.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,34 @@ | ||
namespace TraktNet.Objects.Authentication.Json.Reader | ||
{ | ||
using Newtonsoft.Json; | ||
using Objects.Json; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal class DeviceArrayJsonReader : AArrayJsonReader<ITraktDevice> | ||
{ | ||
public override async Task<IEnumerable<ITraktDevice>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) | ||
{ | ||
if (jsonReader == null) | ||
return await Task.FromResult(default(IEnumerable<ITraktDevice>)); | ||
|
||
if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) | ||
{ | ||
var deviceReader = new DeviceObjectJsonReader(); | ||
var devices = new List<ITraktDevice>(); | ||
ITraktDevice device = await deviceReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
|
||
while (device != null) | ||
{ | ||
devices.Add(device); | ||
device = await deviceReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
return await Task.FromResult(default(IEnumerable<ITraktDevice>)); | ||
} | ||
} | ||
} |