diff options
author | Sergey Chebotar <s.chebotar@gmail.com> | 2023-03-22 08:36:13 +0300 |
---|---|---|
committer | Sergey Chebotar <s.chebotar@gmail.com> | 2023-03-22 08:36:13 +0300 |
commit | 4f448f203471a19a1444555a895f503515ad2fda (patch) | |
tree | 301b7df2561d650e4d300d24341342bd77ac7f3e /src/Services/RhDatabaseClient.cs | |
parent | 6484cac4f025bd84f7ffa2b2030d729dafe09d3d (diff) |
Add basic test
Diffstat (limited to 'src/Services/RhDatabaseClient.cs')
-rw-r--r-- | src/Services/RhDatabaseClient.cs | 52 |
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 |