public virtual async Task <TokenModel> GetAuthenticationToken() { var builder = new UriBuilder($"{Urls.ApiUrl(_settings.SandboxEnabled)}/auth/token"); _httpClient.DefaultRequestHeaders.Clear(); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("TG-Version", "2.0.0"); var js = new { public_key = _settings.PublicKey, secret_key = _settings.SecretKey }; var request = new HttpRequestMessage(HttpMethod.Post, builder.ToString()) { Content = JsonContent(js) }; var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead); if (response.IsSuccessStatusCode) { Token = JsonConvert.DeserializeObject <TokenModel>(await response.Content.ReadAsStringAsync()); return(Token); } throw BuildException(response.StatusCode, builder.ToString(), await response.Content.ReadAsStringAsync()); }
// Ticket Orders public virtual async Task <PagedListModel <TicketOrderModel> > GetTicketOrders() { var url = $"{Urls.ApiUrl(_settings.SandboxEnabled)}/{_settings.ClientId}/ticket-orders"; var request = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Get }; request.Headers.Add("Authorization", GetAuthHeaders()); var response = await _httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <PagedListModel <TicketOrderModel> >(await response.Content.ReadAsStringAsync())); } throw BuildException(response.StatusCode, url, await response.Content.ReadAsStringAsync()); }