public async Task <AmadeusToken> RevokeToken() { Dictionary <string, string> body = Params.With("grant_type", _config.GetConnectionString("AmadeusGrantType")).And("client_id", _config.GetConnectionString("AmadeusID")).And("client_secret", _config.GetConnectionString("AmadeusSecret")); var response = await _httpClient.PostAsync(new Uri(_config.GetConnectionString("AmadeusTokenAPIUrl")), new FormUrlEncodedContent(body)); var responseBodyString = await response.Content.ReadAsStringAsync(); _amadeusToken = JsonConvert.DeserializeObject <AmadeusToken>(responseBodyString); int expiresIn = _amadeusToken.expires_in; this.expiresAt = GetCurrentMilli() + expiresIn * 1000L; return(_amadeusToken); }
public async Task <Result <Hotels> > GetHotelsCall(Query request) { Hotels hotelsList = new Hotels(); try { AmadeusToken token = await _tokenService.GetToken(); _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.access_token); using (var response = await _httpClient.GetAsync(_config.GetConnectionString("AmadeusAPIUrl") + request.param.ToQueryString())) { string apiResponse = await response.Content.ReadAsStringAsync(); hotelsList = JsonConvert.DeserializeObject <Hotels>(apiResponse); } } catch (Exception e) { _logger.LogError(e, "Error getting data from Amadeus API", e.Message); throw e; } return(Result <Hotels> .Success(hotelsList)); }