add comments
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using Newtonsoft.Json;
|
||||
using RestSharp;
|
||||
|
||||
@@ -10,16 +8,50 @@ namespace NetrunnerDb.Net
|
||||
{
|
||||
public class Repository
|
||||
{
|
||||
public IList<TResult> GetRequest<TResult>(string param)
|
||||
/// <summary>
|
||||
/// Make a get request. Parameter may be optional, look at netrunner db docs for info
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="parameter">The URL parameter, not needed for classes that are plural like Sets</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
public IList<TResult> GetRequest<TResult>(string parameter = "")
|
||||
where TResult : class, IRequest, new()
|
||||
{
|
||||
var s = new TResult();
|
||||
var request = new RestRequest(){
|
||||
Resource = s.EndPoint(param)};
|
||||
Resource = s.EndPoint(parameter)
|
||||
};
|
||||
var client = new RestClient("http://netrunnerdb.com");
|
||||
var response = client.Execute(request);
|
||||
|
||||
if (response.StatusCode != HttpStatusCode.OK) return null;
|
||||
return JsonConvert.DeserializeObject<IList<TResult>>(response.Content);
|
||||
}
|
||||
/// <summary>
|
||||
/// /api/sets/ returns data about all the sets in the database.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IList<Sets> GetSets()
|
||||
{
|
||||
return GetRequest<Sets>();
|
||||
}
|
||||
/// <summary>
|
||||
/// /api/set/{code} returns card data about the cards in the set identified by code (core for Core Set, etc).
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public IList<Sets> GetSet(string code)
|
||||
{
|
||||
return GetRequest<Sets>(code);
|
||||
}
|
||||
/// <summary>
|
||||
/// /api/cards/ returns data about all the cards in the database.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IList<Cards> GetCards()
|
||||
{
|
||||
return GetRequest<Cards>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,6 +117,11 @@ namespace NetrunnerDb.Net
|
||||
|
||||
public string EndPoint(string parameter = "")
|
||||
{
|
||||
//this endpoint should not be passed a parameter
|
||||
if (!string.IsNullOrWhiteSpace(parameter))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("parameter", "Cards does not have any parameters for the endpoint");
|
||||
}
|
||||
return "/api/cards/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,11 @@ namespace NetrunnerDb.Net
|
||||
|
||||
public string EndPoint(string parameter = "")
|
||||
{
|
||||
//we should be passed an actual param
|
||||
if (string.IsNullOrWhiteSpace(parameter))
|
||||
{
|
||||
throw new ArgumentNullException("parameter");
|
||||
}
|
||||
return string.Format("/api/set/{0}", parameter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,10 @@ namespace NetrunnerDb.Net
|
||||
|
||||
public string EndPoint(string parameter = "")
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(parameter))
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("parameter", "Sets does not have a URL parameter");
|
||||
}
|
||||
return "/api/sets/";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user