public async Task <WeatherMainResponse> GetPastWeatherAsync(int zipCode, DateTime dateTime) { // our current subscription plan does not support historical weather data. Please upgrade your account to use this feature."}} // won't work // http://api.weatherstack.com/historical?access_key=&query=New%20York&historical_date=2015-01-21&hourly=1 var response = await httpClient.GetStringAsync($"historical?access_key={apiKey}&type=zipcode&units=f&query={zipCode}&historical_date={dateTime}&hourly=1"); return(WeatherMainResponse.FromJson(response)); }
// http://api.weatherstack.com/historical?access_key={key}&query=New%20York&historical_date=2015-01-21&hourly=1 // your current subscription plan does not support historical weather data. Please upgrade your account to use this feature."}} public async Task <WeatherMainResponse> GetPastWeather_NotTestableAsync(int zipCode, DateTime dateTime) { // why can't we write tests for this? using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri($"https://api.apixu.com/v1/"); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = await httpClient.GetStringAsync($"past.json?key={apiKey}&q={zipCode}&date={dateTime}"); return(WeatherMainResponse.FromJson(response)); } }
public async Task <double> GetCurrentTempAsync(int zipCode) { string response; try { response = await httpClient.GetStringAsync($"current?access_key={apiKey}&type=zipcode&units=f&query={zipCode}"); } catch (HttpRequestException) { // for ApixuClientTests_GetTemp_GivenAZipCode_NotFound_ThrowsException discussion // TODO check the body of the exception throw new NotFoundException($"{zipCode} didn't work"); } var weather = WeatherMainResponse.FromJson(response); return(weather.Current.Temperature); }