aboutsummaryrefslogtreecommitdiff
path: root/src/Services/RhDatabaseClient.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2022-12-20 12:27:47 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2022-12-20 12:27:47 +0300
commit73569a43644309d0342817580bcfd86c1face5b8 (patch)
treef3c6e15db82130b02ec8c3fa1b64674e6a9cf48d /src/Services/RhDatabaseClient.cs
parent3d186c22e8665b80839495fdcf4b176c2f3e03b9 (diff)
Namespace refactoring
Diffstat (limited to 'src/Services/RhDatabaseClient.cs')
-rw-r--r--src/Services/RhDatabaseClient.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Services/RhDatabaseClient.cs b/src/Services/RhDatabaseClient.cs
new file mode 100644
index 0000000..c57d4d8
--- /dev/null
+++ b/src/Services/RhDatabaseClient.cs
@@ -0,0 +1,45 @@
+using Newtonsoft.Json;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+namespace RhSolutions.Services
+{
+ public static class RhDatabaseClient
+ {
+ private static HttpClient httpClient = RhSolutionsAddIn.httpClient;
+
+ public static async Task<object> GetProduct(string line)
+ {
+ string request = @"https://rh.cebotari.ru/api/search?query=" + line;
+
+ ServicePointManager.SecurityProtocol =
+ SecurityProtocolType.Tls12 |
+ SecurityProtocolType.Tls11 |
+ SecurityProtocolType.Tls;
+
+ string response = await httpClient.GetStringAsync(request);
+
+ var products = JsonConvert.DeserializeObject<IEnumerable<DbProduct>>(response);
+
+ var product = products.FirstOrDefault();
+
+ if (product == null)
+ {
+ return null;
+ }
+ else
+ {
+ return $"{product.productSku} {product.name}";
+ }
+ }
+
+ private class DbProduct
+ {
+ public string productSku { get; set; }
+ public string name { get; set; }
+ }
+ }
+} \ No newline at end of file