@@ -226,4 +226,138 @@ public async Task<IEnumerable<PointsBoost>> BoostsAsync(
226226 ) ;
227227 }
228228 }
229+
230+ /// <summary>
231+ /// Get all levels for a points system.
232+ /// </summary>
233+ /// <example><code>
234+ /// await client.Points.LevelsAsync("points-system-key");
235+ /// </code></example>
236+ public async Task < IEnumerable < PointsLevel > > LevelsAsync (
237+ string key ,
238+ RequestOptions ? options = null ,
239+ CancellationToken cancellationToken = default
240+ )
241+ {
242+ var response = await _client
243+ . SendRequestAsync (
244+ new JsonRequest
245+ {
246+ BaseUrl = _client . Options . Environment . Api ,
247+ Method = HttpMethod . Get ,
248+ Path = string . Format (
249+ "points/{0}/levels" ,
250+ ValueConvert . ToPathParameterString ( key )
251+ ) ,
252+ Options = options ,
253+ } ,
254+ cancellationToken
255+ )
256+ . ConfigureAwait ( false ) ;
257+ if ( response . StatusCode is >= 200 and < 400 )
258+ {
259+ var responseBody = await response . Raw . Content . ReadAsStringAsync ( ) ;
260+ try
261+ {
262+ return JsonUtils . Deserialize < IEnumerable < PointsLevel > > ( responseBody ) ! ;
263+ }
264+ catch ( JsonException e )
265+ {
266+ throw new TrophyApiException ( "Failed to deserialize response" , e ) ;
267+ }
268+ }
269+
270+ {
271+ var responseBody = await response . Raw . Content . ReadAsStringAsync ( ) ;
272+ try
273+ {
274+ switch ( response . StatusCode )
275+ {
276+ case 401 :
277+ throw new UnauthorizedError ( JsonUtils . Deserialize < ErrorBody > ( responseBody ) ) ;
278+ case 404 :
279+ throw new NotFoundError ( JsonUtils . Deserialize < ErrorBody > ( responseBody ) ) ;
280+ }
281+ }
282+ catch ( JsonException )
283+ {
284+ // unable to map error response, throwing generic error
285+ }
286+ throw new TrophyApiApiException (
287+ $ "Error with status code { response . StatusCode } ",
288+ response . StatusCode ,
289+ responseBody
290+ ) ;
291+ }
292+ }
293+
294+ /// <summary>
295+ /// Get a breakdown of the number of users at each level in a points system.
296+ /// </summary>
297+ /// <example><code>
298+ /// await client.Points.LevelSummaryAsync("points-system-key");
299+ /// </code></example>
300+ public async Task < IEnumerable < PointsLevelSummaryResponseItem > > LevelSummaryAsync (
301+ string key ,
302+ RequestOptions ? options = null ,
303+ CancellationToken cancellationToken = default
304+ )
305+ {
306+ var response = await _client
307+ . SendRequestAsync (
308+ new JsonRequest
309+ {
310+ BaseUrl = _client . Options . Environment . Api ,
311+ Method = HttpMethod . Get ,
312+ Path = string . Format (
313+ "points/{0}/level-summary" ,
314+ ValueConvert . ToPathParameterString ( key )
315+ ) ,
316+ Options = options ,
317+ } ,
318+ cancellationToken
319+ )
320+ . ConfigureAwait ( false ) ;
321+ if ( response . StatusCode is >= 200 and < 400 )
322+ {
323+ var responseBody = await response . Raw . Content . ReadAsStringAsync ( ) ;
324+ try
325+ {
326+ return JsonUtils . Deserialize < IEnumerable < PointsLevelSummaryResponseItem > > (
327+ responseBody
328+ ) ! ;
329+ }
330+ catch ( JsonException e )
331+ {
332+ throw new TrophyApiException ( "Failed to deserialize response" , e ) ;
333+ }
334+ }
335+
336+ {
337+ var responseBody = await response . Raw . Content . ReadAsStringAsync ( ) ;
338+ try
339+ {
340+ switch ( response . StatusCode )
341+ {
342+ case 401 :
343+ throw new UnauthorizedError ( JsonUtils . Deserialize < ErrorBody > ( responseBody ) ) ;
344+ case 404 :
345+ throw new NotFoundError ( JsonUtils . Deserialize < ErrorBody > ( responseBody ) ) ;
346+ case 422 :
347+ throw new UnprocessableEntityError (
348+ JsonUtils . Deserialize < ErrorBody > ( responseBody )
349+ ) ;
350+ }
351+ }
352+ catch ( JsonException )
353+ {
354+ // unable to map error response, throwing generic error
355+ }
356+ throw new TrophyApiApiException (
357+ $ "Error with status code { response . StatusCode } ",
358+ response . StatusCode ,
359+ responseBody
360+ ) ;
361+ }
362+ }
229363}
0 commit comments