From 3a88dcc39e000c9f32f4fc73269fdef0cdf076fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Fr=C3=B6hling?= Date: Sat, 11 Aug 2018 22:34:45 +0200 Subject: [PATCH] GH-33: Implement missing json readers for show objects --- .../Json/Factories/ShowAirsJsonIOFactory.cs | 4 +-- .../ShowCollectionProgressJsonIOFactory.cs | 4 +-- .../Json/Factories/ShowIdsJsonIOFactory.cs | 4 +-- .../ShowWatchedProgressJsonIOFactory.cs | 4 +-- .../Json/Reader/ShowAirsArrayJsonReader.cs | 34 +++++++++++++++++++ .../ShowCollectionProgressArrayJsonReader.cs | 34 +++++++++++++++++++ .../Json/Reader/ShowIdsArrayJsonReader.cs | 34 +++++++++++++++++++ .../ShowWatchedProgressArrayJsonReader.cs | 34 +++++++++++++++++++ 8 files changed, 140 insertions(+), 12 deletions(-) create mode 100644 Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowAirsArrayJsonReader.cs create mode 100644 Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowCollectionProgressArrayJsonReader.cs create mode 100644 Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowIdsArrayJsonReader.cs create mode 100644 Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowWatchedProgressArrayJsonReader.cs diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowAirsJsonIOFactory.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowAirsJsonIOFactory.cs index da8f9a553c..77008f2f0b 100644 --- a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowAirsJsonIOFactory.cs +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowAirsJsonIOFactory.cs @@ -3,14 +3,12 @@ using Get.Shows.Json.Reader; using Get.Shows.Json.Writer; using Objects.Json; - using System; internal class ShowAirsJsonIOFactory : IJsonIOFactory { public IObjectJsonReader CreateObjectReader() => new ShowAirsObjectJsonReader(); - public IArrayJsonReader CreateArrayReader() - => throw new NotSupportedException($"A array json reader for {nameof(ITraktShowAirs)} is not supported."); + public IArrayJsonReader CreateArrayReader() => new ShowAirsArrayJsonReader(); public IObjectJsonWriter CreateObjectWriter() => new ShowAirsObjectJsonWriter(); } diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowCollectionProgressJsonIOFactory.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowCollectionProgressJsonIOFactory.cs index 518509181e..40a3258bab 100644 --- a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowCollectionProgressJsonIOFactory.cs +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowCollectionProgressJsonIOFactory.cs @@ -3,14 +3,12 @@ using Get.Shows.Json.Reader; using Get.Shows.Json.Writer; using Objects.Json; - using System; internal class ShowCollectionProgressJsonIOFactory : IJsonIOFactory { public IObjectJsonReader CreateObjectReader() => new ShowCollectionProgressObjectJsonReader(); - public IArrayJsonReader CreateArrayReader() - => throw new NotSupportedException($"A array json reader for {nameof(ITraktShowCollectionProgress)} is not supported."); + public IArrayJsonReader CreateArrayReader() => new ShowCollectionProgressArrayJsonReader(); public IObjectJsonWriter CreateObjectWriter() => new ShowCollectionProgressObjectJsonWriter(); } diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowIdsJsonIOFactory.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowIdsJsonIOFactory.cs index 8a7e7cf5dc..4c89c56a10 100644 --- a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowIdsJsonIOFactory.cs +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowIdsJsonIOFactory.cs @@ -3,14 +3,12 @@ using Get.Shows.Json.Reader; using Get.Shows.Json.Writer; using Objects.Json; - using System; internal class ShowIdsJsonIOFactory : IJsonIOFactory { public IObjectJsonReader CreateObjectReader() => new ShowIdsObjectJsonReader(); - public IArrayJsonReader CreateArrayReader() - => throw new NotSupportedException($"A array json reader for {nameof(ITraktShowIds)} is not supported."); + public IArrayJsonReader CreateArrayReader() => new ShowIdsArrayJsonReader(); public IObjectJsonWriter CreateObjectWriter() => new ShowIdsObjectJsonWriter(); } diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowWatchedProgressJsonIOFactory.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowWatchedProgressJsonIOFactory.cs index a23b6b3729..96e68f838c 100644 --- a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowWatchedProgressJsonIOFactory.cs +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Factories/ShowWatchedProgressJsonIOFactory.cs @@ -3,14 +3,12 @@ using Get.Shows.Json.Reader; using Get.Shows.Json.Writer; using Objects.Json; - using System; internal class ShowWatchedProgressJsonIOFactory : IJsonIOFactory { public IObjectJsonReader CreateObjectReader() => new ShowWatchedProgressObjectJsonReader(); - public IArrayJsonReader CreateArrayReader() - => throw new NotSupportedException($"A array json reader for {nameof(ITraktShowWatchedProgress)} is not supported."); + public IArrayJsonReader CreateArrayReader() => new ShowWatchedProgressArrayJsonReader(); public IObjectJsonWriter CreateObjectWriter() => new ShowWatchedProgressObjectJsonWriter(); } diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowAirsArrayJsonReader.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowAirsArrayJsonReader.cs new file mode 100644 index 0000000000..30821c5f97 --- /dev/null +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowAirsArrayJsonReader.cs @@ -0,0 +1,34 @@ +namespace TraktNet.Objects.Get.Shows.Json.Reader +{ + using Newtonsoft.Json; + using Objects.Json; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + internal class ShowAirsArrayJsonReader : AArrayJsonReader + { + public override async Task> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) + { + if (jsonReader == null) + return await Task.FromResult(default(IEnumerable)); + + if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) + { + var showAirsReader = new ShowAirsObjectJsonReader(); + var showAirss = new List(); + ITraktShowAirs showAirs = await showAirsReader.ReadObjectAsync(jsonReader, cancellationToken); + + while (showAirs != null) + { + showAirss.Add(showAirs); + showAirs = await showAirsReader.ReadObjectAsync(jsonReader, cancellationToken); + } + + return showAirss; + } + + return await Task.FromResult(default(IEnumerable)); + } + } +} diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowCollectionProgressArrayJsonReader.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowCollectionProgressArrayJsonReader.cs new file mode 100644 index 0000000000..9f7695eae8 --- /dev/null +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowCollectionProgressArrayJsonReader.cs @@ -0,0 +1,34 @@ +namespace TraktNet.Objects.Get.Shows.Json.Reader +{ + using Newtonsoft.Json; + using Objects.Json; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + internal class ShowCollectionProgressArrayJsonReader : AArrayJsonReader + { + public override async Task> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) + { + if (jsonReader == null) + return await Task.FromResult(default(IEnumerable)); + + if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) + { + var showCollectionProgressReader = new ShowCollectionProgressObjectJsonReader(); + var showCollectionProgresses = new List(); + ITraktShowCollectionProgress showCollectionProgress = await showCollectionProgressReader.ReadObjectAsync(jsonReader, cancellationToken); + + while (showCollectionProgress != null) + { + showCollectionProgresses.Add(showCollectionProgress); + showCollectionProgress = await showCollectionProgressReader.ReadObjectAsync(jsonReader, cancellationToken); + } + + return showCollectionProgresses; + } + + return await Task.FromResult(default(IEnumerable)); + } + } +} diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowIdsArrayJsonReader.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowIdsArrayJsonReader.cs new file mode 100644 index 0000000000..252386fcfc --- /dev/null +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowIdsArrayJsonReader.cs @@ -0,0 +1,34 @@ +namespace TraktNet.Objects.Get.Shows.Json.Reader +{ + using Newtonsoft.Json; + using Objects.Json; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + internal class ShowIdsArrayJsonReader : AArrayJsonReader + { + public override async Task> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) + { + if (jsonReader == null) + return await Task.FromResult(default(IEnumerable)); + + if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) + { + var showIdsReader = new ShowIdsObjectJsonReader(); + var showIdss = new List(); + ITraktShowIds showIds = await showIdsReader.ReadObjectAsync(jsonReader, cancellationToken); + + while (showIds != null) + { + showIdss.Add(showIds); + showIds = await showIdsReader.ReadObjectAsync(jsonReader, cancellationToken); + } + + return showIdss; + } + + return await Task.FromResult(default(IEnumerable)); + } + } +} diff --git a/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowWatchedProgressArrayJsonReader.cs b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowWatchedProgressArrayJsonReader.cs new file mode 100644 index 0000000000..bd1d4c4b96 --- /dev/null +++ b/Source/Lib/Trakt.NET/Objects/Get/Shows/Json/Reader/ShowWatchedProgressArrayJsonReader.cs @@ -0,0 +1,34 @@ +namespace TraktNet.Objects.Get.Shows.Json.Reader +{ + using Newtonsoft.Json; + using Objects.Json; + using System.Collections.Generic; + using System.Threading; + using System.Threading.Tasks; + + internal class ShowWatchedProgressArrayJsonReader : AArrayJsonReader + { + public override async Task> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default) + { + if (jsonReader == null) + return await Task.FromResult(default(IEnumerable)); + + if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray) + { + var showWatchedProgressReader = new ShowWatchedProgressObjectJsonReader(); + var showWatchedProgresses = new List(); + ITraktShowWatchedProgress showWatchedProgress = await showWatchedProgressReader.ReadObjectAsync(jsonReader, cancellationToken); + + while (showWatchedProgress != null) + { + showWatchedProgresses.Add(showWatchedProgress); + showWatchedProgress = await showWatchedProgressReader.ReadObjectAsync(jsonReader, cancellationToken); + } + + return showWatchedProgresses; + } + + return await Task.FromResult(default(IEnumerable)); + } + } +}