Beispiel #1
0
        /// <summary>
        /// Calls the API and gets the results
        /// </summary>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="httpClient"></param>
        /// <returns></returns>
        public Task <IEnumerable <TResult> > Call <TResult>(HttpClient httpClient)
            where TResult : new()
        {
            if (query is null)
            {
                throw new Exception("No query provided");
            }

            if (httpClient is null)
            {
                throw new ArgumentNullException(nameof(httpClient));
            }

            httpClient.BaseAddress = igdbConfiguration.IgdbUrl;

            if (httpClient.DefaultRequestHeaders.Contains(UserKeyHeaderName))
            {
                httpClient.DefaultRequestHeaders.Remove(UserKeyHeaderName);
            }

            httpClient.DefaultRequestHeaders.Add(UserKeyHeaderName, igdbConfiguration.UserToken);

            var builder = new RequestBuilder <T>(new Apicalypse.DotNet.Configuration.RequestBuilderConfiguration
            {
                CaseContract = Apicalypse.DotNet.Configuration.CaseContract.SnakeCase
            });

            query.Invoke(builder);

            return(builder.Build().Send <TResult>(httpClient, EndpointMapper.Map <T>()));
        }