Ejemplo n.º 1
0
 private static void AddCommonDependencies(IServiceCollection services, CircleApiConfiguration apiConfiguration)
 {
     services.AddSingleton <ClientConfigurator>();
     services.AddSingleton <ICircleCredentialsProvider, ApiKeyCredentialsProvider>();
     services.AddSingleton <IDateTimeProvider, DateTimeProvider>();
     AddClients(services, apiConfiguration);
 }
Ejemplo n.º 2
0
        public static IServiceCollection AddCircleClient(
            this IServiceCollection services, CircleApiConfiguration apiConfiguration)
        {
            var options = Options.Create(apiConfiguration);

            services.AddSingleton(options);

            AddCommonDependencies(services, apiConfiguration);

            return(services);
        }
Ejemplo n.º 3
0
        public CircleApiFixture()
        {
            var secrets       = new Secrets();
            var configuration = new CircleApiConfiguration
            {
                ApiKey  = secrets.CircleApiKey,
                BaseUrl = "https://api-sandbox.circle.com"
            };

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton(configuration);
            serviceCollection.AddCircleClient(configuration);

            ServiceProvider = serviceCollection.BuildServiceProvider();
        }
Ejemplo n.º 4
0
        private static void AddClients(this IServiceCollection services, CircleApiConfiguration configuration)
        {
            var delay = Backoff.DecorrelatedJitterBackoffV2(
                medianFirstRetryDelay: TimeSpan.FromMilliseconds(configuration.InitialRetryDelayInMilliseconds ?? 100),
                retryCount: configuration.MaxRetryCount ?? 3, fastFirst: true);

            services.AddHttpClient <IAccountsClient, AccountsClient>("Trakx.Circle.ApiClient.AccountsClient")
            .AddPolicyHandler((s, request) =>
                              Policy <HttpResponseMessage>
                              .Handle <ApiException>()
                              .Or <HttpRequestException>()
                              .OrTransientHttpStatusCode()
                              .WaitAndRetryAsync(delay,
                                                 onRetry: (result, timeSpan, retryCount, context) =>
            {
                var logger = Log.Logger.ForContext <AccountsClient>();
                LogFailure(logger, result, timeSpan, retryCount, context);
            })
                              .WithPolicyKey("Trakx.Circle.ApiClient.AccountsClient"));
        }
Ejemplo n.º 5
0
 public ClientConfigurator(IOptions <CircleApiConfiguration> configuration, ICircleCredentialsProvider credentialsProvider)
 {
     CredentialsProvider = credentialsProvider;
     ApiConfiguration    = configuration.Value;
 }
Ejemplo n.º 6
0
 public ApiKeyCredentialsProvider(IOptions <CircleApiConfiguration> configuration)
 {
     _configuration = configuration.Value;
     _tokenSource   = new CancellationTokenSource();
 }