/// <summary> /// Gets the parameter for the resource endpoint based on the searchtype selected /// </summary> /// <param name="rateLimitType"></param> /// <returns></returns> private static string GetSearchResource(AnalyticRateLimitType rateLimitType) { switch (rateLimitType) { case AnalyticRateLimitType.TopIps: return("ips"); default: throw new AlgoliaException("Invalid Rate Limit Feature Selected"); } }
/// <summary> /// Get Analytics features for Rate Limits /// Consult Algolia Analytics documentation for options /// </summary> /// <param name="options"></param> /// <param name="searchType"></param> /// <returns></returns> public async Task <JObject> GetAnalyticsForRateLimits(AnalyticsOptions options, AnalyticRateLimitType searchType) { var requestUrl = $"{AnalyticsApiUrl}/ratelimits/{Indices}/{GetSearchResource(searchType)}"; if (!string.IsNullOrWhiteSpace(options.RequestString)) { requestUrl += options.RequestString; } var httpRequest = await _httpClient.GetAsync(requestUrl); var httpResponse = string.Empty; if (httpRequest.IsSuccessStatusCode) { httpResponse = await httpRequest.Content.ReadAsStringAsync(); } else { switch (httpRequest.StatusCode) { case HttpStatusCode.Forbidden: throw new AlgoliaException("Invalid Incredentials."); case HttpStatusCode.InternalServerError: throw new AlgoliaException("An Internal server error occurred."); } } var result = JObject.Parse(httpResponse); return(result); }
/// <summary> /// Default method for getting analytics for ratelimits /// </summary> /// <param name="searchType"></param> /// <returns></returns> public async Task <JObject> GetAnalyticsForRateLimits(AnalyticRateLimitType searchType) { return(await GetAnalyticsForRateLimits(new AnalyticsOptions(), searchType)); }