private SwapiEntityResults <T> GetAllPaginated <T>(string entityName, string pageNumber = "1") where T : SwapiEntity { Dictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("page", pageNumber); SwapiEntityResults <T> result = GetMultiple <T>(entityName, parameters); result.NextPageNo = String.IsNullOrEmpty(result.Next) ? null : GetQueryParameters(result.Next)["page"]; result.PreviousPageNo = String.IsNullOrEmpty(result.Previous) ? null : GetQueryParameters(result.Previous)["page"]; return(result); }
private SwapiEntityResults <T> GetMultiple <T>(string endpoint, Dictionary <string, string> parameters) where T : SwapiEntity { string serializedParameters = ""; if (parameters != null) { serializedParameters = "?" + SerializeDictionary(parameters); } string json = Request(string.Format("{0}{1}{2}", apiUrl, endpoint, serializedParameters), HttpMethod.GET); SwapiEntityResults <T> swapiResponse = JsonConvert.DeserializeObject <SwapiEntityResults <T> >(json); return(swapiResponse); }
public SwapiEntityResults <SwapiPeople> GetAllPeople(string pageNumber = "1") { SwapiEntityResults <SwapiPeople> result = GetAllPaginated <SwapiPeople>("/people/", pageNumber); return(result); }