diff --git a/LICENSE b/LICENSE index 7942739..05c7df6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 RetailDriver LLC +Copyright (c) 2015-2017 RetailDriver LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 9ef9ec2..8dbed94 100644 --- a/README.md +++ b/README.md @@ -1,142 +1,73 @@ -.NET client for retailCRM API -============================= +.NET-клиент RetailCRM API +========================= -.NET client for [RetailCRM API](http://www.retailcrm.pro/docs/Developers/ApiVersion3). +.NET-клиент для работы с [RetailCRM API](http://www.retailcrm.ru/docs/Developers/Index). Клиент поддерживает версию со всеми доступными на текущий момент версиями API (v3-v5). -Requirements ------------------------ -* [Newtonsoft.Json](http://james.newtonking.com/json) - -Install with NuGet +Установка через NuGet --------------------- -Install [NuGet](http://docs.nuget.org/consume/installing-nuget). - -Run this command into [Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console) ``` bash PM> Install-Package RetailCRM.ApiClient ``` -Usage +Примеры использования --------------------- -### Get order +### Получение информации о заказе ``` csharp -using RetailCrm; -using RetailCrm.Response; +using System.Diagnostics; +using Retailcrm; +using Retailcrm.Versions.V5; ... -ApiClient api; -try -{ - api = new ApiClient( - "https://demo.retailcrm.pro", - "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH" - ); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} -ApiResponse response = null; -try -{ - response = api.ordersGet("M-2342"); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} +Client api = new Client("https://demo.retailcrm.ru", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH"); +Response response = api.OrdersGet("12345", "externalId"); if (response.isSuccessful()) { - System.Console.WriteLine(response["totalSumm"]); + Debug.WriteLine(Response.GetRawResponse()); } else { - System.Console.WriteLine( - "Error: [HTTP-code " + - response["statusCode"] + "] " + - response["errorMsg"] - ); + Debug.WriteLine($"Ошибка получения информации о заказа: [Статус HTTP-ответа {response.GetStatusCode().ToString()}]"); } ``` -### Create order +### Создание заказа ``` csharp -using RetailCrm; -using RetailCrm.Response; +using System.Diagnostics; +using Retailcrm; +using Retailcrm.Versions.V4; ... -ApiClient api; -string url, key; -try -{ - api = new ApiClient(url, key); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} -Dictionary tmpOrder = new Dictionary(){ - {"number", "example"}, - {"externalId", "example"}, - {"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - {"discount", 50}, - {"phone", "89263832233"}, - {"email", "example@gmail.com"}, - {"customerComment", "example"}, - {"customFields", new Dictionary(){ - {"reciever_phone", "example"}, - {"reciever_name", "example"}, - {"ext_number", "example"} - } - }, - {"contragentType", "individual"}, - {"orderType", "eshop-individual"}, - {"orderMethod", "app"}, - {"customerId", "555"}, - {"managerId", 8}, - {"items", new Dictionary(){ - {"0", new Dictionary(){ - {"initialPrice", 100}, - {"quantity", 1}, - {"productId", 55}, - {"productName", "example"} - } - } - } - }, - {"delivery", new Dictionary(){ - {"code", "courier"}, - {"date", DateTime.Now.ToString("Y-m-d")}, - {"address", new Dictionary(){ - {"text", "example"} - } - } - } - } - }; - -ApiResponse response = null; -try +Client api = new Client("https://demo.retailcrm.ru", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH"); +Response response = api.OrdersCreate(new Dictionary { - response = api.ordersEdit(order); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} + {"externalId", "12345"}, + {"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, + {"lastName", "Doe"}, + {"firstName", "John"}, + {"email", "john@example.com"}, + {"phone", "+79999999999"}, + {"items", new List { + new Dictionary { + {"initialPrice", 100}, + {"quantity", 1}, + {"productId", 55}, + {"productName", "example"} + }, + new Dictionary { + {"initialPrice", 200}, + {"quantity", 2}, + {"productId", 14}, + {"productName", "example too"} + } + }} +}); -if (response.isSuccessful() && 201 == response["statusCode"]) { - System.Console.WriteLine( - "Order created. Order ID is " + response["id"] - ); +if (response.isSuccessful()) { + Debug.WriteLine(Response.GetResponse()["externalId"].ToString()); } else { - System.Console.WriteLine( - "Error: [HTTP-code " + - response["statusCode"] + "] " + - response["errorMsg"] - ); + Debug.WriteLine($"Ошибка получения информации о заказа: [Статус HTTP-ответа {response.GetStatusCode().ToString()}]"); } ``` diff --git a/README.ru.md b/README.ru.md deleted file mode 100644 index a4e58f1..0000000 --- a/README.ru.md +++ /dev/null @@ -1,142 +0,0 @@ -.NET-клиент для retailCRM API -============================= - -.NET-клиент для работы с [RetailCRM API](http://www.retailcrm.ru/docs/rest-api/index.html). - -Обязательные требования ------------------------ -* [Newtonsoft.Json](http://james.newtonking.com/json) - -Установка через NuGet ---------------------- - -Для начала требуется скачать и установить сам [NuGet](http://docs.nuget.org/consume/installing-nuget). - -После этого для установки клиента требуется запустить комманду в [Package Manager Console](http://docs.nuget.org/docs/start-here/using-the-package-manager-console) -``` bash -PM> Install-Package RetailCRM.ApiClient -``` - -Примеры использования ---------------------- - -### Получение информации о заказе - -``` csharp -using RetailCrm; -using RetailCrm.Response; -... -ApiClient api; -try -{ - api = new ApiClient( - "https://demo.retailcrm.ru", - "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH" - ); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} - -ApiResponse response = null; -try -{ - response = api.ordersGet("M-2342"); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} - -if (response.isSuccessful()) { - System.Console.WriteLine(response["totalSumm"]); -} else { - System.Console.WriteLine( - "Ошибка получения информации о заказа: [Статус HTTP-ответа " + - response["statusCode"] + "] " + - response["errorMsg"] - ); -} - -``` -### Создание заказа - -``` csharp -using RetailCrm; -using RetailCrm.Response; -... -ApiClient api; -string url, key; -try -{ - api = new ApiClient(url, key); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} - -Dictionary tmpOrder = new Dictionary(){ - {"number", "example"}, - {"externalId", "example"}, - {"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}, - {"discount", 50}, - {"phone", "89263832233"}, - {"email", "example@gmail.com"}, - {"customerComment", "example"}, - {"customFields", new Dictionary(){ - {"reciever_phone", "example"}, - {"reciever_name", "example"}, - {"ext_number", "example"} - } - }, - {"contragentType", "individual"}, - {"orderType", "eshop-individual"}, - {"orderMethod", "app"}, - {"customerId", "555"}, - {"managerId", 8}, - {"items", new Dictionary(){ - {"0", new Dictionary(){ - {"initialPrice", 100}, - {"quantity", 1}, - {"productId", 55}, - {"productName", "example"} - } - } - } - }, - {"delivery", new Dictionary(){ - {"code", "courier"}, - {"date", DateTime.Now.ToString("Y-m-d")}, - {"address", new Dictionary(){ - {"text", "example"} - } - } - } - } - }; - -ApiResponse response = null; -try -{ - response = api.ordersEdit(order); -} -catch (WebException e) -{ - System.Console.WriteLine(e.ToString()); -} - -if (response.isSuccessful() && 201 == response["statusCode"]) { - System.Console.WriteLine( - "Заказ успешно создан. ID заказа в retailCRM = " + response["id"] - ); -} else { - System.Console.WriteLine( - "Ошибка создания заказа: [Статус HTTP-ответа " + - response["statusCode"] + "] " + - response["errorMsg"] - ); -} - -```