diff --git a/README.md b/README.md index 6a517a9..cc3b641 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,23 @@ ============================= .NET-клиент для работы с [RetailCRM API](http://www.retailcrm.ru/docs/rest-api/index.html). -version: 3.0.0 + +version: 3.0.2 Обязательные требования ----------------------- * [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 +``` + Примеры использования --------------------- diff --git a/RetailCrm/ApiClient.cs b/RetailCrm/ApiClient.cs index dce708a..12dda5c 100644 --- a/RetailCrm/ApiClient.cs +++ b/RetailCrm/ApiClient.cs @@ -55,8 +55,8 @@ namespace RetailCrm "/orders/create", Client.METHOD_POST, this.fillSite( - site, - new Dictionary() { + site, + new Dictionary() { { "order", JsonConvert.SerializeObject(order) } } ) @@ -90,7 +90,7 @@ namespace RetailCrm Client.METHOD_POST, this.fillSite( site, - new Dictionary() { + new Dictionary() { { "order", JsonConvert.SerializeObject(order) }, { "by", by } } @@ -116,7 +116,7 @@ namespace RetailCrm Client.METHOD_POST, this.fillSite( site, - new Dictionary() { + new Dictionary() { { "orders", JsonConvert.SerializeObject(orders) } } ) @@ -277,7 +277,7 @@ namespace RetailCrm Client.METHOD_POST, this.fillSite( site, - new Dictionary() { + new Dictionary() { { "customer", JsonConvert.SerializeObject(customer) } } ) @@ -311,7 +311,7 @@ namespace RetailCrm Client.METHOD_POST, this.fillSite( site, - new Dictionary() { + new Dictionary() { { "customer", JsonConvert.SerializeObject(customer) }, { "by", by } } @@ -337,7 +337,7 @@ namespace RetailCrm Client.METHOD_POST, this.fillSite( site, - new Dictionary() { + new Dictionary() { { "customers", JsonConvert.SerializeObject(customers) } } ) @@ -414,6 +414,175 @@ namespace RetailCrm ); } + /// + /// Returns filtered orders packs list + /// + /// + /// + /// + /// ApiResponse + public ApiResponse packsList(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter.Count > 0) + { + parameters.Add("filter", filter); + } + if (page > 0) + { + parameters.Add("page", page); + } + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return client.makeRequest("/orders/packs", Client.METHOD_GET, parameters); + } + + /// + /// Create a order pack + /// + /// + /// ApiResponse + public ApiResponse packsCreate(Dictionary pack) + { + if (pack.Count < 1) + { + throw new ArgumentException("Parameter `pack` must contains a data"); + } + + return client.makeRequest( + "/orders/packs/create", + Client.METHOD_POST, + new Dictionary() { + { "pack", JsonConvert.SerializeObject(pack) } + } + ); + } + + /// + /// Returns a orders history + /// + /// + /// + /// + /// ApiResponse + public ApiResponse packsHistory(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter.Count > 0) + { + parameters.Add("filter", filter); + } + if (page > 0) + { + parameters.Add("page", page); + } + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return client.makeRequest("/orders/packs/history", Client.METHOD_GET, parameters); + } + + /// + /// Get order packs by id + /// + /// + /// ApiResponse + public ApiResponse packsGet(string id) + { + return client.makeRequest("/orders/packs/" + id, Client.METHOD_GET); + } + + /// + /// Delete order packs by id + /// + /// + /// ApiResponse + public ApiResponse packsDelete(string id) + { + return client.makeRequest("/orders/packs/" + id + "/delete", Client.METHOD_POST); + } + + /// + /// Edit a order packs + /// + /// + /// + /// ApiResponse + public ApiResponse packsEdit(string id, Dictionary pack) + { + if (pack.Count < 1) + { + throw new ArgumentException("Parameter `pack` must contains a data"); + } + + return client.makeRequest( + "/orders/packs/" + id + "/edit", + Client.METHOD_POST, + new Dictionary() { + { "pack", JsonConvert.SerializeObject(pack) } + } + ); + } + + /// + /// Returns filtered store inventories list + /// + /// + /// + /// + /// ApiResponse + public ApiResponse inventoriesList(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter.Count > 0) + { + parameters.Add("filter", filter); + } + if (page > 0) + { + parameters.Add("page", page); + } + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return client.makeRequest("/store/inventories", Client.METHOD_GET, parameters); + } + + /// + /// Upload array of the store inventories + /// + /// + /// + /// ApiResponse + public ApiResponse inventoriesUpload(Dictionary offers, string site = "") + { + if (offers.Count < 1) + { + throw new ArgumentException("Parameter `offers` must contains a data"); + } + + return client.makeRequest( + "/store/inventories/upload", + Client.METHOD_POST, + this.fillSite( + site, + new Dictionary() { + { "offers", JsonConvert.SerializeObject(offers) } + } + ) + ); + } + /// /// Returns deliveryServices list /// @@ -504,6 +673,15 @@ namespace RetailCrm return client.makeRequest("/reference/sites", Client.METHOD_GET); } + /// + /// Returns stores list + /// + /// ApiResponse + public ApiResponse storesList() + { + return client.makeRequest("/reference/stores", Client.METHOD_GET); + } + /// /// Edit deliveryService /// @@ -519,7 +697,7 @@ namespace RetailCrm return client.makeRequest( "/reference/delivery-services/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "deliveryService", JsonConvert.SerializeObject(data) } } ); @@ -540,7 +718,7 @@ namespace RetailCrm return client.makeRequest( "/reference/delivery-types/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "deliveryType", JsonConvert.SerializeObject(data) } } ); @@ -561,7 +739,7 @@ namespace RetailCrm return client.makeRequest( "/reference/order-methods/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "orderMethod", JsonConvert.SerializeObject(data) } } ); @@ -582,7 +760,7 @@ namespace RetailCrm return client.makeRequest( "/reference/order-types/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "orderType", JsonConvert.SerializeObject(data) } } ); @@ -603,7 +781,7 @@ namespace RetailCrm return client.makeRequest( "/reference/payment-statuses/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "paymentStatus", JsonConvert.SerializeObject(data) } } ); @@ -624,7 +802,7 @@ namespace RetailCrm return client.makeRequest( "/reference/payment-types/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "paymentType", JsonConvert.SerializeObject(data) } } ); @@ -645,7 +823,7 @@ namespace RetailCrm return client.makeRequest( "/reference/product-statuses/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "productStatus", JsonConvert.SerializeObject(data) } } ); @@ -666,7 +844,7 @@ namespace RetailCrm return client.makeRequest( "/reference/statuses/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "status", JsonConvert.SerializeObject(data) } } ); @@ -687,12 +865,33 @@ namespace RetailCrm return client.makeRequest( "/reference/sites/" + data["code"] + "/edit", Client.METHOD_POST, - new Dictionary() { + new Dictionary() { { "site", JsonConvert.SerializeObject(data) } } ); } + /// + /// Edit stores + /// + /// + /// ApiResponse + public ApiResponse storesEdit(Dictionary store) + { + if (store.ContainsKey("code") == false) + { + throw new ArgumentException("Data must contain \"code\" parameter"); + } + + return client.makeRequest( + "/reference/stores/" + store["code"] + "/edit", + Client.METHOD_POST, + new Dictionary() { + { "store", JsonConvert.SerializeObject(store) } + } + ); + } + /// /// Update CRM basic statistic /// @@ -725,7 +924,7 @@ namespace RetailCrm /// protected void checkIdParameter(string by) { - string[] allowedForBy = new string[]{"externalId", "id"}; + string[] allowedForBy = new string[] { "externalId", "id" }; if (allowedForBy.Contains(by) == false) { throw new ArgumentException("Value \"" + by + "\" for parameter \"by\" is not valid. Allowed values are " + String.Join(", ", allowedForBy)); @@ -743,7 +942,7 @@ namespace RetailCrm if (site.Length > 1) { param.Add("site", site); - } + } else if (siteCode.Length > 1) { param.Add("site", siteCode); diff --git a/lib/RetailCrm.dll b/lib/RetailCrm.dll deleted file mode 100644 index 147cbaa..0000000 Binary files a/lib/RetailCrm.dll and /dev/null differ