Пример #1
0
 public void MoreThanLimitSent_DoesNotThrow()
 {
     for (int i = 0; i < 15; i++)
     {
         Assert.DoesNotThrow(() => RequestRateHttpClient.GetRequest(new Uri(DummyMatchesForPlayerEndpoint)));
     }
 }
Пример #2
0
        public HaloAPIService(string apiToken, string baseApiUrl = BaseApiUrl, IApiCacheManager apiCache = null)
        {
            Endpoints.Halo5.MajorPrefix = baseApiUrl;

            RequestRateHttpClient.SetAPIToken(apiToken);
            if (apiCache == null)
            {
                apiCache = SingletonCacheManager.Instance;
            }
            _responseProcessor = new ResponseProcessor(apiCache);
            HaloWars2          = new HaloWars2APIService(_responseProcessor, baseApiUrl, apiCache);
        }
Пример #3
0
 public HaloAPIService(HaloAPIConfig config, IApiCacheManager apiCache = null)
 {
     Endpoints.Halo5.MajorPrefix = config.BaseApiUrl;
     _statCacheExpiry            = config.StatCacheExpiry;
     _profileCacheExpiry         = config.ProfileCacheExpiry;
     _ugcCacheExpiry             = config.UGCCacheExpiry;
     RequestRateHttpClient.SetAPIToken(config.APIToken);
     if (apiCache == null && config.UseDefaultCache)
     {
         apiCache = SingletonCacheManager.Instance;
     }
     _responseProcessor = new ResponseProcessor(apiCache);
     HaloWars2          = new HaloWars2APIService(_responseProcessor, config.APIToken, apiCache);
 }
Пример #4
0
        public async Task <T> ProcessRequest <T>(Uri endpoint, int cacheExpiryMin) where T : class
        {
            string key = endpoint.AbsoluteUri;

            if (CacheManager.Contains(key))
            {
                return(CacheManager.Get <T>(key));
            }
            var message = await RequestRateHttpClient.GetRequest(endpoint);

            var messageObject = await HandleResponse <T>(message);

            CacheManager.Add <T>(messageObject, key, cacheExpiryMin);
            return(messageObject);
        }
Пример #5
0
        public async Task <Image> ProcessImageRequest(Uri endpoint, int cacheExpiryMin, bool bustCache = false)
        {
            string key = endpoint.AbsoluteUri;

            if (!bustCache && _apiCache.Contains(key))
            {
                return(_apiCache.Get <Image>(key));
            }
            if (bustCache)
            {
                _apiCache.Remove(key);
            }
            var message = await RequestRateHttpClient.GetRequest(endpoint);

            var messageObject = await HandleImageResponse(message);

            _apiCache.Add <Image>(messageObject, key, cacheExpiryMin);
            return(messageObject);
        }
Пример #6
0
 public void ChangeTokenToInvalid_ThrowAccessDenied(string token)
 {
     RequestRateHttpClient.SetAPIToken(token);
     Assert.Throws <HaloAPIException>(async() => await HaloApiService.GetArenaServiceRecords(new[] { "Glitch100" }), CommonErrorMessages.AccessDenied);
 }
Пример #7
0
 public void Default_DoesNotThrow(string token)
 {
     Assert.DoesNotThrow(() => RequestRateHttpClient.SetAPIToken(token));
 }
Пример #8
0
 public HaloAPIService(string apiToken, string baseApiUrl = "https://www.haloapi.com")
 {
     Endpoints.MajorPrefix = baseApiUrl;
     RequestRateHttpClient.SetAPIToken(apiToken);
     _responseProcessor = new ResponseProcessor();
 }
Пример #9
0
 public void Default_InvalidAPIKey_Unauthorized()
 {
     RequestRateHttpClient.SetAPIToken("INVALID");
     Assert.Throws <HaloAPIException>(async() => await HaloApiService.GetMatchesForPlayer("a", GameMode.Arena),
                                      CommonErrorMessages.AccessDenied);
 }
Пример #10
0
 public void Default_DoesNotThrow()
 {
     Assert.DoesNotThrow(() => RequestRateHttpClient.GetRequest(new Uri(DummyMatchesForPlayerEndpoint)));
 }