diff --git a/src/NetrunnerDb.Net/Repository.cs b/src/NetrunnerDb.Net/Repository.cs index 8498ecb..04ca6cb 100644 --- a/src/NetrunnerDb.Net/Repository.cs +++ b/src/NetrunnerDb.Net/Repository.cs @@ -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 GetRequest(string param) + /// + /// Make a get request. Parameter may be optional, look at netrunner db docs for info + /// + /// + /// The URL parameter, not needed for classes that are plural like Sets + /// + /// + /// + public IList GetRequest(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>(response.Content); } + /// + /// /api/sets/ returns data about all the sets in the database. + /// + /// + public IList GetSets() + { + return GetRequest(); + } + /// + /// /api/set/{code} returns card data about the cards in the set identified by code (core for Core Set, etc). + /// + /// + /// + public IList GetSet(string code) + { + return GetRequest(code); + } + /// + /// /api/cards/ returns data about all the cards in the database. + /// + /// + public IList GetCards() + { + return GetRequest(); + } } } diff --git a/src/NetrunnerDb.Net/Responses/Cards.cs b/src/NetrunnerDb.Net/Responses/Cards.cs index 573e390..08d1d28 100644 --- a/src/NetrunnerDb.Net/Responses/Cards.cs +++ b/src/NetrunnerDb.Net/Responses/Cards.cs @@ -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/"; } } diff --git a/src/NetrunnerDb.Net/Responses/Set.cs b/src/NetrunnerDb.Net/Responses/Set.cs index 559d740..d295b69 100644 --- a/src/NetrunnerDb.Net/Responses/Set.cs +++ b/src/NetrunnerDb.Net/Responses/Set.cs @@ -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); } } diff --git a/src/NetrunnerDb.Net/Responses/Sets.cs b/src/NetrunnerDb.Net/Responses/Sets.cs index 1279928..9e02122 100644 --- a/src/NetrunnerDb.Net/Responses/Sets.cs +++ b/src/NetrunnerDb.Net/Responses/Sets.cs @@ -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/"; } }