public async Task <WeatherData> GetWeatherData(string query) { WeatherData weatherData = null; try { var response = await _client.GetAsync(query); InsightsEvent insightsEvent = new InsightsEvent(); insightsEvent.deviceOS = Device.RuntimePlatform == Device.Android ? "Android" : "iOS"; insightsEvent.runtimePlatform = Device.RuntimePlatform; insightsEvent.ID = "123"; insightsEvent.Notes = "WeatherDataRequest"; if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); weatherData = JsonConvert.DeserializeObject <WeatherData>(content); insightsEvent.eventType = "XamarinHTTPRequest"; insightsEvent.responseCode = Convert.ToString(Convert.ToInt32(response.StatusCode)); insightsEvent.reasonPhrase = response.ReasonPhrase; insightsEvent.Done = true; } else { insightsEvent.eventType = "XamarinHTTPRequestError"; insightsEvent.responseCode = "404"; insightsEvent.reasonPhrase = "City Not Found"; } App.InsightsManager.SaveInsightsEventAsync(insightsEvent); } catch (Exception ex) { Debug.WriteLine("\t\tERROR {0}", ex.Message); } return(weatherData); }
string GenerateRequestUri(string endpoint) { string requestUri = endpoint; requestUri += $"?q={_cityEntry.Text}"; requestUri += "&units=imperial"; // or units=metric requestUri += $"&APPID={Constants.OpenWeatherMapAPIKey}"; InsightsEvent insightsEvent = new InsightsEvent(); insightsEvent.ID = "123"; insightsEvent.eventType = "XamarinEvent"; insightsEvent.Notes = _cityEntry.Text; insightsEvent.deviceOS = Device.RuntimePlatform == Device.Android ? "Android" : "iOS"; insightsEvent.runtimePlatform = Device.RuntimePlatform; insightsEvent.Done = true; App.InsightsManager.SaveInsightsEventAsync(insightsEvent); return(requestUri); }
public async Task SaveInsightsEventAsync(InsightsEvent item) { Uri uri = new Uri(string.Format(Constants.InsightsUrl, string.Empty)); try { string json = JsonConvert.SerializeObject(item); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { Debug.WriteLine(@"\tInsightsEvent successfully saved."); } } catch (Exception ex) { Debug.WriteLine(@"\tERROR {0}", ex.Message); } }
public Task SaveInsightsEventAsync(InsightsEvent item) { return(restService.SaveInsightsEventAsync(item)); }