Skip to content

Commit d519fbb

Browse files
committed
Updated XML comments and Description.
1 parent aa8fe44 commit d519fbb

File tree

3 files changed

+106
-36
lines changed

3 files changed

+106
-36
lines changed

Readme.txt

+16-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,16 @@
1-
To be filled.
1+
C-Sharp-API-Client
2+
This is a simple API Client for WaniKani to speed up projects writen in .NET
3+
4+
How to use:
5+
Include the dll or code into your project.
6+
7+
To Create a client.
8+
var client = new WaniKaniClient("theApiKey");
9+
10+
To get the latest study queue Information
11+
var studyQueue = client.StudyQueue();
12+
13+
With that you can example see how many reviews you got left.
14+
Console.WriteLine("You have {0} reviews and {1} new lessons.", studyQueue.ReviewsAvailable, studyQueue.LessonsAvailable);
15+
16+
The API got full XML documentation for every public method and pretty self explained.

WaniKaniApp/Program.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ static void Main(string[] args)
1313
Console.WriteLine("PLease enter your API key: ");
1414
string apiKey = Console.ReadLine();
1515

16-
WaniKaniClient client = new WaniKaniClient(apiKey);
16+
var client = new WaniKaniClient(apiKey);
1717

1818
var studyQueue = client.StudyQueue();
19+
studyQueue = client.StudyQueue();
1920

2021
Console.WriteLine("Hello {0}", client.UserInformation().UserName);
2122
Console.WriteLine("You have {0} reviews and {1} new lessons.", studyQueue.ReviewsAvailable, studyQueue.LessonsAvailable);

WaniKaniClient/WaniKaniClient.cs

+88-34
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,22 @@ public class WaniKaniClient
2525
private SrsDistribution _cachedSrsDistribution;
2626
private DateTime _cachedTimeSrsDistribution;
2727

28+
/// <summary>
29+
/// Creates the client object.
30+
/// </summary>
31+
/// <param name="apiKey">The users API key</param>
32+
/// <param name="cacheInMinutes">How many minutes you want requests to be cached, default is 15.</param>
2833
public WaniKaniClient(string apiKey, int cacheInMinutes = 15)
2934
{
3035
APIKey = apiKey;
3136
CacheInMinutes = cacheInMinutes;
3237
}
3338

34-
private string BuildUrl(string resource = null, string optionalArgument = null)
35-
{
36-
string url = "http://www.wanikani.com/api/" + ApiVersion + "/user/" + APIKey + "/";
37-
38-
if (resource != null)
39-
url += resource + "/";
40-
41-
if (optionalArgument != null)
42-
url += optionalArgument + "/";
43-
44-
return url;
45-
}
46-
47-
private JObject Request(string resource = null, string optionalArgument = null)
48-
{
49-
WebClient httpClient = new WebClient();
50-
string responce = httpClient.DownloadString(BuildUrl(resource, optionalArgument));
51-
52-
return JObject.Parse(responce);
53-
}
54-
39+
/// <summary>
40+
/// Get user information, you get this information from every request you do so if your smart you don't request this information the first time.
41+
/// </summary>
42+
/// <param name="noCache">No cached results if set to true</param>
43+
/// <returns>UserInformation</returns>
5544
public UserInformation UserInformation(bool noCache = false)
5645
{
5746
if (!noCache && _cachedUserInformation != null && _cachedTimeUserInformation > DateTime.Now)
@@ -63,14 +52,11 @@ public UserInformation UserInformation(bool noCache = false)
6352
return _cachedUserInformation;
6453
}
6554

66-
private void UpdateUserInformation(JObject responce)
67-
{
68-
var requestData = responce["user_information"];
69-
_cachedUserInformation = JsonConvert.DeserializeObject<UserInformation>(requestData.ToString());
70-
71-
_cachedTimeUserInformation = DateTime.Now.AddMinutes(CacheInMinutes);
72-
}
73-
55+
/// <summary>
56+
/// Retreives the StudyQueue, it contains information such as number of reviews left.
57+
/// </summary>
58+
/// <param name="noCache">No cached results if set to true</param>
59+
/// <returns>StudyQueue</returns>
7460
public StudyQueue StudyQueue(bool noCache = false)
7561
{
7662
if (!noCache && _cachedStudyQueue != null && _cachedTimeStudyQueue > DateTime.Now)
@@ -87,6 +73,11 @@ public StudyQueue StudyQueue(bool noCache = false)
8773
return _cachedStudyQueue;
8874
}
8975

76+
/// <summary>
77+
/// Retreives information about the current level progression.
78+
/// </summary>
79+
/// <param name="noCache">No cached results if set to true</param>
80+
/// <returns>LevelProgression</returns>
9081
public LevelProgression LevelProgression(bool noCache = false)
9182
{
9283
if (!noCache && _cachedLevelProgression != null && _cachedTimeLevelProgression > DateTime.Now)
@@ -103,14 +94,19 @@ public LevelProgression LevelProgression(bool noCache = false)
10394
return _cachedLevelProgression;
10495
}
10596

