private ApiTokenResponse RefreshApiToken(ApiKeyParameter apiKeyParameter, ApiTokenCache tokenCache) { using (var client = new HttpClient()) { client.BaseAddress = _baseAddress; var request = client.SendAsync(new ApiKeyRequest(apiKeyParameter)).Result; if (request.StatusCode == HttpStatusCode.InternalServerError) { throw new ApplicationException("Request for API token failed: " + request.Content.ReadAsStringAsync().Result); } var token = request.Content.ReadAsAsync <ApiTokenResponse>().Result; tokenCache.AddToken(apiKeyParameter.MandatorId, token); return(token); } }
public ApiKeyRequest(ApiKeyParameter apiKeyParameter) : base(HttpMethod.Post, "Auth") { Content = new ObjectContent(typeof(ApiKeyParameter), apiKeyParameter, new JsonMediaTypeFormatter()); }