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-109: Add interface and implementation for comment like
- Loading branch information
1 parent
4fd8c81
commit 7feba0c
Showing
9 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Source/Lib/TraktApiSharp/Objects/Basic/ITraktCommentLike.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,12 @@ | ||
namespace TraktApiSharp.Objects.Basic | ||
{ | ||
using Get.Users; | ||
using System; | ||
|
||
public interface ITraktCommentLike | ||
{ | ||
DateTime? LikedAt { get; set; } | ||
|
||
ITraktUser User { get; set; } | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Source/Lib/TraktApiSharp/Objects/Basic/Implementations/TraktCommentLike.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,12 @@ | ||
namespace TraktApiSharp.Objects.Basic | ||
{ | ||
using Get.Users; | ||
using System; | ||
|
||
public class TraktCommentLike : ITraktCommentLike | ||
{ | ||
public DateTime? LikedAt { get; set; } | ||
|
||
public ITraktUser User { get; set; } | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Source/Lib/TraktApiSharp/Objects/Basic/Json/Factories/CommentLikeJsonIOFactory.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,15 @@ | ||
namespace TraktApiSharp.Objects.Basic.Json.Factories | ||
{ | ||
using Objects.Basic.Json.Reader; | ||
using Objects.Basic.Json.Writer; | ||
using Objects.Json; | ||
|
||
internal class CommentLikeJsonIOFactory : IJsonIOFactory<ITraktCommentLike> | ||
{ | ||
public IObjectJsonReader<ITraktCommentLike> CreateObjectReader() => new CommentLikeObjectJsonReader(); | ||
|
||
public IArrayJsonReader<ITraktCommentLike> CreateArrayReader() => new CommentLikeArrayJsonReader(); | ||
|
||
public IObjectJsonWriter<ITraktCommentLike> CreateObjectWriter() => new CommentLikeObjectJsonWriter(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
Source/Lib/TraktApiSharp/Objects/Basic/Json/Reader/CommentLikeArrayJsonReader.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,40 @@ | ||
namespace TraktApiSharp.Objects.Basic.Json.Reader | ||
{ | ||
using Newtonsoft.Json; | ||
using Objects.Json; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal class CommentLikeArrayJsonReader : AArrayJsonReader<ITraktCommentLike> | ||
{ | ||
public override async Task<IEnumerable<ITraktCommentLike>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) | ||
{ | ||
if (jsonReader == null) | ||
return await Task.FromResult(default(IEnumerable<ITraktCommentLike>)); | ||
|
||
if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) | ||
{ | ||
var commentLikeReader = new CommentLikeObjectJsonReader(); | ||
//var commentLikeReadingTasks = new List<Task<ITraktCommentLike>>(); | ||
var commentLikes = new List<ITraktCommentLike>(); | ||
|
||
//commentLikeReadingTasks.Add(commentLikeReader.ReadObjectAsync(jsonReader, cancellationToken)); | ||
ITraktCommentLike commentLike = await commentLikeReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
|
||
while (commentLike != null) | ||
{ | ||
commentLikes.Add(commentLike); | ||
//commentLikeReadingTasks.Add(commentLikeReader.ReadObjectAsync(jsonReader, cancellationToken)); | ||
commentLike = await commentLikeReader.ReadObjectAsync(jsonReader, cancellationToken); | ||
} | ||
|
||
//var readCommentLikes = await Task.WhenAll(commentLikeReadingTasks); | ||
//return (IEnumerable<ITraktCommentLike>)readCommentLikes.GetEnumerator(); | ||
return commentLikes; | ||
} | ||
|
||
return await Task.FromResult(default(IEnumerable<ITraktCommentLike>)); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Source/Lib/TraktApiSharp/Objects/Basic/Json/Reader/CommentLikeObjectJsonReader.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,51 @@ | ||
namespace TraktApiSharp.Objects.Basic.Json.Reader | ||
{ | ||
using Get.Users.Json.Reader; | ||
using Newtonsoft.Json; | ||
using Objects.Json; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal class CommentLikeObjectJsonReader : AObjectJsonReader<ITraktCommentLike> | ||
{ | ||
public override async Task<ITraktCommentLike> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) | ||
{ | ||
if (jsonReader == null) | ||
return await Task.FromResult(default(ITraktCommentLike)); | ||
|
||
if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject) | ||
{ | ||
ITraktCommentLike traktCommentLike = new TraktCommentLike(); | ||
var userObjectJsonReader = new UserObjectJsonReader(); | ||
|
||
while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName) | ||
{ | ||
var propertyName = jsonReader.Value.ToString(); | ||
|
||
switch (propertyName) | ||
{ | ||
case JsonProperties.COMMENT_LIKE_PROPERTY_NAME_LIKED_AT: | ||
{ | ||
var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken).ConfigureAwait(false); | ||
|
||
if (value.First) | ||
traktCommentLike.LikedAt = value.Second; | ||
|
||
break; | ||
} | ||
case JsonProperties.COMMENT_LIKE_PROPERTY_NAME_USER: | ||
traktCommentLike.User = await userObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false); | ||
break; | ||
default: | ||
await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken).ConfigureAwait(false); | ||
break; | ||
} | ||
} | ||
|
||
return traktCommentLike; | ||
} | ||
|
||
return await Task.FromResult(default(ITraktCommentLike)); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Source/Lib/TraktApiSharp/Objects/Basic/Json/Writer/CommentLikeObjectJsonWriter.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.Objects.Basic.Json.Writer | ||
{ | ||
using Extensions; | ||
using Get.Users.Json.Writer; | ||
using Newtonsoft.Json; | ||
using Objects.Json; | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
internal class CommentLikeObjectJsonWriter : AObjectJsonWriter<ITraktCommentLike> | ||
{ | ||
public override async Task WriteObjectAsync(JsonTextWriter jsonWriter, ITraktCommentLike obj, CancellationToken cancellationToken = default) | ||
{ | ||
if (jsonWriter == null) | ||
throw new ArgumentNullException(nameof(jsonWriter)); | ||
|
||
await jsonWriter.WriteStartObjectAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
if (obj.LikedAt.HasValue) | ||
{ | ||
await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_LIKE_PROPERTY_NAME_LIKED_AT, cancellationToken).ConfigureAwait(false); | ||
await jsonWriter.WriteValueAsync(obj.LikedAt.Value.ToTraktLongDateTimeString(), cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
if (obj.User != null) | ||
{ | ||
var userObjectJsonWriter = new UserObjectJsonWriter(); | ||
await jsonWriter.WritePropertyNameAsync(JsonProperties.COMMENT_LIKE_PROPERTY_NAME_USER, cancellationToken).ConfigureAwait(false); | ||
await userObjectJsonWriter.WriteObjectAsync(jsonWriter, obj.User, cancellationToken).ConfigureAwait(false); | ||
} | ||
|
||
await jsonWriter.WriteEndObjectAsync(cancellationToken).ConfigureAwait(false); | ||
} | ||
} | ||
} |
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
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
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