Exemple #1
0
        public async Task <ApiCallInfo> Add(ApiCallInfo apiCallInfo, CancellationToken token)
        {
            _db.ApiCallHistories.Add(apiCallInfo);

            await _db.SaveChangesAsync();

            return(apiCallInfo);
        }
        private async Task <T> _stringParameterApiCall <T>(ApiCallInfo apiCallInfo) where T : class
        {
            var service = RestService.For <IDynamicRefit <T, string> >(new HttpClient(new AuthorizedHttpClientHandler(apiCallInfo.HeaderValues))
            {
                BaseAddress = new Uri(apiCallInfo.Url)
            });

            switch (apiCallInfo.HttpMethod.ToLower())
            {
            case "post":
                return(await service.Post(apiCallInfo.Headers, JsonConvert.SerializeObject(apiCallInfo.StringQueryParamValues)));

            default:
                throw new NotImplementedException();
            }
        }
 public async Task <T> CallApi <T>(ApiCallInfo apiCallInfo) where T : class
 {
     if (apiCallInfo != null)
     {
         if (string.IsNullOrEmpty(apiCallInfo.StringQueryParamValues) && string.IsNullOrEmpty(apiCallInfo.Headers))
         {
             return(await _defaultApiCall <T>(apiCallInfo));
         }
         else
         {
             return(await _stringParameterApiCall <T>(apiCallInfo));
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }
        private async Task <T> _defaultApiCall <T>(ApiCallInfo apiCallInfo) where T : class
        {
            var service = RestService.For <IDynamicRefit <T, string> >(new HttpClient(new AuthorizedHttpClientHandler(apiCallInfo.HeaderValues))
            {
                BaseAddress = new Uri(apiCallInfo.Url)
            });

            switch (apiCallInfo.HttpMethod.ToLower())
            {
            case "get":
                return(await service.Get());

            case "post":
                return(await service.Post());

            case "delete":
                return(await service.Delete());

            default:
                throw new NotImplementedException();
            }
        }
        public async Task <T> CallApi <T, U>(ApiCallInfo apiCallInfo) where T : class
        {
            var service = RestService.For <IDynamicRefit <T, U> >(new HttpClient(new AuthorizedHttpClientHandler(apiCallInfo.HeaderValues))
            {
                BaseAddress = new Uri(apiCallInfo.Url)
            });

            switch (apiCallInfo.HttpMethod.ToLower())
            {
            case "get":
                return(await service.Get(apiCallInfo.QueryParamValues as Dictionary <string, object>));

            case "post":
                return(await service.Post((U)apiCallInfo.QueryParamValues));

            case "put":
                return(await service.Put((U)apiCallInfo.QueryParamValues));

            default:
                throw new NotImplementedException();
            }
        }
Exemple #6
0
        public async Task <ApiCallInfo> Process()
        {
            string     serviceName = "http://www.google.com";
            WebRequest request     = WebRequest.Create(serviceName);

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            var response = (HttpWebResponse)await Task.Factory
                           .FromAsync(request.BeginGetResponse,
                                      request.EndGetResponse,
                                      null);

            stopWatch.Stop();

            var apiCallHistory = new ApiCallInfo
            {
                ServiceName = serviceName,
                CreatedDate = DateTime.Now,
                TimeTaken   = stopWatch.Elapsed.TotalMilliseconds
            };

            return(apiCallHistory);
        }
Exemple #7
0
        /// <summary>
        /// Gets check type. &lt;br/&gt;&lt;br/&gt;&lt;b&gt;Roles&lt;/b&gt;&lt;br/&gt;Denied Anonymous Access&lt;br/&gt;seg.reviewer&lt;br/&gt; seg.admin
        /// </summary>
        /// <exception cref="SegApiClient.Client.ApiException">Thrown when fails to make API call</exception>
        /// <returns>Task of ApiResponse (List&lt;CardType&gt;)</returns>
        public async System.Threading.Tasks.Task <List <CardType> > ChecktypeAsyncWithHttpInfo()
        {
            var    localVarPath         = "/api/v1/segs/checkType";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
            };
            String localVarHttpContentType    = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }


            // authentication (oauth2) required
            // oauth required
            Dictionary <string, string> dictionaryToken = new Dictionary <string, string>();

            if (!String.IsNullOrEmpty(this.Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + this.Configuration.AccessToken;
                dictionaryToken.Add("Authorization", "Bearer " + this.Configuration.AccessToken);
            }

            //make Refit HTTP request
            var apiCallInfo = new ApiCallInfo()
            {
                HeaderValues = dictionaryToken,
                Url          = Configuration.BasePath + localVarPath,
                HttpMethod   = Microsoft.AspNetCore.Http.HttpMethods.Get
            };

            return(await _refitWrapper.CallApi <List <CardType> >(apiCallInfo));

            // make the HTTP request
            //IRestResponse localVarResponse = (IRestResponse) await this.Configuration.ApiClient.CallApiAsync(localVarPath,
            //    Method.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
            //    localVarPathParams, localVarHttpContentType);

            //int localVarStatusCode = (int) localVarResponse.StatusCode;

            //if (ExceptionFactory != null)
            //{
            //    Exception exception = ExceptionFactory("Checktype", localVarResponse);
            //    if (exception != null) throw exception;
            //}

            //return new ApiResponse<List<CardType>>(localVarStatusCode,
            //    localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
            //    (List<CardType>) this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(List<CardType>)));
        }