blob: 70530aea789f7873c961d25ebcd0d8c9afab7470 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
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}";
}
}
}
}
|