2022-12-20 12:03:05 +03:00
|
|
|
|
using Newtonsoft.Json;
|
2022-12-20 12:41:46 +03:00
|
|
|
|
using RhSolutions.AddIn;
|
2022-12-20 12:03:05 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2022-12-20 12:27:47 +03:00
|
|
|
|
namespace RhSolutions.Services
|
2022-12-20 12:03:05 +03:00
|
|
|
|
{
|
|
|
|
|
public static class RhDatabaseClient
|
|
|
|
|
{
|
2022-12-20 12:27:47 +03:00
|
|
|
|
private static HttpClient httpClient = RhSolutionsAddIn.httpClient;
|
2022-12-20 12:03:05 +03:00
|
|
|
|
|
|
|
|
|
public static async Task<object> GetProduct(string line)
|
|
|
|
|
{
|
|
|
|
|
string request = @"https://rh.cebotari.ru/api/search?query=" + line;
|
|
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|