diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-26 18:22:32 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2021-12-26 18:22:32 +0300 |
commit | 54fc3320e7d64d7903b4d091fe0d5c15df01fd78 (patch) | |
tree | ac8b9aa1e883a85339a594b2797ab319cca73c4e /src/Assistant/HttpClientUtil.cs | |
parent | 20cfbfcca3a779c04aecdca5e4b465651e2be42a (diff) |
Move to /src
Diffstat (limited to 'src/Assistant/HttpClientUtil.cs')
-rw-r--r-- | src/Assistant/HttpClientUtil.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Assistant/HttpClientUtil.cs b/src/Assistant/HttpClientUtil.cs new file mode 100644 index 0000000..316ea07 --- /dev/null +++ b/src/Assistant/HttpClientUtil.cs @@ -0,0 +1,53 @@ +using System; +using System.Net; +using System.Net.Http; +using System.Threading.Tasks; + +namespace RehauSku.Assistant +{ + static class HttpClientUtil + { + private static HttpClient _httpClient = AddIn.httpClient; + + public async static Task<string> GetContentByRequest(string request) + { + Uri uri = request.ConvertToUri(); + + ServicePointManager.SecurityProtocol = + SecurityProtocolType.Tls12 | + SecurityProtocolType.Tls11 | + SecurityProtocolType.Tls; + + return await _httpClient.GetStringAsync(uri); + } + + private static Uri ConvertToUri(this string request) + { + UriBuilder baseUri = new UriBuilder("https", "shop-rehau.ru"); + + baseUri.Path = "/catalogsearch/result/index/"; + string cleanedRequest = request.CleanRequest(); + + switch (RegistryUtil.StoreResponseOrder) + { + case ResponseOrder.Relevance: + baseUri.Query = "dir=asc&order=relevance&q=" + cleanedRequest; + break; + case ResponseOrder.Name: + baseUri.Query = "dir=asc&order=name&q=" + cleanedRequest; + break; + case ResponseOrder.Price: + baseUri.Query = "dir=asc&order=price&q=" + cleanedRequest; + break; + case ResponseOrder.Series: + baseUri.Query = "dir=asc&order=sch_product_series&q=" + cleanedRequest; + break; + default: + baseUri.Query = "q=" + cleanedRequest; + break; + } + + return baseUri.Uri; + } + } +}
\ No newline at end of file |