@@ -25,33 +25,22 @@ public class WaniKaniClient
25
25
private SrsDistribution _cachedSrsDistribution ;
26
26
private DateTime _cachedTimeSrsDistribution ;
27
27
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>
28
33
public WaniKaniClient ( string apiKey , int cacheInMinutes = 15 )
29
34
{
30
35
APIKey = apiKey ;
31
36
CacheInMinutes = cacheInMinutes ;
32
37
}
33
38
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>
55
44
public UserInformation UserInformation ( bool noCache = false )
56
45
{
57
46
if ( ! noCache && _cachedUserInformation != null && _cachedTimeUserInformation > DateTime . Now )
@@ -63,14 +52,11 @@ public UserInformation UserInformation(bool noCache = false)
63
52
return _cachedUserInformation ;
64
53
}
65
54
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>
74
60
public StudyQueue StudyQueue ( bool noCache = false )
75
61
{
76
62
if ( ! noCache && _cachedStudyQueue != null && _cachedTimeStudyQueue > DateTime . Now )
@@ -87,6 +73,11 @@ public StudyQueue StudyQueue(bool noCache = false)
87
73
return _cachedStudyQueue ;
88
74
}
89
75
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>
90
81
public LevelProgression LevelProgression ( bool noCache = false )
91
82
{
92
83
if ( ! noCache && _cachedLevelProgression != null && _cachedTimeLevelProgression > DateTime . Now )
@@ -103,14 +94,19 @@ public LevelProgression LevelProgression(bool noCache = false)
103
94
return _cachedLevelProgression ;
104
95
}
105
96
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>
106
102
public SrsDistribution SrsDistribution ( bool noCache = false )
107
103
{
108
104
if ( ! noCache && _cachedSrsDistribution != null && _cachedTimeSrsDistribution > DateTime . Now )
109
105
return _cachedSrsDistribution ;
110
106
111
107
JObject responce = Request ( "srs-distribution" ) ;
112
108
UpdateUserInformation ( responce ) ;
113
- @
109
+
114
110
var requestData = responce [ "requested_information" ] ;
115
111
116
112
_cachedSrsDistribution = JsonConvert . DeserializeObject < SrsDistribution > ( requestData . ToString ( ) ) ;
@@ -139,10 +135,11 @@ public List<BaseCharacter> RecentUnlocks(int take = 10)
139
135
140
136
141
137
/// <summary>
138
+ /// Gets all items that is in the users Critical List ( Default 75% or lower)
142
139
/// This request is not cached.
143
140
/// </summary>
144
- /// <param name="maxPercentage"></param>
145
- /// <returns></returns>
141
+ /// <param name="maxPercentage">The max % failed to retreeive. </param>
142
+ /// <returns>List<BaseCharacter> </returns>
146
143
public List < BaseCharacter > CriticalItems ( int maxPercentage = 75 )
147
144
{
148
145
if ( maxPercentage > 100 )
@@ -156,6 +153,11 @@ public List<BaseCharacter> CriticalItems(int maxPercentage = 75)
156
153
return JsonConvert . DeserializeObject < List < BaseCharacter > > ( requestData . ToString ( ) , new CharacterTypeCreationConverter ( ) ) ;
157
154
}
158
155
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>
159
161
public List < Radical > Radicals ( int maxLevel = 0 )
160
162
{
161
163
if ( maxLevel == 0 )
@@ -169,6 +171,11 @@ public List<Radical> Radicals(int maxLevel = 0)
169
171
return Radicals ( string . Join ( "," , Enumerable . Range ( 1 , maxLevel ) ) ) ;
170
172
}
171
173
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>
172
179
public List < Radical > Radicals ( string levels )
173
180
{
174
181
JObject responce = Request ( "radicals" , levels ) ;
@@ -179,7 +186,11 @@ public List<Radical> Radicals(string levels)
179
186
return JsonConvert . DeserializeObject < List < Radical > > ( requestData . ToString ( ) ) ;
180
187
}
181
188
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>
183
194
public List < Kanji > Kanji ( int maxLevel = 0 )
184
195
{
185
196
if ( maxLevel == 0 )
@@ -190,6 +201,11 @@ public List<Kanji> Kanji(int maxLevel = 0)
190
201
return Kanji ( string . Join ( "," , Enumerable . Range ( 1 , maxLevel ) ) ) ;
191
202
}
192
203
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>
193
209
public List < Kanji > Kanji ( string levels )
194
210
{
195
211
JObject responce = Request ( "kanji" , levels ) ;
@@ -200,6 +216,11 @@ public List<Kanji> Kanji(string levels)
200
216
return JsonConvert . DeserializeObject < List < Kanji > > ( requestData . ToString ( ) ) ;
201
217
}
202
218
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>
203
224
public List < Vocabulary > Vocabulary ( int maxLevel = 0 )
204
225
{
205
226
if ( maxLevel == 0 )
@@ -210,7 +231,11 @@ public List<Vocabulary> Vocabulary(int maxLevel = 0)
210
231
return Vocabulary ( string . Join ( "," , Enumerable . Range ( 1 , maxLevel ) ) ) ;
211
232
}
212
233
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>
214
239
public List < Vocabulary > Vocabulary ( string levels )
215
240
{
216
241
JObject responce = Request ( "vocabulary" , levels ) ;
@@ -221,5 +246,34 @@ public List<Vocabulary> Vocabulary(string levels)
221
246
return JsonConvert . DeserializeObject < List < Vocabulary > > ( requestData . ToString ( ) ) ;
222
247
}
223
248
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
+
224
278
}
225
279
}
0 commit comments