Skip to content

Commit

Permalink
Implement Info/GetEntryTags of the new API #45
Browse files Browse the repository at this point in the history
  • Loading branch information
wbpascal committed Aug 8, 2016
1 parent 4037b61 commit b0a2526
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Azuria.Portable/Azuria.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
<Compile Include="..\Azuria\AnimeManga\Properties\StreamPartner.cs">
<Link>AnimeManga\Properties\StreamPartner.cs</Link>
</Compile>
<Compile Include="..\Azuria\AnimeManga\Properties\Tag.cs">
<Link>AnimeManga\Properties\Tag.cs</Link>
</Compile>
<Compile Include="..\Azuria\AnimeManga\Properties\TagType.cs">
<Link>AnimeManga\Properties\TagType.cs</Link>
</Compile>
Expand Down Expand Up @@ -156,6 +159,9 @@
<Compile Include="..\Azuria\Api\v1\Converters\Info\StreamPartnerConverter.cs">
<Link>Api\v1\Converters\Info\StreamPartnerConverter.cs</Link>
</Compile>
<Compile Include="..\Azuria\Api\v1\Converters\IntToBoolConverter.cs">
<Link>Api\v1\Converters\IntToBoolConverter.cs</Link>
</Compile>
<Compile Include="..\Azuria\Api\v1\Converters\MediumConverter.cs">
<Link>Api\v1\Converters\MediumConverter.cs</Link>
</Compile>
Expand All @@ -177,6 +183,9 @@
<Compile Include="..\Azuria\Api\v1\DataModels\Info\EntryDataModel.cs">
<Link>Api\v1\DataModels\Info\EntryDataModel.cs</Link>
</Compile>
<Compile Include="..\Azuria\Api\v1\DataModels\Info\EntryTagDataModel.cs">
<Link>Api\v1\DataModels\Info\EntryTagDataModel.cs</Link>
</Compile>
<Compile Include="..\Azuria\Api\v1\DataModels\Info\GroupDataModel.cs">
<Link>Api\v1\DataModels\Info\GroupDataModel.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions Azuria/AnimeManga/Anime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ internal Anime()
{
IsInitialisedOnce = false
};
this.Tags = new InitialisableProperty<IEnumerable<Tag>>(() => this.InitEntryTagsApi(this._senpai));
}

