/// <summary> Specify the endpoint (e.g. EddiBgsService.Endpoint.factions) and a list of queries as KeyValuePairs </summary> public List <object> GetData(IBgsRestClient restClient, string endpoint, List <KeyValuePair <string, object> > queries) { if (queries == null) { return(null); } var docs = new List <object>(); var currentPage = 1; RestRequest request = new RestRequest(endpoint, Method.GET); foreach (KeyValuePair <string, object> query in queries) { request.AddParameter(query.Key, query.Value); } // Make our initial request PageResponse response = PageRequest(restClient, request, currentPage); if (response != null) { docs.AddRange(response.docs); var totalPages = response.pages; // Make additional requests as needed while (currentPage < totalPages) { PageResponse pageResponse = PageRequest(restClient, request, ++currentPage); if (pageResponse != null) { docs.AddRange(pageResponse.docs); } } return(docs); } return(null); }
private PageResponse PageRequest(IBgsRestClient restClient, RestRequest request, int page) { request.AddOrUpdateParameter("page", page); RestResponse <RestRequest> clientResponse = (RestResponse <RestRequest>)restClient.Execute <RestRequest>(request); if (clientResponse.IsSuccessful) { string json = clientResponse.Content; var pageResponse = JsonConvert.DeserializeObject <PageResponse>(json); if (pageResponse != null && pageResponse.docs.Any()) { return(pageResponse); } } else { Logging.Debug("EliteBGS data error: Error obtaining data from " + request.Resource + ". Query: " + request.Parameters.ToArray()); } return(null); // No results }
public BgsService(IBgsRestClient restClient = null) { this.restClient = restClient ?? new BgsRestClient(baseUrl); }
public BgsService(IBgsRestClient bgsRestClient = null, IBgsRestClient eddbRestClient = null) { this.bgsRestClient = bgsRestClient ?? new BgsRestClient(bgsBaseUrl); this.eddbRestClient = eddbRestClient ?? new BgsRestClient(eddbBaseUrl); }