public DefaultRequestExecutor(
            IHttpClient httpClient,
            IClientApiKey apiKey,
            AuthenticationScheme authenticationScheme,
            ILogger logger,
            IBackoffStrategy defaultBackoffStrategy,
            IBackoffStrategy throttlingBackoffStrategy)
        {
            if (!apiKey.IsValid())
            {
                throw new ApplicationException("API Key is invalid.");
            }

            this.httpClient = httpClient;
            this.syncHttpClient = httpClient as ISynchronousHttpClient;
            this.asyncHttpClient = httpClient as IAsynchronousHttpClient;

            this.apiKey = apiKey;
            this.authenticationScheme = authenticationScheme;

            IRequestAuthenticatorFactory requestAuthenticatorFactory = new DefaultRequestAuthenticatorFactory();
            this.requestAuthenticator = requestAuthenticatorFactory.Create(authenticationScheme);

            this.logger = logger;
            this.defaultBackoffStrategy = defaultBackoffStrategy;
            this.throttlingBackoffStrategy = throttlingBackoffStrategy;
        }
        public DefaultRequestExecutor(
            IHttpClient httpClient,
            IClientApiKey apiKey,
            AuthenticationScheme authenticationScheme,
            ILogger logger,
            IBackoffStrategy defaultBackoffStrategy,
            IBackoffStrategy throttlingBackoffStrategy)
        {
            if (!apiKey.IsValid())
            {
                throw new ApplicationException("API Key is invalid.");
            }

            this.httpClient      = httpClient;
            this.syncHttpClient  = httpClient as ISynchronousHttpClient;
            this.asyncHttpClient = httpClient as IAsynchronousHttpClient;

            this.apiKey = apiKey;
            this.authenticationScheme = authenticationScheme;

            IRequestAuthenticatorFactory requestAuthenticatorFactory = new DefaultRequestAuthenticatorFactory();

            this.requestAuthenticator = requestAuthenticatorFactory.Create(authenticationScheme);

            this.logger = logger;
            this.defaultBackoffStrategy    = defaultBackoffStrategy;
            this.throttlingBackoffStrategy = throttlingBackoffStrategy;
        }
예제 #3
0
        IClientBuilder IClientBuilder.SetApiKey(IClientApiKey apiKey)
        {
            if (apiKey == null)
            {
                throw new ArgumentNullException("API Key cannot be null.");
            }

            if (!apiKey.IsValid())
            {
                throw new ArgumentException("API Key is not valid.");
            }

            this.apiKey = apiKey;
            return(this);
        }
        public DefaultClient(
            IClientApiKey apiKey,
            string baseUrl,
            AuthenticationScheme authenticationScheme,
            int connectionTimeout,
            IWebProxy proxy,
            IHttpClient httpClient,
            IJsonSerializer serializer,
            ICacheProvider cacheProvider,
            IUserAgentBuilder userAgentBuilder,
            ILogger logger,
            TimeSpan identityMapExpiration)
        {
            if (apiKey == null || !apiKey.IsValid())
            {
                throw new ArgumentException("API Key is not valid.");
            }

            if (string.IsNullOrEmpty(baseUrl))
            {
                throw new ArgumentNullException("Base URL cannot be empty.");
            }

            if (connectionTimeout < 0)
            {
                throw new ArgumentException("Timeout cannot be negative.");
            }

            this.logger = logger;
            this.apiKey = apiKey;
            this.baseUrl = baseUrl;
            this.connectionTimeout = connectionTimeout;
            this.proxy = proxy;
            this.cacheProvider = cacheProvider;
            this.authenticationScheme = authenticationScheme;
            this.serializer = serializer;
            this.httpClient = httpClient;

            var requestExecutor = new DefaultRequestExecutor(httpClient, apiKey, authenticationScheme, this.logger);

            this.dataStore = new DefaultDataStore(this as IClient, requestExecutor, baseUrl, this.serializer, this.logger, userAgentBuilder, cacheProvider, identityMapExpiration);
            this.dataStoreAsync = this.dataStore as IInternalAsyncDataStore;
            this.dataStoreSync = this.dataStore as IInternalSyncDataStore;
        }
        public DefaultClient(
            IClientApiKey apiKey,
            string baseUrl,
            AuthenticationScheme authenticationScheme,
            int connectionTimeout,
            IWebProxy proxy,
            IHttpClient httpClient,
            IJsonSerializer serializer,
            ICacheProvider cacheProvider,
            IUserAgentBuilder userAgentBuilder,
            ILogger logger,
            TimeSpan identityMapExpiration)
        {
            if (apiKey == null || !apiKey.IsValid())
            {
                throw new ArgumentException("API Key is not valid.");
            }

            if (string.IsNullOrEmpty(baseUrl))
            {
                throw new ArgumentNullException("Base URL cannot be empty.");
            }

            if (connectionTimeout < 0)
            {
                throw new ArgumentException("Timeout cannot be negative.");
            }

            this.logger               = logger;
            this.apiKey               = apiKey;
            this.baseUrl              = baseUrl;
            this.connectionTimeout    = connectionTimeout;
            this.proxy                = proxy;
            this.cacheProvider        = cacheProvider;
            this.authenticationScheme = authenticationScheme;
            this.serializer           = serializer;
            this.httpClient           = httpClient;

            var requestExecutor = new DefaultRequestExecutor(httpClient, apiKey, authenticationScheme, this.logger);

            this.dataStore      = new DefaultDataStore(this as IClient, requestExecutor, baseUrl, this.serializer, this.logger, userAgentBuilder, cacheProvider, identityMapExpiration);
            this.dataStoreAsync = this.dataStore as IInternalAsyncDataStore;
            this.dataStoreSync  = this.dataStore as IInternalSyncDataStore;
        }