public async Task <GetProxyResult> GetProxy(GetProxySearchCriteria criteria) { try { return(await _baseApiUrl .AppendPathSegment("proxy") .SetQueryParams(criteria.GetQueryParamsObject()) .SetQueryParam("apiKey", _apiKey) .GetJsonAsync <GetProxyResult>()); } catch (FlurlHttpException ex) { var errorResponse = await ex.GetResponseJsonAsync <ErrorResult>(); switch (errorResponse.Error) { case ErrorMesssages.InvalidApiKey: throw new InvalidApiKeyException(); case ErrorMesssages.ExpiredApiKey: throw new ExpiredApiKeyException(); default: throw new Exception(errorResponse.Error); } } }
public static object GetQueryParamsObject(this GetProxySearchCriteria value) { return(new { lastTested = value.LastTested, port = value.Port, anonymity = value.Anonymity, protocol = value.Protocol, allowsRefererHeader = value.AllowsRefererHeader, allowsUserAgentHeader = value.AllowsUserAgentHeader, allowsCustomHeaders = value.AllowsCustomHeaders, allowsCookies = value.AllowsCookies, allowsPost = value.AllowsPost, allowsHttps = value.AllowsHttps, country = value.Country, notCountry = value.NotCountry, ip = value.Ip, maxConnectTime = value.MaxConnectTime, maxSecondsToFirstByte = value.MaxSecondsToFirstByte, minDownloadSpeed = value.MinDownloadSpeed, minUptime = value.MinUptime, all = value.All }); }