コード例 #1
0
 public MapLinkFactoryApiV0(IMapLinkSignature mapLinkSignature, IRequestJSON requestJSON, IApiConfig apiConfig)
     : base("v0")
 {
     this.mapLinkSignature = mapLinkSignature;
     this.requestJSON = requestJSON;
     this.apiConfig = apiConfig;
 }
コード例 #2
0
 public MapLinkFactoryApiV0()
     : base("v0")
 {
     mapLinkSignature = new MapLinkSignatureV0();
     requestJSON = new RequestJSON();
     apiConfig = new ApiConfig();
 }
コード例 #3
0
 public FileHandlerResolver(
     IServiceProvider serviceProvider,
     IApiConfig config)
 {
     _serviceProvider = serviceProvider;
     _config          = config;
 }
コード例 #4
0
        IAPI Create(ILogin login, IApiConfig config)
        {
            if (config is null)
            {
                throw new Exception("Configuration cannot be null");
            }

            IHttpHandler client      = new HttpHandler();
            IMemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions()
            {
                SizeLimit = 128,                 // Each ApiRequest is one in size
            });

            if (!string.IsNullOrEmpty(config.SpecURL))
            {
                Spec = SpecFromUrl(config.SpecURL);
            }

            IFactory <IApiRequest>   apiRequestFactory   = new ApiRequestFactory();
            IFactory <ICacheControl> cacheControlFactory = new CacheControlFactory();

            ITokenManager    tokenManager    = new TokenManager(client, config, login);
            IResponseManager responseManager = new ResponseManager(client, config, login, cacheControlFactory);
            ICacheManager    cacheManager    = new CacheManager(client, config, login, memoryCache, tokenManager, responseManager);
            IRequestManager  requestManager  = new RequestManager(client, config, login, cacheManager, apiRequestFactory, Spec);
            IEventManager    eventManager    = new EventManager(client, config, login, cacheManager, requestManager);

            IFactory <IApiPath>        pathFacotry        = new ApiPathFactory(requestManager);
            IFactory <IApiEventMethod> eventMethodFactory = new ApiEventMethodFactory(eventManager);
            IFactory <IApiEventPath>   eventPathFactory   = new ApiEventPathFactory(eventMethodFactory);

            return(new API(login, config, pathFacotry, Spec, eventPathFactory));
        }
コード例 #5
0
 public PostService7(HttpClient client, IApiConfig apiConfig, IMapper mapper, IFeatureConfig featureConfig)
 {
     _apiConfig     = apiConfig;
     _mapper        = mapper;
     _featureConfig = featureConfig;
     _client        = client;
 }
コード例 #6
0
 public ApiDataViewResolver(
     IApiConfig apiConfig,
     IServiceProvider serviceProvider)
 {
     _dataViewTypes   = apiConfig.DataViews.ToDictionary(dataView => dataView.Alias, dataView => dataView.DataViewBuilder);
     _serviceProvider = serviceProvider;
 }
コード例 #7
0
ファイル: CacheManager.cs プロジェクト: Alkrun/Eve-OpenAPI
 public CacheManager(IHttpHandler client, IApiConfig config, ILogin login, IMemoryCache memoryCache, ITokenManager tokenManager, IResponseManager responseManager) : base(client, login, config)
 {
     requestQueue         = new RequestQueueAsync <IApiRequest, IApiResponse>(ProcessResponse);
     cache                = memoryCache;
     this.tokenManager    = tokenManager;
     this.responseManager = responseManager;
 }
コード例 #8
0
 public void Initialize()
 {
     var mockMapLinkSignature = new Mock<IMapLinkSignature>();
     mockMapLinkSignature.Setup(t => t.GenerateSignature(It.IsAny<string>(), It.IsAny<string>())).Returns("http://localhost");
     mapLinkSignature = mockMapLinkSignature.Object;
     apiConfig = new ApiConfig();
 }
