diff --git a/License.txt b/License.txt index 0266604..aa051f7 100644 --- a/License.txt +++ b/License.txt @@ -1,5 +1,14 @@ -Copyright (c) 2012, Daniel Widegren daniel@widegren.org +Copyright (c) 2012, Daniel Widegren +Copyright (c) 2015, Iris Ward -Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. \ No newline at end of file diff --git a/Readme.md b/Readme.md index 6a88f8e..330f0bd 100644 --- a/Readme.md +++ b/Readme.md @@ -1,9 +1,10 @@ ## C-Sharp-API-Client This is a simple API Client for WaniKani to speed up projects written in .NET -Current API version is 1.1 +Current API version is 1.4 Copyright (c) 2012, Daniel Widegren -All code is licensed under the MIT License, Please read License.txt for more information. +Copyright (c) 2015, Iris Ward +All code is licensed under the ISC License, Please read License.txt for more information. ## How to use: Include the dll or code into your project. diff --git a/WaniKaniApp.sln b/WaniKaniApp.sln index f79b939..a3d2bda 100644 --- a/WaniKaniApp.sln +++ b/WaniKaniApp.sln @@ -1,6 +1,6 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaniKaniClientDemo", "WaniKaniApp\WaniKaniClientDemo.csproj", "{AC47E8F6-4436-4FFF-AF3D-F3F7A538696F}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaniKaniClientLib", "WaniKaniClient\WaniKaniClientLib.csproj", "{6546956C-826B-4A5C-B639-A0F909C68F31}" diff --git a/WaniKaniClient/Models/BaseCharacter.cs b/WaniKaniClient/Models/BaseCharacter.cs index 628db73..e352b58 100644 --- a/WaniKaniClient/Models/BaseCharacter.cs +++ b/WaniKaniClient/Models/BaseCharacter.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace WaniKaniClientLib.Models { @@ -13,19 +9,7 @@ public class BaseCharacter public string Meaning { get; set; } public int Level { get; set; } - [JsonProperty("unlocked_date")] - public long UnlockTimeStamp { get; set; } - public DateTime UnlockedDate - { - get - { - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(UnlockTimeStamp); - } - } - - public string Percentage { get; set; } - + [JsonProperty("user_specific")] public Stats Stats { get; set; } } } diff --git a/WaniKaniClient/Models/Kanji.cs b/WaniKaniClient/Models/Kanji.cs index a8dfd4d..f0460c6 100644 --- a/WaniKaniClient/Models/Kanji.cs +++ b/WaniKaniClient/Models/Kanji.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace WaniKaniClientLib.Models { @@ -14,7 +10,8 @@ public Kanji() } public string Onyomi { get; set; } - public string kunyomi { get; set; } + public string Kunyomi { get; set; } + public string Nanori { get; set; } [JsonProperty("important_reading")] public string ImportantReading { get; set; } diff --git a/WaniKaniClient/Models/LevelProgression.cs b/WaniKaniClient/Models/LevelProgression.cs index 6eb461b..2d3d747 100644 --- a/WaniKaniClient/Models/LevelProgression.cs +++ b/WaniKaniClient/Models/LevelProgression.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace WaniKaniClientLib.Models { diff --git a/WaniKaniClient/Models/Radical.cs b/WaniKaniClient/Models/Radical.cs index da00a94..6bce5b0 100644 --- a/WaniKaniClient/Models/Radical.cs +++ b/WaniKaniClient/Models/Radical.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WaniKaniClientLib.Models +namespace WaniKaniClientLib.Models { public class Radical : BaseCharacter { diff --git a/WaniKaniClient/Models/SrsDistribution.cs b/WaniKaniClient/Models/SrsDistribution.cs index 688c45b..58a91de 100644 --- a/WaniKaniClient/Models/SrsDistribution.cs +++ b/WaniKaniClient/Models/SrsDistribution.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WaniKaniClientLib.Models +namespace WaniKaniClientLib.Models { public class SrsDistribution { diff --git a/WaniKaniClient/Models/SrsDistributionItem.cs b/WaniKaniClient/Models/SrsDistributionItem.cs index 2f77124..41641dc 100644 --- a/WaniKaniClient/Models/SrsDistributionItem.cs +++ b/WaniKaniClient/Models/SrsDistributionItem.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WaniKaniClientLib.Models +namespace WaniKaniClientLib.Models { public class SrsDistributionItem { diff --git a/WaniKaniClient/Models/Stats.cs b/WaniKaniClient/Models/Stats.cs index c33b9fd..1a303d3 100644 --- a/WaniKaniClient/Models/Stats.cs +++ b/WaniKaniClient/Models/Stats.cs @@ -1,14 +1,20 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; +using WaniKaniClientLib.Utils; namespace WaniKaniClientLib.Models { public class Stats { public string Srs { get; set; } + + // The precise stage of SRS the learning item is currently at. + // Stages 1 to 4 fall within "Apprentice"; stages 5 & 6 are "Guru"; + // Stages 7, 8 and 9 are "Master", "Enlightened" and "Burned" + // respectively + [JsonProperty("srs_numeric")] + public int SrsLevel { get; set; } + public bool Burned { get; set; } [JsonProperty("meaning_correct")] @@ -44,8 +50,7 @@ public DateTime? UnlockedDate if (UnlockedTimeStamp == 0) return null; - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(UnlockedTimeStamp); + return Utilities.UnixEpoch.AddSeconds(UnlockedTimeStamp); } } @@ -58,8 +63,7 @@ public DateTime? AvailableDate if (AvailableTimeStamp == 0) return null; - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(AvailableTimeStamp); + return Utilities.UnixEpoch.AddSeconds(AvailableTimeStamp); } } @@ -72,10 +76,18 @@ public DateTime? BurnedDate if (BurnedTimeStamp == 0) return null; - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(BurnedTimeStamp); + return Utilities.UnixEpoch.AddSeconds(BurnedTimeStamp); } } + + [JsonProperty("meaning_note")] + public string MeaningNote { get; set; } + + [JsonProperty("reading_note")] + public string ReadingNote { get; set; } + + [JsonProperty("user_synonyms")] + public string UserSynonyms { get; set; } } } diff --git a/WaniKaniClient/Models/StudyQueue.cs b/WaniKaniClient/Models/StudyQueue.cs index 7ea3e28..9e831fd 100644 --- a/WaniKaniClient/Models/StudyQueue.cs +++ b/WaniKaniClient/Models/StudyQueue.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; +using WaniKaniClientLib.Utils; namespace WaniKaniClientLib.Models { @@ -20,8 +18,7 @@ public DateTime NextReviewDate { get { - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(NextReviewTimeStamp); + return Utilities.UnixEpoch.AddSeconds(NextReviewTimeStamp); } } diff --git a/WaniKaniClient/Models/UserInformation.cs b/WaniKaniClient/Models/UserInformation.cs index 3ccb416..63e4675 100644 --- a/WaniKaniClient/Models/UserInformation.cs +++ b/WaniKaniClient/Models/UserInformation.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; +using WaniKaniClientLib.Utils; namespace WaniKaniClientLib.Models { @@ -24,14 +22,28 @@ public class UserInformation [JsonProperty("creation_date")] public long CreationTimeStamp { get; set; } - public DateTime CreatioDate + public DateTime CreationDate { get { - var date = new DateTime(1970, 1, 1, 0, 0, 0, 0); - return date.AddSeconds(CreationTimeStamp); + return Utilities.UnixEpoch.AddSeconds(CreationTimeStamp); } } + // We have to use a nullable long here as the vacation date is passed as "null" in the API + // if the user is not on vacation, rather than being omitted as in learning items + [JsonProperty("vacation_date")] + public long? VacationTimeStamp { get; set; } + public DateTime? VacationDate + { + get + { + if (VacationTimeStamp.HasValue) + { + return Utilities.UnixEpoch.AddSeconds(VacationTimeStamp.Value); + } + return null; + } + } } } diff --git a/WaniKaniClient/Models/Vocabulary.cs b/WaniKaniClient/Models/Vocabulary.cs index 1a1f040..bcf2539 100644 --- a/WaniKaniClient/Models/Vocabulary.cs +++ b/WaniKaniClient/Models/Vocabulary.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace WaniKaniClientLib.Models +namespace WaniKaniClientLib.Models { public class Vocabulary : BaseCharacter { diff --git a/WaniKaniClient/Utils/Extensions.cs b/WaniKaniClient/Utils/Extensions.cs new file mode 100644 index 0000000..801310d --- /dev/null +++ b/WaniKaniClient/Utils/Extensions.cs @@ -0,0 +1,9 @@ +using System; + +namespace WaniKaniClientLib.Utils +{ + internal static class Utilities + { + public static DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); + } +} diff --git a/WaniKaniClient/WaniKaniClient.cs b/WaniKaniClient/WaniKaniClient.cs index adffab8..36f3d8b 100644 --- a/WaniKaniClient/WaniKaniClient.cs +++ b/WaniKaniClient/WaniKaniClient.cs @@ -13,7 +13,7 @@ namespace WaniKaniClientLib public class WaniKaniClient { public string APIKey { get; private set; } - public static readonly string ApiVersion = "v1.1"; + public static readonly string ApiVersion = "v1.4"; public int CacheInMinutes { get; set; } private UserInformation _cachedUserInformation; @@ -262,6 +262,7 @@ private string BuildUrl(string resource = null, string optionalArgument = null) private JObject Request(string resource = null, string optionalArgument = null) { WebClient httpClient = new WebClient(); + httpClient.Encoding = Encoding.UTF8; string responce = httpClient.DownloadString(BuildUrl(resource, optionalArgument)); return JObject.Parse(responce); diff --git a/WaniKaniClient/WaniKaniClientLib.csproj b/WaniKaniClient/WaniKaniClientLib.csproj index 984558e..43a65c4 100644 --- a/WaniKaniClient/WaniKaniClientLib.csproj +++ b/WaniKaniClient/WaniKaniClientLib.csproj @@ -54,6 +54,7 @@ +