97+
/// <summary>
98+
/// Get the SRS detailed distrobution.
99+
/// </summary>
100+
/// <param name="noCache">No cached results if set to true</param>
101+
/// <returns>SrsDistribution</returns>
106102
public SrsDistribution SrsDistribution(bool noCache = false)
107103
{
108104
if (!noCache && _cachedSrsDistribution != null && _cachedTimeSrsDistribution > DateTime.Now)
109105
return _cachedSrsDistribution;
110106

111107
JObject responce = Request("srs-distribution");
112108
UpdateUserInformation(responce);
113-
@
109+
114110
var requestData = responce["requested_information"];
115111

116112
_cachedSrsDistribution = JsonConvert.DeserializeObject<SrsDistribution>(requestData.ToString());
@@ -139,10 +135,11 @@ public List<BaseCharacter> RecentUnlocks(int take = 10)
139135

140136

141137
/// <summary>
138+
/// Gets all items that is in the users Critical List ( Default 75% or lower)
142139
/// This request is not cached.
143140
/// </summary>
144-
/// <param name="maxPercentage"></param>
145-
/// <returns></returns>
141+
/// <param name="maxPercentage">The max % failed to retreeive.</param>
142+
/// <returns>List<BaseCharacter></returns>
146143
public List<BaseCharacter> CriticalItems(int maxPercentage = 75)
147144
{
148145
if (maxPercentage > 100)
@@ -156,6 +153,11 @@ public List<BaseCharacter> CriticalItems(int maxPercentage = 75)
156153
return JsonConvert.DeserializeObject<List<BaseCharacter>>(requestData.ToString(), new CharacterTypeCreationConverter());
157154
}
158155

156+
/// <summary>
157+
/// Get all unlocked Radicals up to given level, if no level given will get all unlocked.
158+
/// </summary>
159+
/// <param name="maxLevel">Max level to get</param>
160+
/// <returns>List of Radicals</returns>
159161
public List<Radical> Radicals(int maxLevel = 0)
160162
{
161163
if (maxLevel == 0)
@@ -169,6 +171,11 @@ public List<Radical> Radicals(int maxLevel = 0)
169171
return Radicals(string.Join(",", Enumerable.Range(1, maxLevel)));
170172
}
171173

174+
/// <summary>
175+
/// Get all unlocked Radicals from the given range of levels, Each level is comma separated, example 2,3,4. To get a single level you can just enter the level such as 5
176+
/// </summary>
177+
/// <param name="maxLevel">Max level to get</param>
178+
/// <returns>List of Radicals</returns>
172179
public List<Radical> Radicals(string levels)
173180
{
174181
JObject responce = Request("radicals", levels);
@@ -179,7 +186,11 @@ public List<Radical> Radicals(string levels)
179186
return JsonConvert.DeserializeObject<List<Radical>>(requestData.ToString());
180187
}
181188

182-
189+
/// <summary>
190+
/// Get all unlocked Kanji up to given level, if no level given will get all unlocked.
191+
/// </summary>
192+
/// <param name="maxLevel">Max level to get</param>
193+
/// <returns>List of Kanjis</returns>
183194
public List<Kanji> Kanji(int maxLevel = 0)
184195
{
185196
if (maxLevel == 0)
@@ -190,6 +201,11 @@ public List<Kanji> Kanji(int maxLevel = 0)
190201
return Kanji(string.Join(",", Enumerable.Range(1, maxLevel)));
191202
}
192203

204+
/// <summary>
205+
/// Get all unlocked Kanjis from the given range of levels, Each level is comma separated, example 2,3,4. To get a single level you can just enter the level such as 5
206+
/// </summary>
207+
/// <param name="maxLevel">Max level to get</param>
208+
/// <returns>List of Kanji</returns>
193209
public List<Kanji> Kanji(string levels)
194210
{
195211
JObject responce = Request("kanji", levels);
@@ -200,6 +216,11 @@ public List<Kanji> Kanji(string levels)
200216
return JsonConvert.DeserializeObject<List<Kanji>>(requestData.ToString());
201217
}
202218

219+
/// <summary>
220+
/// Get all unlocked Vocabulary up to given level, if no level given will get all unlocked.
221+
/// </summary>
222+
/// <param name="maxLevel">Max level to get</param>
223+
/// <returns>List of Vocabulary</returns>
203224
public List<Vocabulary> Vocabulary(int maxLevel = 0)
204225
{
205226
if (maxLevel == 0)
@@ -210,7 +231,11 @@ public List<Vocabulary> Vocabulary(int maxLevel = 0)
210231
return Vocabulary(string.Join(",", Enumerable.Range(1, maxLevel)));
211232
}
212233

213-
234+
/// <summary>
235+
/// Get all unlocked Vocabulary from the given range of levels, Each level is comma separated, example 2,3,4. To get a single level you can just enter the level such as 5
236+
/// </summary>
237+
/// <param name="maxLevel">Max level to get</param>
238+
/// <returns>List of Vocabulary</returns>
214239
public List<Vocabulary> Vocabulary(string levels)
215240
{
216241
JObject responce = Request("vocabulary", levels);
@@ -221,5 +246,34 @@ public List<Vocabulary> Vocabulary(string levels)
221246
return JsonConvert.DeserializeObject<List<Vocabulary>>(requestData.ToString());
222247
}
223248

249+
private string BuildUrl(string resource = null, string optionalArgument = null)
250+
{
251+
string url = "http://www.wanikani.com/api/" + ApiVersion + "/user/" + APIKey + "/";
252+
253+
if (resource != null)
254+
url += resource + "/";
255+
256+
if (optionalArgument != null)
257+
url += optionalArgument + "/";
258+
259+
return url;
260+
}
261+
262+
private JObject Request(string resource = null, string optionalArgument = null)
263+
{
264+
WebClient httpClient = new WebClient();
265+
string responce = httpClient.DownloadString(BuildUrl(resource, optionalArgument));
266+
267+
return JObject.Parse(responce);
268+
}
269+
270+
private void UpdateUserInformation(JObject responce)
271+
{
272+
var requestData = responce["user_information"];
273+
_cachedUserInformation = JsonConvert.DeserializeObject<UserInformation>(requestData.ToString());
274+
275+
_cachedTimeUserInformation = DateTime.Now.AddMinutes(CacheInMinutes);
276+
}
277+
224278
}
225279
}

0 commit comments

Comments
 (0)