internal Anime([NotNull] string name, int id, [NotNull] Senpai senpai) : this()
Expand Down Expand Up @@ -236,6 +237,11 @@ internal Anime(RelationDataModel dataModel, Senpai senpai) : this((EntryDataMode
/// </summary>
public InitialisableProperty<string> Synonym { get; }

/// <summary>
/// Gets the tags the <see cref="Anime" /> was tagged with.
/// </summary>
public InitialisableProperty<IEnumerable<Tag>> Tags { get; }

#endregion

#region Inherited
Expand Down
5 changes: 5 additions & 0 deletions Azuria/AnimeManga/IAnimeMangaObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ public interface IAnimeMangaObject : ISearchableObject
[NotNull]
InitialisableProperty<string> Synonym { get; }

/// <summary>
/// Gets the tags the <see cref="Anime" /> or <see cref="Manga" /> was tagged with.
/// </summary>
InitialisableProperty<IEnumerable<Tag>> Tags { get; }

#endregion

#region
Expand Down
6 changes: 6 additions & 0 deletions Azuria/AnimeManga/Manga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ internal Manga()
{
IsInitialisedOnce = false
};
this.Tags = new InitialisableProperty<IEnumerable<Tag>>(() => this.InitEntryTagsApi(this._senpai));
}

internal Manga([NotNull] string name, int id, [NotNull] Senpai senpai) : this()
Expand Down Expand Up @@ -237,6 +238,11 @@ internal Manga(RelationDataModel dataModel, Senpai senpai) : this((EntryDataMode
/// </summary>
public InitialisableProperty<string> Synonym { get; }

/// <summary>
/// Gets the tags the <see cref="Manga" /> was tagged with.
/// </summary>
public InitialisableProperty<IEnumerable<Tag>> Tags { get; }

#endregion

#region Inherited
Expand Down
32 changes: 32 additions & 0 deletions Azuria/AnimeManga/Properties/Tag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Azuria.Api.v1.DataModels.Info;

namespace Azuria.AnimeManga.Properties
{
/// <summary>
/// </summary>
public class Tag
{
internal Tag(EntryTagDataModel dataModel)
{
this.TagType = dataModel.Tag;
this.IsRated = dataModel.IsRated;
this.IsSpoiler = dataModel.IsSpoiler;
}

#region Properties

/// <summary>
/// </summary>
public bool IsRated { get; set; }

/// <summary>
/// </summary>
public bool IsSpoiler { get; set; }

/// <summary>
/// </summary>
public TagType TagType { get; set; }

#endregion
}
}
8 changes: 8 additions & 0 deletions Azuria/Api/v1/ApiRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ internal static ApiRequest<EntryDataModel> BuildForGetEntry(int entryId, Senpai
};
}

internal static ApiRequest<EntryTagDataModel[]> BuildForGetEntryTags(int entryId, Senpai senpai)
{
return new ApiRequest<EntryTagDataModel[]>(senpai)
{
Address = new Uri($"{ApiAddress}/info/entrytags?id={entryId}")
};
}

internal static ApiRequest<bool> BuildForGetGate(int entryId, Senpai senpai)
{
return new ApiRequest<bool>(senpai)
Expand Down
45 changes: 45 additions & 0 deletions Azuria/Api/v1/Converters/IntToBoolConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using Newtonsoft.Json;

namespace Azuria.Api.v1.Converters
{
internal class IntToBoolConverter : JsonConverter
{
#region

/// <summary>
/// Determines whether this instance can convert the specified object type.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <returns>
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
/// </returns>
public override bool CanConvert(Type objectType)
{
return objectType == typeof(int);
}

/// <summary>Reads the JSON representation of the object.</summary>
/// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader" /> to read from.</param>
/// <param name="objectType">Type of the object.</param>
/// <param name="existingValue">The existing value of object being read.</param>
/// <param name="serializer">The calling serializer.</param>
/// <returns>The object value.</returns>
public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
JsonSerializer serializer)
{
return Convert.ToInt32(reader.Value) == 1;
}

/// <summary>Writes the JSON representation of the object.</summary>
/// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
/// <param name="value">The value.</param>
/// <param name="serializer">The calling serializer.</param>
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
writer.WriteValue((bool) value ? 1 : 0);
}

#endregion
}
}
25 changes: 25 additions & 0 deletions Azuria/Api/v1/DataModels/Info/EntryTagDataModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Azuria.AnimeManga.Properties;
using Azuria.Api.v1.Converters;
using Newtonsoft.Json;

namespace Azuria.Api.v1.DataModels.Info
{
internal class EntryTagDataModel : IDataModel
{
#region Properties

[JsonProperty("id")]
internal int Id { get; set; }

[JsonProperty("rate_flag"), JsonConverter(typeof(IntToBoolConverter))]
internal bool IsRated { get; set; }

[JsonProperty("spoiler_flag"), JsonConverter(typeof(IntToBoolConverter))]
internal bool IsSpoiler { get; set; }

[JsonProperty("tid")]
internal TagType Tag { get; set; }

#endregion
}
}
3 changes: 3 additions & 0 deletions Azuria/Azuria.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@
<Compile Include="AnimeManga\Properties\MangaType.cs" />
<Compile Include="AnimeManga\Properties\Season.cs" />
<Compile Include="AnimeManga\Properties\StreamPartner.cs" />
<Compile Include="AnimeManga\Properties\Tag.cs" />
<Compile Include="AnimeManga\Properties\TagType.cs" />
<Compile Include="Api\ApiInfo.cs" />
<Compile Include="Api\v1\ApiRequest.cs" />
<Compile Include="Api\v1\ApiRequestBuilder.cs" />
<Compile Include="Api\v1\Converters\Info\LanguageConverter.cs" />
<Compile Include="Api\v1\Converters\Info\LanguageKommaCollectionConverter.cs" />
<Compile Include="Api\v1\Converters\Info\StreamPartnerConverter.cs" />
<Compile Include="Api\v1\Converters\IntToBoolConverter.cs" />
<Compile Include="Api\v1\Converters\SubRatingsConverter.cs" />
<Compile Include="Api\v1\DataModels\Info\AnimeMangaContentDataModel.cs" />
<Compile Include="Api\v1\DataModels\Info\CommentDataModel.cs" />
Expand All @@ -101,6 +103,7 @@
<Compile Include="Api\v1\DataModels\Info\PublisherDataModel.cs" />
<Compile Include="Api\v1\DataModels\Info\RelationDataModel.cs" />
<Compile Include="Api\v1\DataModels\Info\SeasonDataModel.cs" />
<Compile Include="Api\v1\DataModels\Info\EntryTagDataModel.cs" />
<Compile Include="Api\v1\DataModels\User\ListDataModel.cs" />
<Compile Include="Api\v1\DataModels\User\ToptenDataModel.cs" />
<Compile Include="Api\v1\DataModels\User\UserInfoDataModel.cs" />
Expand Down
5 changes: 4 additions & 1 deletion Azuria/Security/SecureStringContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public class SecureStringContainer : ISecureContainer<char[]>
{
private SecureString _secureString;

internal SecureStringContainer()
/// <summary>
/// Default constructor.
/// </summary>
public SecureStringContainer()
{
this._secureString = new SecureString();
}
Expand Down
11 changes: 11 additions & 0 deletions Azuria/Utilities/Extensions/AnimeMangaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ internal static async Task<ProxerResult> InitAvailableLangApi(this IAnimeMangaOb
return new ProxerResult();
}

internal static async Task<ProxerResult> InitEntryTagsApi(this IAnimeMangaObject animeMangaObject, Senpai senpai)
{
ProxerResult<ProxerApiResponse<EntryTagDataModel[]>> lResult =
await RequestHandler.ApiRequest(ApiRequestBuilder.BuildForGetEntryTags(animeMangaObject.Id, senpai));
if (!lResult.Success || lResult.Result == null) return new ProxerResult(lResult.Exceptions);

animeMangaObject.Tags.SetInitialisedObject(from entryTagDataModel in lResult.Result.Data
select new Tag(entryTagDataModel));
return new ProxerResult();
}

[ItemNotNull]
internal static async Task<ProxerResult> InitGroupsApi(this IAnimeMangaObject animeMangaObject, Senpai senpai)
{
Expand Down

0 comments on commit b0a2526

Please sign in to comment.