コード例 #9
0
    public BroadcastsListener(ILogger <BroadcastsListener> logger, IInterfaceConfigProvider <IApiConfig> configProvider,
                              DiscordClient discordClient, IDatabaseProvider <PluginManifest> database, TrustlistClient trustlistUserApiService)
    {
        IApiConfig config = configProvider.InitConfig(PluginManifest.ApiConfigFileName).PopulateApiConfig();

        _logger          = logger;
        _discordClient   = discordClient;
        _trustlistClient = trustlistUserApiService;
        _guildConfig     = database.GetMongoDatabase().GetCollection <GuildConfig>(nameof(GuildConfig));

        _hubConnection = new HubConnectionBuilder()
                         .WithUrl(config.ApiHost + "/hubs/trustlist")
                         .AddMessagePackProtocol()
                         .WithAutomaticReconnect()
                         .Build();

        void LogBroadcast(string name, ulong userid) => logger.LogDebug("Received SignalR Boradcast: {name} {userId}", name, userid);

        _hubConnection.On <ulong, TrustlistEntry>(nameof(ITrustlistHubPush.NotifyNewEntry), async(userId, entry) =>
        {
            LogBroadcast(nameof(ITrustlistHubPush.NotifyNewEntry), userId);
            await BroadcastUpdateAsync(BroadcastUpdateType.NewEntry, userId, entry);
        });

        _hubConnection.On <ulong, TrustlistEntry, byte>(nameof(ITrustlistHubPush.NotifyEscalatedEntry), async(userId, entry, level) =>
        {
            LogBroadcast(nameof(ITrustlistHubPush.NotifyEscalatedEntry), userId);
            await BroadcastUpdateAsync(BroadcastUpdateType.Escalation, userId, entry);
        });

        _hubConnection.On <ulong, TrustlistEntry>(nameof(ITrustlistHubPush.NotifyDeletedEntry), (userId, entry) =>
        {
            LogBroadcast(nameof(ITrustlistHubPush.NotifyDeletedEntry), userId);
        });
    }
コード例 #10
0
 public TodoService(
     IApiConfig config,
     HttpClient httpClient)
 {
     _config     = config;
     _httpClient = httpClient;
 }
コード例 #11
0
 public TflService(HttpClient client, IApiConfig apiConfig)
 {
     _client            = client;
     client.BaseAddress = apiConfig.AppUrl;
     client.Timeout     = new TimeSpan(0, 0, 30);
     client.DefaultRequestHeaders.Clear();
     _apiConfig = apiConfig;
 }
コード例 #12
0
 public ApiClient(IApiConfig config)
 {
     _baseUri = config.BaseUri;
     foreach (var header in config.headerValues)
     {
         _client.Headers.Add(header.Key, header.Value);
     }
 }
コード例 #13
0
 internal API(ILogin login, IApiConfig config, IFactory <IApiPath> pathFacotry, OpenApiDocument spec, IFactory <IApiEventPath> eventPathFacotry)
 {
     Login                 = login;
     this.pathFacotry      = pathFacotry;
     this.eventPathFacotry = eventPathFacotry;
     Spec        = spec;
     Config      = config;
     DefaultUser = Config.DefaultUser;
 }
コード例 #14
0
 public PluginManifest(ILogger <PluginManifest> logger, IApiConfig config,
                       BroadcastsListener broadcastsListener, GuildTrafficHandler guildTrafficHandler, ComponentInteractionsListener componentInteractionsListener)
 {
     VersionString ??= Version;
     _logger                        = logger;
     _broadcastsListener            = broadcastsListener;
     _guildTrafficHandler           = guildTrafficHandler;
     _componentInteractionsListener = componentInteractionsListener;
     _apiConfig                     = config;
 }
コード例 #15
0
        public MongoRepository(IApiConfig cfg)
        {
            var typeName       = typeof(TModel).Name;
            var collectionName = typeName.Substring(0,
                                                    typeName.Length - "Model".Length);
            var client = new MongoClient(cfg.MongoDbUrl);

            database   = client.GetDatabase(cfg.MongoDbName);
            collection = database.GetCollection <TModel>(collectionName);
        }
