private static async Task <ObserverResponse> CreateObserverResponse(HttpResponseMessage response, string apiName = "") { var observerResponse = new ObserverResponse(); if (response == null) { observerResponse.StatusCode = HttpStatusCode.InternalServerError; observerResponse.Content = "Unable to fetch data from Observer API : " + apiName; } observerResponse.StatusCode = response.StatusCode; if (response.IsSuccessStatusCode) { observerResponse.Content = await response.Content.ReadAsAsync <dynamic>(); } else if (response.StatusCode == HttpStatusCode.NotFound) { observerResponse.Content = (string)"Resource Not Found. API : " + apiName; } else { observerResponse.Content = (string)"Unable to fetch data from Observer API : " + apiName; } return(observerResponse); }
private static async Task <ObserverResponse> GetSiteInternal(string endpoint, string hashInput) { var request = new HttpRequestMessage() { RequestUri = new Uri(endpoint), Method = HttpMethod.Get }; request.Headers.Add("client-hash", SignData(hashInput, SimpleHashAuthenticationHashKey)); var response = await _httpClient.SendAsync(request); ObserverResponse res = await CreateObserverResponse(response, "GetAdminSite"); return(res); }
/// <summary> /// Get Hostnames for a site /// </summary> /// <param name="siteName">SiteName</param> /// <returns>Hostnames</returns> internal static async Task <ObserverResponse> GetHostnames(string siteName) { var request = new HttpRequestMessage() { RequestUri = new Uri(SupportObserverApiEndpoint + "sites/" + siteName + "/hostnames?api-version=2.0"), Method = HttpMethod.Get }; var serializedParameters = JsonConvert.SerializeObject(new Dictionary <string, string>() { { "site", siteName } }); request.Headers.Add("client-hash", SignData(serializedParameters, SimpleHashAuthenticationHashKey)); var response = await _httpClient.SendAsync(request); ObserverResponse res = await CreateObserverResponse(response, "GetHostnames(2.0)"); return(res); }