Skip to content

Commit

Permalink
GH-33: Implement missing json readers for show objects
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikfroehling committed Aug 11, 2018
1 parent bcb0bbf commit 3a88dcc
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using Get.Shows.Json.Reader;
using Get.Shows.Json.Writer;
using Objects.Json;
using System;

internal class ShowAirsJsonIOFactory : IJsonIOFactory<ITraktShowAirs>
{
public IObjectJsonReader<ITraktShowAirs> CreateObjectReader() => new ShowAirsObjectJsonReader();

public IArrayJsonReader<ITraktShowAirs> CreateArrayReader()
=> throw new NotSupportedException($"A array json reader for {nameof(ITraktShowAirs)} is not supported.");
public IArrayJsonReader<ITraktShowAirs> CreateArrayReader() => new ShowAirsArrayJsonReader();

public IObjectJsonWriter<ITraktShowAirs> CreateObjectWriter() => new ShowAirsObjectJsonWriter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using Get.Shows.Json.Reader;
using Get.Shows.Json.Writer;
using Objects.Json;
using System;

internal class ShowCollectionProgressJsonIOFactory : IJsonIOFactory<ITraktShowCollectionProgress>
{
public IObjectJsonReader<ITraktShowCollectionProgress> CreateObjectReader() => new ShowCollectionProgressObjectJsonReader();

public IArrayJsonReader<ITraktShowCollectionProgress> CreateArrayReader()
=> throw new NotSupportedException($"A array json reader for {nameof(ITraktShowCollectionProgress)} is not supported.");
public IArrayJsonReader<ITraktShowCollectionProgress> CreateArrayReader() => new ShowCollectionProgressArrayJsonReader();

public IObjectJsonWriter<ITraktShowCollectionProgress> CreateObjectWriter() => new ShowCollectionProgressObjectJsonWriter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using Get.Shows.Json.Reader;
using Get.Shows.Json.Writer;
using Objects.Json;
using System;

internal class ShowIdsJsonIOFactory : IJsonIOFactory<ITraktShowIds>
{
public IObjectJsonReader<ITraktShowIds> CreateObjectReader() => new ShowIdsObjectJsonReader();

public IArrayJsonReader<ITraktShowIds> CreateArrayReader()
=> throw new NotSupportedException($"A array json reader for {nameof(ITraktShowIds)} is not supported.");
public IArrayJsonReader<ITraktShowIds> CreateArrayReader() => new ShowIdsArrayJsonReader();

public IObjectJsonWriter<ITraktShowIds> CreateObjectWriter() => new ShowIdsObjectJsonWriter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
using Get.Shows.Json.Reader;
using Get.Shows.Json.Writer;
using Objects.Json;
using System;

internal class ShowWatchedProgressJsonIOFactory : IJsonIOFactory<ITraktShowWatchedProgress>
{
public IObjectJsonReader<ITraktShowWatchedProgress> CreateObjectReader() => new ShowWatchedProgressObjectJsonReader();

public IArrayJsonReader<ITraktShowWatchedProgress> CreateArrayReader()
=> throw new NotSupportedException($"A array json reader for {nameof(ITraktShowWatchedProgress)} is not supported.");
public IArrayJsonReader<ITraktShowWatchedProgress> CreateArrayReader() => new ShowWatchedProgressArrayJsonReader();

public IObjectJsonWriter<ITraktShowWatchedProgress> CreateObjectWriter() => new ShowWatchedProgressObjectJsonWriter();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ITraktShowAirs>
{
public override async Task<IEnumerable<ITraktShowAirs>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
{
if (jsonReader == null)
return await Task.FromResult(default(IEnumerable<ITraktShowAirs>));

if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
{
var showAirsReader = new ShowAirsObjectJsonReader();
var showAirss = new List<ITraktShowAirs>();
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<ITraktShowAirs>));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ITraktShowCollectionProgress>
{
public override async Task<IEnumerable<ITraktShowCollectionProgress>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
{
if (jsonReader == null)
return await Task.FromResult(default(IEnumerable<ITraktShowCollectionProgress>));

if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
{
var showCollectionProgressReader = new ShowCollectionProgressObjectJsonReader();
var showCollectionProgresses = new List<ITraktShowCollectionProgress>();
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<ITraktShowCollectionProgress>));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ITraktShowIds>
{
public override async Task<IEnumerable<ITraktShowIds>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
{
if (jsonReader == null)
return await Task.FromResult(default(IEnumerable<ITraktShowIds>));

if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
{
var showIdsReader = new ShowIdsObjectJsonReader();
var showIdss = new List<ITraktShowIds>();
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<ITraktShowIds>));
}
}
}
Original file line number Diff line number Diff line change
@@ -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<ITraktShowWatchedProgress>
{
public override async Task<IEnumerable<ITraktShowWatchedProgress>> ReadArrayAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
{
if (jsonReader == null)
return await Task.FromResult(default(IEnumerable<ITraktShowWatchedProgress>));

if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartArray)
{
var showWatchedProgressReader = new ShowWatchedProgressObjectJsonReader();
var showWatchedProgresses = new List<ITraktShowWatchedProgress>();
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<ITraktShowWatchedProgress>));
}
}
}

0 comments on commit 3a88dcc

Please sign in to comment.