コード例 #16
0
 /// <summary>
 /// Constructor for BaseHackerRestClient
 /// </summary>
 /// <param name="config">RestApiConfig containing details about Rest API to call</param>
 /// <param name="logger">ILogger implementation for logging</param>
 /// <param name="itemMapper">IItemMapper implementation for parsing the type from the response.</param>
 public HackerNewsRestClient(IApiConfig config,
                             IHttpClientFactory clientFactory,
                             ILogger <IHackerNewsClient <T> > logger,
                             IItemMapper <T> itemMapper)
 {
     this.apiConfig     = config;
     this.clientFactory = clientFactory;
     this.logger        = logger;
     this.itemMapper    = itemMapper;
 }
コード例 #17
0
 public UserService(
     IAppUserRepository userRepository,
     IPasswordHashing passwordHashing,
     ITokenService tokenService,
     IApiConfig apiConfig)
 {
     this.userRepository  = userRepository;
     this.passwordHashing = passwordHashing;
     this.tokenService    = tokenService;
     this.apiConfig       = apiConfig;
 }
コード例 #18
0
        public static void ThrowIfApiConfigInvalid(IApiConfig config, string?paramName = null)
        {
            ThrowIfNull(config, nameof(config));

            if (string.IsNullOrWhiteSpace(config.ApiKey))
            {
                throw new ArgumentException(
                          "Invalid API key format",
                          paramName ?? nameof(config.ApiKey));
            }
        }
コード例 #19
0
        public TokenService(
            ILogger log,
            IApiConfig apiConfig)
        {
            this.log       = log;
            this.apiConfig = apiConfig;

            if (ValidateConfig() == false)
            {
                throw new Exception("Config variables are not set properly. Can't create token.");
            }
        }
コード例 #20
0
        /// <summary>
        /// Initialize a new instance of the <see cref="ExpressWaybillApi"/> class.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="config"></param>
        /// <param name="creator"></param>
        public ExpressWaybillApi(
            IApiHttpClient client,
            IApiConfig config,
            ExpressWaybillRequestCreator creator)
        {
            ThrowHelper.ThrowIfNull(client, nameof(client));
            ThrowHelper.ThrowIfNull(config, nameof(config));
            ThrowHelper.ThrowIfNull(creator, nameof(creator));

            _client  = client;
            _config  = config;
            _creator = creator;
        }
コード例 #21
0
ファイル: AddressApi.cs プロジェクト: kachechka/NovaPoshtaApi
        /// <summary>
        /// Initialize a new instance of the <see cref="AddressApi"/> class.
        /// </summary>
        /// <param name="client"><see cref="IApiHttpClient"/> for sending requests</param>
        /// <param name="config">Api configuration</param>
        /// <param name="creator">Request creator</param>
        internal AddressApi(
            IApiHttpClient client,
            IApiConfig config,
            AddressRequestCreator creator)
        {
            ThrowHelper.ThrowIfNull(client, nameof(client));
            ThrowHelper.ThrowIfNull(config, nameof(config));
            ThrowHelper.ThrowIfNull(creator, nameof(creator));

            _client  = client;
            _config  = config;
            _creator = creator;
        }
コード例 #22
0
        public EcommerceHttpClient(IApiConfig config)
        {
            var httpClientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true
            };

            Http = new HttpClient(httpClientHandler)
            {
                BaseAddress = new Uri(config.StorageBaseAddress)
            };
            Http.DefaultRequestHeaders.Accept.Clear();
            Http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }
コード例 #23
0
        public NovaPoshtaApi(
            IApiConfig config,
            IApiHttpClient client,
            RequestHelper requestHelper)
        {
            ThrowHelper.ThrowIfApiConfigInvalid(config);
            ThrowHelper.ThrowIfNull(client, nameof(client));
            ThrowHelper.ThrowIfNull(requestHelper, nameof(requestHelper));

            _config = config;
            _client = client;

            Address        = new AddressApi(client, config, requestHelper.AddressRequestCreator);
            Directory      = new DirectoryApi(client, config, requestHelper.DirectoryRequestCreator);
            ExpressWaybill = new ExpressWaybillApi(client, config, requestHelper.ExpressWaybillRequest);
        }
