diff --git a/Retailcrm/Retailcrm.csproj b/Retailcrm/Retailcrm.csproj index 0048f2f..58508c2 100644 --- a/Retailcrm/Retailcrm.csproj +++ b/Retailcrm/Retailcrm.csproj @@ -55,9 +55,25 @@ + + + + + + + + + + + + + + + + diff --git a/Retailcrm/Versions/V3/Packs.cs b/Retailcrm/Versions/V3/Packs.cs index f83c8e6..3a81f8b 100644 --- a/Retailcrm/Versions/V3/Packs.cs +++ b/Retailcrm/Versions/V3/Packs.cs @@ -69,11 +69,6 @@ public Response PacksDelete(string id) { - if (id.Length < 1) - { - throw new ArgumentException("Parameter `id` must contains a data"); - } - return Request.MakeRequest( $"/orders/packs/{id}/delete", Request.MethodPost diff --git a/Retailcrm/Versions/V3/References.cs b/Retailcrm/Versions/V3/References.cs index c671608..f9fed36 100644 --- a/Retailcrm/Versions/V3/References.cs +++ b/Retailcrm/Versions/V3/References.cs @@ -1,12 +1,363 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Retailcrm.Versions.V3 +namespace Retailcrm.Versions.V3 { - class References + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client { + public Response Countries() + { + return Request.MakeRequest( + "/reference/countries", + Request.MethodGet + ); + } + + public Response DeliveryServices() + { + return Request.MakeRequest( + "/reference/delivery-services", + Request.MethodGet + ); + } + + public Response DeliveryTypes() + { + return Request.MakeRequest( + "/reference/delivery-types", + Request.MethodGet + ); + } + + public Response OrderMethods() + { + return Request.MakeRequest( + "/reference/order-methods", + Request.MethodGet + ); + } + + public Response OrderTypes() + { + return Request.MakeRequest( + "/reference/order-types", + Request.MethodGet + ); + } + + public Response PaymentStatuses() + { + return Request.MakeRequest( + "/reference/payment-statuses", + Request.MethodGet + ); + } + + public Response PaymentTypes() + { + return Request.MakeRequest( + "/reference/payment-types", + Request.MethodGet + ); + } + + public Response ProductStatuses() + { + return Request.MakeRequest( + "/reference/product-statuses", + Request.MethodGet + ); + } + + public Response Sites() + { + return Request.MakeRequest( + "/reference/sites", + Request.MethodGet + ); + } + + public Response StatusGroups() + { + return Request.MakeRequest( + "/reference/status-groups", + Request.MethodGet + ); + } + + public Response Statuses() + { + return Request.MakeRequest( + "/reference/statuses", + Request.MethodGet + ); + } + + public Response Stores() + { + return Request.MakeRequest( + "/reference/stores", + Request.MethodGet + ); + } + + public Response DeliveryServicesEdit(Dictionary service) + { + if (!service.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!service.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/delivery-services/{service["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "deliveryService", new JavaScriptSerializer().Serialize(service) } + } + ); + } + + public Response DeliveryTypesEdit(Dictionary type) + { + if (!type.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!type.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + if (!type.ContainsKey("defaultCost")) + { + throw new ArgumentException("Parameter `defaultCost` is missing"); + } + + if (!type.ContainsKey("defaultNetCost")) + { + throw new ArgumentException("Parameter `defaultCost` is missing"); + } + + return Request.MakeRequest( + $"/reference/delivery-types/{type["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "deliveryType", new JavaScriptSerializer().Serialize(type) } + } + ); + } + + public Response OrderMethodsEdit(Dictionary method) + { + if (!method.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!method.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/order-methods/{method["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "orderMethod", new JavaScriptSerializer().Serialize(method) } + } + ); + } + + public Response OrderTypesEdit(Dictionary type) + { + if (!type.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!type.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/order-types/{type["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "orderType", new JavaScriptSerializer().Serialize(type) } + } + ); + } + + public Response PaymentStatusesEdit(Dictionary status) + { + if (!status.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!status.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/payment-statuses/{status["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "paymentStatus", new JavaScriptSerializer().Serialize(status) } + } + ); + } + + public Response PaymentTypesEdit(Dictionary type) + { + if (!type.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!type.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/payment-types/{type["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "paymentType", new JavaScriptSerializer().Serialize(type) } + } + ); + } + + public Response ProductStatusesEdit(Dictionary status) + { + if (!status.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!status.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/product-statuses/{status["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "productStatus", new JavaScriptSerializer().Serialize(status) } + } + ); + } + + public Response SitesEdit(Dictionary site) + { + if (!site.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!site.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + if (!site.ContainsKey("url")) + { + throw new ArgumentException("Parameter `url` is missing"); + } + + return Request.MakeRequest( + $"/reference/sites/{site["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "site", new JavaScriptSerializer().Serialize(site) } + } + ); + } + + public Response StatusesEdit(Dictionary status) + { + if (!status.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!status.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + if (!status.ContainsKey("ordering")) + { + throw new ArgumentException("Parameter `ordering` is missing"); + } + + if (!status.ContainsKey("group")) + { + throw new ArgumentException("Parameter `group` is missing"); + } + + return Request.MakeRequest( + $"/reference/statuses/{status["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "status", new JavaScriptSerializer().Serialize(status) } + } + ); + } + + public Response StoresEdit(Dictionary store) + { + if (!store.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!store.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + List types = new List + { + "store-type-online", + "store-type-retail", + "store-type-supplier", + "store-type-warehouse" + }; + + if (store.ContainsKey("type") && !types.Contains(store["type"].ToString())) + { + throw new ArgumentException("Parameter `type` should be equal to one of `store-type-online|store-type-retail|store-type-supplier|store-type-warehouse`"); + } + + return Request.MakeRequest( + $"/reference/stores/{store["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "store", new JavaScriptSerializer().Serialize(store) } + } + ); + } } } diff --git a/Retailcrm/Versions/V4/Customers.cs b/Retailcrm/Versions/V4/Customers.cs new file mode 100644 index 0000000..90d5c7b --- /dev/null +++ b/Retailcrm/Versions/V4/Customers.cs @@ -0,0 +1,29 @@ +namespace Retailcrm.Versions.V4 +{ + using System.Collections.Generic; + + public partial class Client + { + public Response CustomersHistory(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/customers/history", Request.MethodGet, parameters); + } + } +} diff --git a/Retailcrm/Versions/V4/Delivery.cs b/Retailcrm/Versions/V4/Delivery.cs new file mode 100644 index 0000000..31e3b15 --- /dev/null +++ b/Retailcrm/Versions/V4/Delivery.cs @@ -0,0 +1,81 @@ +namespace Retailcrm.Versions.V4 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response DeliverySettingGet(string code) + { + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `code` is mandatory"); + } + + return Request.MakeRequest( + $"/delivery/generic/setting/{code}", + Request.MethodGet + ); + } + + public Response DeliverySettingsEdit(Dictionary configuration) + { + if (configuration.Count < 1) + { + throw new ArgumentException("Parameter `configuration` must contain data"); + } + + if (!configuration.ContainsKey("clientId")) + { + throw new ArgumentException("Parameter `configuration` should contain `clientId`"); + } + + if (!configuration.ContainsKey("baseUrl")) + { + throw new ArgumentException("Parameter `configuration` should contain `baseUrl`"); + } + + if (!configuration.ContainsKey("code")) + { + throw new ArgumentException("Parameter `configuration` should contain `code`"); + } + + if (!configuration.ContainsKey("name")) + { + throw new ArgumentException("Parameter `configuration` should contain `name`"); + } + + return Request.MakeRequest( + $"/delivery/generic/setting/{configuration["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "configuration", new JavaScriptSerializer().Serialize(configuration) } + } + ); + } + + public Response DeliveryTracking(string code, List statusUpdate) + { + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `code` is mandatory"); + } + + if (statusUpdate.Count < 1) + { + throw new ArgumentException("Parameter `statusUpdate` must contain data"); + } + + return Request.MakeRequest( + $"delivery/generic/{code}/edit", + Request.MethodPost, + new Dictionary + { + { "statusUpdate", new JavaScriptSerializer().Serialize(statusUpdate) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/Marketplace.cs b/Retailcrm/Versions/V4/Marketplace.cs new file mode 100644 index 0000000..46930c4 --- /dev/null +++ b/Retailcrm/Versions/V4/Marketplace.cs @@ -0,0 +1,36 @@ +namespace Retailcrm.Versions.V4 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response MarketplaceSettingsEdit(Dictionary configuration) + { + if (configuration.Count < 1) + { + throw new ArgumentException("Parameter `configuration` must contain data"); + } + + if (!configuration.ContainsKey("code")) + { + throw new ArgumentException("Parameter `configuration` should contain `code`"); + } + + if (!configuration.ContainsKey("name")) + { + throw new ArgumentException("Parameter `configuration` should contain `name`"); + } + + return Request.MakeRequest( + $"/marketplace/external/setting/{configuration["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "configuration", new JavaScriptSerializer().Serialize(configuration) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/References.cs b/Retailcrm/Versions/V4/References.cs new file mode 100644 index 0000000..05bbd2e --- /dev/null +++ b/Retailcrm/Versions/V4/References.cs @@ -0,0 +1,39 @@ +namespace Retailcrm.Versions.V4 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response PriceTypes() + { + return Request.MakeRequest( + "/reference/price-types", + Request.MethodGet + ); + } + + public Response PriceTypesEdit(Dictionary type) + { + if (!type.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!type.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + return Request.MakeRequest( + $"/reference/price-types/{type["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "priceType", new JavaScriptSerializer().Serialize(type) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/Stores.cs b/Retailcrm/Versions/V4/Stores.cs new file mode 100644 index 0000000..558edfa --- /dev/null +++ b/Retailcrm/Versions/V4/Stores.cs @@ -0,0 +1,103 @@ +namespace Retailcrm.Versions.V4 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response StoreProducts(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/store/products", Request.MethodGet, parameters); + } + + public Response StorePricesUpload(List prices) + { + if (prices.Count< 1) + { + throw new ArgumentException("Parameter `prices` must contains a data"); + } + + if (prices.Count > 250) + { + throw new ArgumentException("Parameter `prices` must contain 250 or less records"); + } + + return Request.MakeRequest( + "/store/prices/upload", + Request.MethodPost, + new Dictionary + { + { "prices", new JavaScriptSerializer().Serialize(prices) } + } + ); + } + + public Response StoreSettingGet(string code) + { + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `code` is mandatory"); + } + + return Request.MakeRequest( + $"/store/setting/{code}", + Request.MethodGet + ); + } + + public Response StoreSettingsEdit(Dictionary configuration) + { + if (configuration.Count < 1) + { + throw new ArgumentException("Parameter `configuration` must contain data"); + } + + if (!configuration.ContainsKey("clientId")) + { + throw new ArgumentException("Parameter `configuration` should contain `clientId`"); + } + + if (!configuration.ContainsKey("baseUrl")) + { + throw new ArgumentException("Parameter `configuration` should contain `baseUrl`"); + } + + if (!configuration.ContainsKey("code")) + { + throw new ArgumentException("Parameter `configuration` should contain `code`"); + } + + if (!configuration.ContainsKey("name")) + { + throw new ArgumentException("Parameter `configuration` should contain `name`"); + } + + return Request.MakeRequest( + $"/store/setting/{configuration["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "configuration", new JavaScriptSerializer().Serialize(configuration) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V4/Users.cs b/Retailcrm/Versions/V4/Users.cs new file mode 100644 index 0000000..a15cd3d --- /dev/null +++ b/Retailcrm/Versions/V4/Users.cs @@ -0,0 +1,51 @@ +namespace Retailcrm.Versions.V4 +{ + using System.Collections.Generic; + + public partial class Client + { + public Response Users(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/users", Request.MethodGet, parameters); + } + + public Response UsersGroups(int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/user-groups", Request.MethodGet, parameters); + } + + public Response User(int id) + { + return Request.MakeRequest($"/users/{id}", Request.MethodGet); + } + } +} diff --git a/Retailcrm/Versions/V5/Costs.cs b/Retailcrm/Versions/V5/Costs.cs new file mode 100644 index 0000000..2d67312 --- /dev/null +++ b/Retailcrm/Versions/V5/Costs.cs @@ -0,0 +1,123 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response CostsList(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/costs", Request.MethodGet, parameters); + } + + public Response CostsCreate(Dictionary cost, string site = "") + { + if (cost.Count < 1) + { + throw new ArgumentException("Parameter `cost` must contains a data"); + } + + return Request.MakeRequest( + "/costs/create", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "cost", new JavaScriptSerializer().Serialize(cost) } + } + ) + ); + } + + public Response CostsDelete(List ids) + { + if (ids.Count < 1) + { + throw new ArgumentException("Parameter `ids` must contains a data"); + } + + return Request.MakeRequest( + "/costs/delete", + Request.MethodPost, + new Dictionary + { + { "ids", new JavaScriptSerializer().Serialize(ids) } + } + ); + } + + public Response CostsUpload(List costs) + { + if (costs.Count < 1) + { + throw new ArgumentException("Parameter `costs` must contains a data"); + } + + return Request.MakeRequest( + "/costs/upload", + Request.MethodPost, + new Dictionary + { + { "costs", new JavaScriptSerializer().Serialize(costs) } + } + ); + } + + public Response CostsGet(int id) + { + return Request.MakeRequest($"/costs/{id}", Request.MethodGet); + } + + public Response CostsDelete(string id) + { + return Request.MakeRequest( + $"/costs/{id}/delete", + Request.MethodPost + ); + } + + public Response CostsUpdate(Dictionary cost, string site = "") + { + if (cost.Count < 1) + { + throw new ArgumentException("Parameter `cost` must contains a data"); + } + + if (!cost.ContainsKey("id")) + { + throw new ArgumentException("Parameter `cost` must contains an id"); + } + + return Request.MakeRequest( + $"/costs/{cost["id"].ToString()}/edit", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "cost", new JavaScriptSerializer().Serialize(cost) } + } + ) + ); + } + } +} diff --git a/Retailcrm/Versions/V5/Delivery.cs b/Retailcrm/Versions/V5/Delivery.cs new file mode 100644 index 0000000..d77f6bc --- /dev/null +++ b/Retailcrm/Versions/V5/Delivery.cs @@ -0,0 +1,18 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + + public partial class Client + { + public new Response DeliverySettingGet(string code) + { + throw new ArgumentException("This method is unavailable in API V5", code); + } + + public new Response DeliverySettingsEdit(Dictionary configuration) + { + throw new ArgumentException("This method is unavailable in API V5"); + } + } +} diff --git a/Retailcrm/Versions/V5/Integrations.cs b/Retailcrm/Versions/V5/Integrations.cs new file mode 100644 index 0000000..1c2c1e9 --- /dev/null +++ b/Retailcrm/Versions/V5/Integrations.cs @@ -0,0 +1,49 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response IntegrationsSettingGet(string code) + { + if (string.IsNullOrEmpty(code)) + { + throw new ArgumentException("Parameter `code` is mandatory"); + } + + return Request.MakeRequest( + $"/integration-modules/{code}", + Request.MethodGet + ); + } + + public Response IntegrationsSettingsEdit(Dictionary integrationModule) + { + if (integrationModule.Count < 1) + { + throw new ArgumentException("Parameter `integrationModule` must contain data"); + } + + if (!integrationModule.ContainsKey("code")) + { + throw new ArgumentException("Parameter `integrationModule` should contain `code`"); + } + + if (!integrationModule.ContainsKey("name")) + { + throw new ArgumentException("Parameter `integrationModule` should contain `name`"); + } + + return Request.MakeRequest( + $"/integration-modules/{integrationModule["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "integrationModule", new JavaScriptSerializer().Serialize(integrationModule) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V5/Notes.cs b/Retailcrm/Versions/V5/Notes.cs new file mode 100644 index 0000000..c3d81e5 --- /dev/null +++ b/Retailcrm/Versions/V5/Notes.cs @@ -0,0 +1,59 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response NotesCreate(Dictionary note, string site = "") + { + if (note.Count < 1) + { + throw new ArgumentException("Parameter `note` must contains a data"); + } + + return Request.MakeRequest( + "/customers/notes/create", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "note", new JavaScriptSerializer().Serialize(note) } + } + ) + ); + } + + public Response NotesDelete(string id) + { + return Request.MakeRequest( + $"/customers/notes/{id}/delete", + Request.MethodPost + ); + } + + public Response NotesList(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/customers/notes", Request.MethodGet, parameters); + } + } +} diff --git a/Retailcrm/Versions/V5/Payments.cs b/Retailcrm/Versions/V5/Payments.cs new file mode 100644 index 0000000..21aae8e --- /dev/null +++ b/Retailcrm/Versions/V5/Payments.cs @@ -0,0 +1,67 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response PaymentsCreate(Dictionary payment, string site = "") + { + if (payment.Count < 1) + { + throw new ArgumentException("Parameter `payment` must contains a data"); + } + + return Request.MakeRequest( + "/orders/payments/create", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "payment", new JavaScriptSerializer().Serialize(payment) } + } + ) + ); + } + + public Response PaymentsUpdate(Dictionary payment, string by = "id", string site = "") + { + if (payment.Count < 1) + { + throw new ArgumentException("Parameter `payment` must contains a data"); + } + + if (!payment.ContainsKey("id") && !payment.ContainsKey("externalId")) + { + throw new ArgumentException("Parameter `payment` must contains an id or externalId"); + } + + CheckIdParameter(by); + + string uid = by == "externalId" ? payment["externalId"].ToString() : payment["id"].ToString(); + + return Request.MakeRequest( + $"/orders/payments/{uid}/edit", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "by", by }, + { "payment", new JavaScriptSerializer().Serialize(payment) } + } + ) + ); + } + + public Response PaymentsDelete(string id) + { + return Request.MakeRequest( + $"/orders/payments/{id}/delete", + Request.MethodPost + ); + } + } +} diff --git a/Retailcrm/Versions/V5/References.cs b/Retailcrm/Versions/V5/References.cs new file mode 100644 index 0000000..d271c16 --- /dev/null +++ b/Retailcrm/Versions/V5/References.cs @@ -0,0 +1,115 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response CostGroups() + { + return Request.MakeRequest( + "/reference/cost-groups", + Request.MethodGet + ); + } + + public Response CostItems() + { + return Request.MakeRequest( + "/reference/cost-items", + Request.MethodGet + ); + } + + public Response LegalEntities() + { + return Request.MakeRequest( + "/reference/legal-entities", + Request.MethodGet + ); + } + + public Response CostGroupsEdit(Dictionary group) + { + if (!group.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!group.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + if (!group.ContainsKey("color")) + { + throw new ArgumentException("Parameter `color` is missing"); + } + + return Request.MakeRequest( + $"/reference/cost-groups/{group["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "costGroup", new JavaScriptSerializer().Serialize(group) } + } + ); + } + + public Response CostItemsEdit(Dictionary item) + { + if (!item.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!item.ContainsKey("name")) + { + throw new ArgumentException("Parameter `name` is missing"); + } + + List types = new List + { + "const", + "var" + }; + + if (item.ContainsKey("type") && !types.Contains(item["type"].ToString())) + { + throw new ArgumentException("Parameter `type` should be one of `const|var`"); + } + + return Request.MakeRequest( + $"/reference/cost-items/{item["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "costItem", new JavaScriptSerializer().Serialize(item) } + } + ); + } + + public Response LegalEntitiesEdit(Dictionary entity) + { + if (!entity.ContainsKey("code")) + { + throw new ArgumentException("Parameter `code` is missing"); + } + + if (!entity.ContainsKey("legalName")) + { + throw new ArgumentException("Parameter `legalName` is missing"); + } + + return Request.MakeRequest( + $"/reference/legal-entities/{entity["code"].ToString()}/edit", + Request.MethodPost, + new Dictionary + { + { "legalEntity", new JavaScriptSerializer().Serialize(entity) } + } + ); + } + } +} diff --git a/Retailcrm/Versions/V5/Segments.cs b/Retailcrm/Versions/V5/Segments.cs new file mode 100644 index 0000000..6e8eea8 --- /dev/null +++ b/Retailcrm/Versions/V5/Segments.cs @@ -0,0 +1,30 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + + public partial class Client + { + public Response Segments(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/segments", Request.MethodGet, parameters); + } + } +} diff --git a/Retailcrm/Versions/V5/Stores.cs b/Retailcrm/Versions/V5/Stores.cs new file mode 100644 index 0000000..e5499c4 --- /dev/null +++ b/Retailcrm/Versions/V5/Stores.cs @@ -0,0 +1,62 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + + public partial class Client + { + public new Response StoreSettingGet(string code) + { + throw new ArgumentException("This method is unavailable in API V5", code); + } + + public new Response StoreSettingsEdit(Dictionary configuration) + { + throw new ArgumentException("This method is unavailable in API V5"); + } + + public Response StoreProductsGroups(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/store/products-groups", Request.MethodGet, parameters); + } + + public Response StoreProductsProperties(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/store/products/properties", Request.MethodGet, parameters); + } + } +} diff --git a/Retailcrm/Versions/V5/Tasks.cs b/Retailcrm/Versions/V5/Tasks.cs new file mode 100644 index 0000000..a0c1a3d --- /dev/null +++ b/Retailcrm/Versions/V5/Tasks.cs @@ -0,0 +1,84 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + using System.Web.Script.Serialization; + + public partial class Client + { + public Response TasksCreate(Dictionary task, string site = "") + { + if (task.Count < 1) + { + throw new ArgumentException("Parameter `task` must contains a data"); + } + + return Request.MakeRequest( + "/tasks/create", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "task", new JavaScriptSerializer().Serialize(task) } + } + ) + ); + } + + public Response TasksUpdate(Dictionary task, string site = "") + { + if (task.Count < 1) + { + throw new ArgumentException("Parameter `task` must contains a data"); + } + + if (!task.ContainsKey("id")) + { + throw new ArgumentException("Parameter `task` must contains an id"); + } + + return Request.MakeRequest( + $"/tasks/{task["id"].ToString()}/edit", + Request.MethodPost, + FillSite( + site, + new Dictionary + { + { "task", new JavaScriptSerializer().Serialize(task) } + } + ) + ); + } + + public Response TasksGet(string id) + { + return Request.MakeRequest( + $"/tasks/{id}", + Request.MethodGet + ); + } + + public Response TasksList(Dictionary filter = null, int page = 0, int limit = 0) + { + Dictionary parameters = new Dictionary(); + + if (filter != null && filter.Count > 0) + { + parameters.Add("filter", filter); + } + + if (page > 0) + { + parameters.Add("page", page); + } + + if (limit > 0) + { + parameters.Add("limit", limit); + } + + return Request.MakeRequest("/tasks", Request.MethodGet, parameters); + } + } +} diff --git a/Retailcrm/Versions/V5/Users.cs b/Retailcrm/Versions/V5/Users.cs new file mode 100644 index 0000000..831bf12 --- /dev/null +++ b/Retailcrm/Versions/V5/Users.cs @@ -0,0 +1,27 @@ +namespace Retailcrm.Versions.V5 +{ + using System; + using System.Collections.Generic; + + public partial class Client + { + public Response UsersStatus(int id, string status) + { + List statuses = new List { "free", "busy", "dinner", "break"}; + + if (!statuses.Contains(status)) + { + throw new ArgumentException("Parameter `status` must be equal one of these values: `free|busy|dinner|break`"); + } + + return Request.MakeRequest( + $"/users/{id}/status", + Request.MethodPost, + new Dictionary + { + { "status", status } + } + ); + } + } +} diff --git a/RetailcrmUnitTest/RetailcrmUnitTest.csproj b/RetailcrmUnitTest/RetailcrmUnitTest.csproj index caafbaf..1de723e 100644 --- a/RetailcrmUnitTest/RetailcrmUnitTest.csproj +++ b/RetailcrmUnitTest/RetailcrmUnitTest.csproj @@ -60,7 +60,9 @@ + + diff --git a/RetailcrmUnitTest/V3/PacksTest.cs b/RetailcrmUnitTest/V3/PacksTest.cs index 8f3aa0d..1dacf8f 100644 --- a/RetailcrmUnitTest/V3/PacksTest.cs +++ b/RetailcrmUnitTest/V3/PacksTest.cs @@ -135,7 +135,7 @@ namespace RetailcrmUnitTest.V3 Assert.IsInstanceOfType(packsGetResponse, typeof(Response)); Assert.IsTrue(packsGetResponse.GetResponse().ContainsKey("pack")); - Response packsDeleteResponse = _client.PacksGet(packId); + Response packsDeleteResponse = _client.PacksDelete(packId); Assert.IsTrue(packsDeleteResponse.IsSuccessfull()); Assert.IsTrue(packsDeleteResponse.GetStatusCode() == 200); @@ -167,12 +167,40 @@ namespace RetailcrmUnitTest.V3 { "endDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} }; - Response response = _client.PacksHistory(filter, 1, 100); + Response response = _client.PacksHistory(filter, 2, 100); Assert.IsTrue(response.IsSuccessfull()); Assert.IsTrue(response.GetStatusCode() == 200); Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("history")); } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "Parameter `pack` must contains a data")] + public void PacksCreateArgumentExeption() + { + Dictionary pack = new Dictionary(); + _client.PacksCreate(pack); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "Parameter `pack` must contains a data")] + public void PacksUpdateArgumentExeption() + { + Dictionary pack = new Dictionary(); + _client.PacksUpdate(pack); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "Parameter `pack` must contains an id")] + public void PacksUpdateWithoutIdArgumentExeption() + { + Dictionary pack = new Dictionary + { + { "quantity", 2 } + }; + + _client.PacksUpdate(pack); + } } } diff --git a/RetailcrmUnitTest/V3/StoresTest.cs b/RetailcrmUnitTest/V3/StoresTest.cs index 2734139..92e0b56 100644 --- a/RetailcrmUnitTest/V3/StoresTest.cs +++ b/RetailcrmUnitTest/V3/StoresTest.cs @@ -1,6 +1,4 @@ -using System.Diagnostics; - -namespace RetailcrmUnitTest.V3 +namespace RetailcrmUnitTest.V3 { using System; using System.Collections.Generic; @@ -77,8 +75,6 @@ namespace RetailcrmUnitTest.V3 Assert.IsTrue(response.GetStatusCode() == 200); Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("processedOffersCount")); - - Debug.WriteLine(response.GetRawResponse()); } [TestMethod] @@ -96,8 +92,43 @@ namespace RetailcrmUnitTest.V3 Assert.IsTrue(response.GetStatusCode() == 200); Assert.IsInstanceOfType(response, typeof(Response)); Assert.IsTrue(response.GetResponse().ContainsKey("offers")); + } - Debug.WriteLine(response.GetRawResponse()); + [TestMethod] + [ExpectedException(typeof(ArgumentException), "Parameter `offers` must contains a data")] + public void StoreInventoriesUploadArgumentExeption() + { + List offers = new List(); + _client.StoreInventoriesUpload(offers); + } + + [TestMethod] + [ExpectedException(typeof(ArgumentException), "Parameter `offers` must contain 250 or less records")] + public void StoreInventoriesUploadLimitArgumentExeption() + { + List offers = new List(); + + for (int i = 0; i < 300; i++) + { + offers.Add( + new Dictionary + { + { "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}, + { "stores", new List + { + new Dictionary + { + { "code", _appSettings["store"] }, + { "available", 700 }, + { "purchasePrice", 400} + } + } + } + } + ); + } + + _client.StoreInventoriesUpload(offers); } } } diff --git a/RetailcrmUnitTest/V4/ReferencesTest.cs b/RetailcrmUnitTest/V4/ReferencesTest.cs new file mode 100644 index 0000000..a31b8fb --- /dev/null +++ b/RetailcrmUnitTest/V4/ReferencesTest.cs @@ -0,0 +1,33 @@ +namespace RetailcrmUnitTest.V4 +{ + using System; + using System.Collections.Specialized; + using System.Configuration; + using System.Collections.Generic; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Retailcrm; + using Retailcrm.Versions.V4; + + [TestClass] + public class ReferencesTest + { + private readonly Client _client; + + public ReferencesTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void PriceTypes() + { + Response response = _client.PriceTypes(); + + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("priceTypes")); + } + } +} diff --git a/RetailcrmUnitTest/V5/ReferencesTest.cs b/RetailcrmUnitTest/V5/ReferencesTest.cs new file mode 100644 index 0000000..40d1f47 --- /dev/null +++ b/RetailcrmUnitTest/V5/ReferencesTest.cs @@ -0,0 +1,32 @@ +namespace RetailcrmUnitTest.V5 +{ + using System; + using System.Collections.Specialized; + using System.Configuration; + using System.Collections.Generic; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using Retailcrm; + using Retailcrm.Versions.V5; + + [TestClass] + public class ReferencesTest + { + private readonly Client _client; + + public ReferencesTest() + { + NameValueCollection appSettings = ConfigurationManager.AppSettings; + _client = new Client(appSettings["apiUrl"], appSettings["apiKey"]); + } + + [TestMethod] + public void CostGroups() + { + Response response = _client.CostGroups(); + Assert.IsTrue(response.IsSuccessfull()); + Assert.IsTrue(response.GetStatusCode() == 200); + Assert.IsInstanceOfType(response, typeof(Response)); + Assert.IsTrue(response.GetResponse().ContainsKey("costGroups")); + } + } +}