public MapLinkFactoryApiV0(IMapLinkSignature mapLinkSignature, IRequestJSON requestJSON, IApiConfig apiConfig)
     : base("v0")
 {
     this.mapLinkSignature = mapLinkSignature;
     this.requestJSON = requestJSON;
     this.apiConfig = apiConfig;
 }
 public MapLinkFactoryApiV0()
     : base("v0")
 {
     mapLinkSignature = new MapLinkSignatureV0();
     requestJSON = new RequestJSON();
     apiConfig = new ApiConfig();
 }
Esempio n. 3
0
 public FileHandlerResolver(
     IServiceProvider serviceProvider,
     IApiConfig config)
 {
     _serviceProvider = serviceProvider;
     _config          = config;
 }
Esempio n. 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));
        }
 public PostService7(HttpClient client, IApiConfig apiConfig, IMapper mapper, IFeatureConfig featureConfig)
 {
     _apiConfig     = apiConfig;
     _mapper        = mapper;
     _featureConfig = featureConfig;
     _client        = client;
 }
 public ApiDataViewResolver(
     IApiConfig apiConfig,
     IServiceProvider serviceProvider)
 {
     _dataViewTypes   = apiConfig.DataViews.ToDictionary(dataView => dataView.Alias, dataView => dataView.DataViewBuilder);
     _serviceProvider = serviceProvider;
 }
Esempio n. 7
0
 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;
 }
 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();
 }
Esempio n. 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);
        });
    }
Esempio n. 10
0
 public TodoService(
     IApiConfig config,
     HttpClient httpClient)
 {
     _config     = config;
     _httpClient = httpClient;
 }
Esempio n. 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;
 }
 public ApiClient(IApiConfig config)
 {
     _baseUri = config.BaseUri;
     foreach (var header in config.headerValues)
     {
         _client.Headers.Add(header.Key, header.Value);
     }
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 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);
        }
 /// <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;
 }
Esempio n. 17
0
 public UserService(
     IAppUserRepository userRepository,
     IPasswordHashing passwordHashing,
     ITokenService tokenService,
     IApiConfig apiConfig)
 {
     this.userRepository  = userRepository;
     this.passwordHashing = passwordHashing;
     this.tokenService    = tokenService;
     this.apiConfig       = apiConfig;
 }
Esempio n. 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));
            }
        }
Esempio n. 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.");
            }
        }
Esempio n. 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;
        }
Esempio n. 21
0
        /// <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;
        }
Esempio n. 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"));
        }
Esempio n. 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);
        }
Esempio n. 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;
        }
        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);
        }
Esempio n. 26
0
 public void Init()
 {
     apiConfig = new ApiConfig();
 }
Esempio n. 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);
 }
Esempio n. 28
0
 public RoteirizacaoApiV0(IMapLinkSignature mapLinkSignature, IRequestJSON requestJSON, IApiConfig apiConfig)
 {
     this.mapLinkSignature = mapLinkSignature;
     this.requestJSON = requestJSON;
     this.apiConfig = apiConfig;
 }
Esempio n. 29
0
 protected ExternalApi(IApiConfig config)
 {
     Config = config;
 }
 public OfferProvider(IApiConfig apiConfig, HttpClient httpClient) : base(apiConfig, httpClient)
 {
 }
 public ApiRepositoryTypeResolver(IApiConfig apiConfig)
 {
     _repositoryTypes = apiConfig.Repositories.ToDictionary(repo => repo.Alias, repo => repo.RepositoryType);
 }
 protected BaseProvider(IApiConfig apiConfig, HttpClient httpClient)
 {
     ApiConfig  = apiConfig;
     HttpClient = httpClient;
     HttpClient.DefaultRequestHeaders.Add(ApiConfig.ApiKeyHeader, ApiConfig.ApiKeyValue);
 }
Esempio n. 33
0
 public MetricUrlBuilder(IApiConfig config)
 {
     _config = config;
 }
Esempio n. 34
0
 public ApiBuilder WithConfig(IApiConfig config)
 {
     Config = config;
     return(this);
 }
Esempio n. 35
0
 public ApiBuilder(IApiConfig config, ILogin login) : this()
 {
     Config = config;
     Login  = login;
 }
Esempio n. 36
0
 public ApiBuilder(IApiConfig config) : this()
 {
     Config = config;
 }