public List <Book> GetBooksFromService(List <string> isbns) { List <Book> booksFromService = new ListStack <Book>(); int counOfCalls = (int)Math.Ceiling((double)isbns.Count() / groupSize); for (int i = 0; i < counOfCalls; i++) { var group = isbns.Skip(i * groupSize).Take(groupSize).ToList(); string isbnsParameter = GetIsbnString(group); const string baseUri = "http://api.saxo.com/v1/products/products.json?key=08964e27966e4ca99eb0029ac4c4c217&isbn="; string requestUri = string.Format("{0}{1}", baseUri, isbnsParameter); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; dynamic bookDataJs = JObject.Parse(webClient.DownloadString(requestUri)); booksFromService.AddRange(BookList(bookDataJs)); } return(booksFromService); }
public object GetWeather(double dLatitude = 47.4886, double dLongitude = -117.5786) { Debug.WriteLine(GetType().FullName + "." + MethodBase.GetCurrentMethod().Name); //NOTE: //The first thousand API calls you make every day are free, period. //Every API call after that costs $0.0001 each. //Credit us with a “Powered by Forecast” badge that links to http://forecast.io/ wherever you display data from the API. //https://api.forecast.io/forecast/ec8fab02bc1bf58c04e74c58bc2c3525/47.4886,-117.5786 //https://github.com/f0xy/forecast.io-csharp // API Key, Lat, Long, Unit var request = new ForecastIORequest("ec8fab02bc1bf58c04e74c58bc2c3525", (float)dLatitude, (float)dLongitude, Unit.us); var response = request.Get(); var strSummary = response.daily.summary; var currently = response.currently; List<DailyForecast> tempList = new ListStack<DailyForecast>(); tempList.AddRange(response.daily.data); if (!tempList.Any()) return new HttpResponseException(HttpStatusCode.BadRequest); //Ember Data expects a JSon array and an id in all returns const int id = 1; var currentWeather = new { currently.summary, currently.icon, currently.temperature }; var dailyWeather = tempList.AsQueryable() .Select( x => new { x.summary, x.icon, x.temperatureMin, x.temperatureMinTime, x.temperatureMax, x.temperatureMaxTime }) .ToList(); var data = new { id, strSummary, currentWeather, dailyWeather }; var weatherItems = new List<object>() { data }.AsEnumerable(); return new { weatherItems }; }