aboutsummaryrefslogtreecommitdiff
path: root/src/Services/RhDatabaseClient.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-03-22 08:36:13 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-03-22 08:36:13 +0300
commit4f448f203471a19a1444555a895f503515ad2fda (patch)
tree301b7df2561d650e4d300d24341342bd77ac7f3e /src/Services/RhDatabaseClient.cs
parent6484cac4f025bd84f7ffa2b2030d729dafe09d3d (diff)
Add basic test
Diffstat (limited to 'src/Services/RhDatabaseClient.cs')
-rw-r--r--src/Services/RhDatabaseClient.cs52
1 files changed, 0 insertions, 52 deletions
diff --git a/src/Services/RhDatabaseClient.cs b/src/Services/RhDatabaseClient.cs
deleted file mode 100644
index 70530ae..0000000
--- a/src/Services/RhDatabaseClient.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using Newtonsoft.Json;
-using RhSolutions.AddIn;
-using RhSolutions.Models;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using System.Threading.Tasks;
-
-namespace RhSolutions.Services
-{
- public static class RhDatabaseClient
- {
- public static async Task<object> GetProduct(string line)
- {
- string request;
-
- if (Sku.TryParse(line, out var skus))
- {
- request = @"https://rh.cebotari.ru/api/products/" + skus.FirstOrDefault().ToString();
- }
-
- else
- {
- request = @"https://rh.cebotari.ru/api/search?query=" + line;
- }
-
- var response = await RhSolutionsAddIn.HttpClient.GetAsync(request);
-
- try
- {
- response.EnsureSuccessStatusCode();
- string json = await response.Content.ReadAsStringAsync();
- var product = JsonConvert.DeserializeObject<IEnumerable<Product>>(json)
- .FirstOrDefault();
-
- if (product == null)
- {
- return null;
- }
- else
- {
- return $"{product.ProductSku} {product.Name}";
- }
- }
- catch
- {
- return $"Ошибка сервера {response.StatusCode}";
- }
- }
- }
-} \ No newline at end of file