Esempio n. 1
0
        public async Task <dynamic> PostAsync(string path, IApiCredentials credentials, Dictionary <HttpStatusCode, Type> resultTypeMappings, CancellationToken cancellationToken, object request = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }
            if (resultTypeMappings == null)
            {
                throw new ArgumentNullException(nameof(resultTypeMappings));
            }

            using (var httpResponse = await SendRequestAsync(HttpMethod.Post, path, credentials, request, cancellationToken))
            {
                if (!resultTypeMappings.TryGetValue(httpResponse.StatusCode, out Type resultType))
                {
                    throw new KeyNotFoundException($"The status code {httpResponse.StatusCode} is not mapped to a result type");
                }

                return(await DeserializeJsonAsync(httpResponse, resultType));
            }
        }
Esempio n. 2
0
 public CexIoRestClient(IApiCredentials credentials, CurrencyMapping currencyMapping, ILogFactory logFactory)
 {
     _credentials     = credentials;
     _currencyMapping = currencyMapping;
     _client          = new HttpClient(new LoggingHandler(logFactory.CreateLog(this), new HttpClientHandler()))
     {
         BaseAddress = new Uri("https://cex.io/api/")
     };
 }
 public ApiClient(
     IApiCredentials credentials,
     HttpClientFactory httpClientFactory,
     string internalApiKey = "n/a")
 {
     _credentials       = credentials;
     _httpClientFactory = httpClientFactory;
     InternalApiKey     = internalApiKey;
 }
Esempio n. 4
0
        public PaymentsClient(IApiClient apiClient, CheckoutConfiguration configuration)
        {
            _apiClient = apiClient ?? throw new ArgumentNullException(nameof(apiClient));
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _credentials = new SecretKeyCredentials(configuration);
        }
Esempio n. 5
0
        public HttpClient GetClientV1(IApiCredentials credentials, string internalApiKey)
        {
            lock (_sync)
            {
                if (!_clientsV1.ContainsKey(internalApiKey))
                {
                    _clientsV1[internalApiKey] = CreateClient(credentials, "https://www.bitstamp.net/api/");
                }

                return(_clientsV1[internalApiKey]);
            }
        }
Esempio n. 6
0
        public async Task <TResult> PostAsync <TResult>(string path, IApiCredentials credentials, CancellationToken cancellationToken, object request = null)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            var httpResponse = await SendRequestAsync(HttpMethod.Post, path, credentials, request, cancellationToken);

            return(await DeserializeJsonAsync <TResult>(httpResponse));
        }
Esempio n. 7
0
        private HttpClient CreateClient(IApiCredentials credentials, string baseUrl)
        {
            HttpMessageHandler handler = new LoggingHandler(_log, new HttpClientHandler());

            if (credentials != null)
            {
                handler = new AuthenticationHandler(
                    credentials.UserId,
                    credentials.Key,
                    credentials.Secret,
                    handler);
            }

            return(new HttpClient(handler)
            {
                BaseAddress = new Uri(baseUrl)
            });
        }
 public Task <TResult> PostAsync <TResult>(string path, IApiCredentials credentials, CancellationToken cancellationToken, object request = null, string idempotencyKey = null)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 public CancelOrderRequest(string id, IApiCredentials credentials, long nonce) : base(credentials, nonce)
 {
     Id = id;
 }
Esempio n. 10
0
 public PlaceOrderRequest(IApiCredentials creds, long nonce) : base(creds, nonce)
 {
 }
Esempio n. 11
0
        private async Task <HttpResponseMessage> SendRequestAsync(HttpMethod httpMethod, string path, IApiCredentials credentials, object request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException(nameof(path));
            }

            var httpRequest = new HttpRequestMessage(httpMethod, GetRequestUri(path));

            httpRequest.Headers.UserAgent.ParseAdd("checkout-sdk-net/" + ReflectionUtils.GetAssemblyVersion <ApiClient>());

            await credentials.AuthorizeAsync(httpRequest);

            if (request != null)
            {
                httpRequest.Content = new StringContent(_serializer.Serialize(request), Encoding.UTF8, "application/json");
            }

            Logger.Info("{HttpMethod} {Uri}", httpMethod, httpRequest.RequestUri.AbsoluteUri);

            var httpResponse = await _httpClient.SendAsync(httpRequest, cancellationToken);

            await ValidateResponseAsync(httpResponse);

            return(httpResponse);
        }
 public EmptyRequest(IApiCredentials credentials, long nonce)
 {
     Key       = credentials.ApiKey;
     Nonce     = nonce.ToString();
     Signature = CreateSignature(credentials.UserId, Nonce, credentials.ApiKey, credentials.ApiSecret);
 }
Esempio n. 13
0
 public PerfectWardClient(IApiCredentials credentials, NetworkCredential proxyCredentials)
 {
     _credentials = credentials;
     _httpClient  = new HttpClient(ProxyCredentials.CreateHandler(proxyCredentials));
 }