Ejemplo n.º 1
0
 public async Task <APIResponse <ComtradeResponse> > GetComtradeData(ComTradeParameters parameters, CancellationToken ct = default(CancellationToken))
 {
     try
     {
         if (parameters == null)
         {
             return(GenerateErrorResponse <ComtradeResponse>(HttpStatusCode.BadRequest, $"{nameof(parameters)} can not be empty"));
         }
         return(GenerateSuccessResponse <ComtradeResponse>(await _comtradeDataService.GetComtradeData(parameters, ct), HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         base.LogException(ex, "Error occurred while getting ComTrade data from API");
         return(GenerateErrorResponse <ComtradeResponse>());
     }
 }
        /// <summary>
        /// Gets the ComTrade data from public API
        /// </summary>
        /// <param name="parameters">Parameters for calling the API</param>
        /// <param name="ct">Cancellation token for the task</param>
        /// <returns></returns>
        public async Task<ComtradeResponse> GetComtradeData(ComTradeParameters parameters, CancellationToken ct)
        {
            string requestURL = await GenerateDataRequestURL(parameters,ct);

            return await GetApiResponse<ComtradeResponse>(requestURL, ct);
        }
 private async Task<string> GenerateDataRequestURL(ComTradeParameters parameters, CancellationToken ct)
 {
     //will be replace with logic for call based on actual parameters
     return "?max=10&type=C&freq=A&px=HS&ps=2018%2C2017%2C2016&r=124&p=36&rg=all&cc=TOTAL&uitoken=7b5bdafefc464489fb8123e5c6452328";
 }