Example #1
0
        public List <Vehicle> GetVehicles(IGetApiResponse __getResponser)
        {
            int    i    = 1;
            string next = "";

            do
            {
                // Ideally API url's should come from the Web config.
                string url = string.Format("https://swapi.co/api/starships/?page={0}", i);
                Newtonsoft.Json.Linq.JObject pageNumber = __getResponser.GetApiRespone(url);
                next = pageNumber.SelectToken("next").Value <string>();
                // get JSON result objects into a list
                IList <JToken> results = pageNumber["results"].Children().ToList();

                foreach (JToken result in results)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    Vehicle searchResult = result.ToObject <Vehicle>();
                    Vehicles.getInstance().insertVehicle(searchResult);
                }

                i++;
            } while (next != null);

            return(Vehicles.getInstance().getVehicles());
        }
Example #2
0
 public GetApiResponse(IGetApiResponse getApiResponse)
 {
     __getAPiResponse = getApiResponse;
 }