コード例 #24
0
        public void Setup()
        {
            var handler = new Mock <HttpMessageHandler>();

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(request =>
                                                                                request.RequestUri.ToString() == "http://baseurl.com/explore/tags/Test_GetCount_WhenNoDeletedRecords_ReturnAllRecords/?__a=1"),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage {
                Content = new StringContent("{posts:[{}]}")
            });
            _httpClient = new HttpClient(handler.Object);

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(request =>
                                                                                request.RequestUri.ToString() == "http://baseurl.com/explore/tags/Test_GetCount_WhenHasDeletedRecords_CountOnlyActive/?__a=1"),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{posts:[{}, {IsDeleted: true}]}")
            });

            handler.Protected()
            .Setup <Task <HttpResponseMessage> >("SendAsync",
                                                 ItExpr.Is <HttpRequestMessage>(request =>
                                                                                request.RequestUri.ToString() == "http://baseurl.com/explore/tags/Test_GetPosts/?__a=1"),
                                                 ItExpr.IsAny <CancellationToken>())
            .ReturnsAsync(new HttpResponseMessage
            {
                Content = new StringContent("{posts:[{Title: 'Title'}]}")
            });

            var config = new Mock <IApiConfig>();

            config.Setup(x => x.BaseUrl).Returns("http://baseurl.com");
            _config = config.Object;
        }
コード例 #25
0
        public void Setup()
        {
            config = new Service.RestApiConfig
            {
                ApiVersion = "v0",
                BaseUri    = "hacker-news.firebaseio.com",
                IsSecure   = true
            };

            // Since HttpClient does not implement an interface, mocking by injecting
            // mocked HttpMessageHandler based on technique found at
            // https://gingter.org/2018/07/26/how-to-mock-httpclient-in-your-net-c-unit-tests/
            var handler = new Mock <HttpMessageHandler>();
            //var factory = handler.CreateClientFactory();

            var loggerMock = new Mock <ILogger <HackerNewsRestClient <Item> > >();
            var testLogger = loggerMock.Object;

            var mapperMock = new Mock <IItemMapper <Item> >();
            var testMapper = mapperMock.Object;

            //client = new HackerNewsRestClient<Item>(config, httpClient, testLogger, testMapper);
        }
コード例 #26
0
 public void Init()
 {
     apiConfig = new ApiConfig();
 }
コード例 #27
0
 public KeyVaultService(IApiConfig apiConfig)
 {
     _apiConfig = apiConfig;
     _clientSecretCredential = new(_apiConfig.AzureIdentity.TenantId, _apiConfig.AzureIdentity.ClientId, _apiConfig.AzureIdentity.ClientSecret);
     _keyClient = new(new(_apiConfig.KeyVaultUri), _clientSecretCredential);
 }
コード例 #28
0
 public RoteirizacaoApiV0(IMapLinkSignature mapLinkSignature, IRequestJSON requestJSON, IApiConfig apiConfig)
 {
     this.mapLinkSignature = mapLinkSignature;
     this.requestJSON = requestJSON;
     this.apiConfig = apiConfig;
 }
コード例 #29
0
ファイル: ExternalApi.cs プロジェクト: yngvebn/ArtistBasePage
 protected ExternalApi(IApiConfig config)
 {
     Config = config;
 }
コード例 #30
0
 public OfferProvider(IApiConfig apiConfig, HttpClient httpClient) : base(apiConfig, httpClient)
 {
 }
コード例 #31
0
 public ApiRepositoryTypeResolver(IApiConfig apiConfig)
 {
     _repositoryTypes = apiConfig.Repositories.ToDictionary(repo => repo.Alias, repo => repo.RepositoryType);
 }
コード例 #32
0
 protected BaseProvider(IApiConfig apiConfig, HttpClient httpClient)
 {
     ApiConfig  = apiConfig;
     HttpClient = httpClient;
     HttpClient.DefaultRequestHeaders.Add(ApiConfig.ApiKeyHeader, ApiConfig.ApiKeyValue);
 }
コード例 #33
0
 public MetricUrlBuilder(IApiConfig config)
 {
     _config = config;
 }
コード例 #34
0
 public ApiBuilder WithConfig(IApiConfig config)
 {
     Config = config;
     return(this);
 }
コード例 #35
0
 public ApiBuilder(IApiConfig config, ILogin login) : this()
 {
     Config = config;
     Login  = login;
 }
コード例 #36
0
 public ApiBuilder(IApiConfig config) : this()
 {
     Config = config;
 }