V4 & V5 Methods (without telephony & customFields)

This commit is contained in:
Alex Lushpai 2017-10-09 17:56:16 +03:00
parent b39d295f3a
commit 537efb13f6
24 changed files with 1482 additions and 21 deletions

View file

@ -55,9 +55,25 @@
<Compile Include="Versions\V3\Packs.cs" />
<Compile Include="Versions\V3\Stores.cs" />
<Compile Include="Versions\V4\Client.cs" />
<Compile Include="Versions\V4\Customers.cs" />
<Compile Include="Versions\V4\Delivery.cs" />
<Compile Include="Versions\V4\Marketplace.cs" />
<Compile Include="Versions\V4\Orders.cs" />
<Compile Include="Versions\V4\References.cs" />
<Compile Include="Versions\V4\Stores.cs" />
<Compile Include="Versions\V4\Users.cs" />
<Compile Include="Versions\V5\Client.cs" />
<Compile Include="Versions\V5\Costs.cs" />
<Compile Include="Versions\V5\Delivery.cs" />
<Compile Include="Versions\V5\Integrations.cs" />
<Compile Include="Versions\V5\Notes.cs" />
<Compile Include="Versions\V5\Orders.cs" />
<Compile Include="Versions\V5\Payments.cs" />
<Compile Include="Versions\V5\References.cs" />
<Compile Include="Versions\V5\Segments.cs" />
<Compile Include="Versions\V5\Stores.cs" />
<Compile Include="Versions\V5\Tasks.cs" />
<Compile Include="Versions\V5\Users.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View file

@ -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

View file

@ -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<string, object> 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<string, object>
{
{ "deliveryService", new JavaScriptSerializer().Serialize(service) }
}
);
}
public Response DeliveryTypesEdit(Dictionary<string, object> 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<string, object>
{
{ "deliveryType", new JavaScriptSerializer().Serialize(type) }
}
);
}
public Response OrderMethodsEdit(Dictionary<string, object> 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<string, object>
{
{ "orderMethod", new JavaScriptSerializer().Serialize(method) }
}
);
}
public Response OrderTypesEdit(Dictionary<string, object> 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<string, object>
{
{ "orderType", new JavaScriptSerializer().Serialize(type) }
}
);
}
public Response PaymentStatusesEdit(Dictionary<string, object> 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<string, object>
{
{ "paymentStatus", new JavaScriptSerializer().Serialize(status) }
}
);
}
public Response PaymentTypesEdit(Dictionary<string, object> 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<string, object>
{
{ "paymentType", new JavaScriptSerializer().Serialize(type) }
}
);
}
public Response ProductStatusesEdit(Dictionary<string, object> 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<string, object>
{
{ "productStatus", new JavaScriptSerializer().Serialize(status) }
}
);
}
public Response SitesEdit(Dictionary<string, object> 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<string, object>
{
{ "site", new JavaScriptSerializer().Serialize(site) }
}
);
}
public Response StatusesEdit(Dictionary<string, object> 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<string, object>
{
{ "status", new JavaScriptSerializer().Serialize(status) }
}
);
}
public Response StoresEdit(Dictionary<string, object> store)
{
if (!store.ContainsKey("code"))
{
throw new ArgumentException("Parameter `code` is missing");
}
if (!store.ContainsKey("name"))
{
throw new ArgumentException("Parameter `name` is missing");
}
List<string> types = new List<string>
{
"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<string, object>
{
{ "store", new JavaScriptSerializer().Serialize(store) }
}
);
}
}
}

View file

@ -0,0 +1,29 @@
namespace Retailcrm.Versions.V4
{
using System.Collections.Generic;
public partial class Client
{
public Response CustomersHistory(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "configuration", new JavaScriptSerializer().Serialize(configuration) }
}
);
}
public Response DeliveryTracking(string code, List<object> 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<string, object>
{
{ "statusUpdate", new JavaScriptSerializer().Serialize(statusUpdate) }
}
);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "configuration", new JavaScriptSerializer().Serialize(configuration) }
}
);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "priceType", new JavaScriptSerializer().Serialize(type) }
}
);
}
}
}

View file

@ -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<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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<object> 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<string, object>
{
{ "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<string, object> 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<string, object>
{
{ "configuration", new JavaScriptSerializer().Serialize(configuration) }
}
);
}
}
}

View file

@ -0,0 +1,51 @@
namespace Retailcrm.Versions.V4
{
using System.Collections.Generic;
public partial class Client
{
public Response Users(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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<string, object> 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<string, object>
{
{ "cost", new JavaScriptSerializer().Serialize(cost) }
}
)
);
}
public Response CostsDelete(List<string> ids)
{
if (ids.Count < 1)
{
throw new ArgumentException("Parameter `ids` must contains a data");
}
return Request.MakeRequest(
"/costs/delete",
Request.MethodPost,
new Dictionary<string, object>
{
{ "ids", new JavaScriptSerializer().Serialize(ids) }
}
);
}
public Response CostsUpload(List<object> costs)
{
if (costs.Count < 1)
{
throw new ArgumentException("Parameter `costs` must contains a data");
}
return Request.MakeRequest(
"/costs/upload",
Request.MethodPost,
new Dictionary<string, object>
{
{ "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<string, object> 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<string, object>
{
{ "cost", new JavaScriptSerializer().Serialize(cost) }
}
)
);
}
}
}

View file

@ -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<string, object> configuration)
{
throw new ArgumentException("This method is unavailable in API V5");
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "integrationModule", new JavaScriptSerializer().Serialize(integrationModule) }
}
);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "note", new JavaScriptSerializer().Serialize(note) }
}
)
);
}
public Response NotesDelete(string id)
{
return Request.MakeRequest(
$"/customers/notes/{id}/delete",
Request.MethodPost
);
}
public Response NotesList(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "payment", new JavaScriptSerializer().Serialize(payment) }
}
)
);
}
public Response PaymentsUpdate(Dictionary<string, object> 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<string, object>
{
{ "by", by },
{ "payment", new JavaScriptSerializer().Serialize(payment) }
}
)
);
}
public Response PaymentsDelete(string id)
{
return Request.MakeRequest(
$"/orders/payments/{id}/delete",
Request.MethodPost
);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "costGroup", new JavaScriptSerializer().Serialize(group) }
}
);
}
public Response CostItemsEdit(Dictionary<string, object> item)
{
if (!item.ContainsKey("code"))
{
throw new ArgumentException("Parameter `code` is missing");
}
if (!item.ContainsKey("name"))
{
throw new ArgumentException("Parameter `name` is missing");
}
List<string> types = new List<string>
{
"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<string, object>
{
{ "costItem", new JavaScriptSerializer().Serialize(item) }
}
);
}
public Response LegalEntitiesEdit(Dictionary<string, object> 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<string, object>
{
{ "legalEntity", new JavaScriptSerializer().Serialize(entity) }
}
);
}
}
}

View file

@ -0,0 +1,30 @@
namespace Retailcrm.Versions.V5
{
using System;
using System.Collections.Generic;
public partial class Client
{
public Response Segments(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string, object> configuration)
{
throw new ArgumentException("This method is unavailable in API V5");
}
public Response StoreProductsGroups(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string, object> 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<string, object>
{
{ "task", new JavaScriptSerializer().Serialize(task) }
}
)
);
}
public Response TasksUpdate(Dictionary<string, object> 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<string, object>
{
{ "task", new JavaScriptSerializer().Serialize(task) }
}
)
);
}
public Response TasksGet(string id)
{
return Request.MakeRequest(
$"/tasks/{id}",
Request.MethodGet
);
}
public Response TasksList(Dictionary<string, object> filter = null, int page = 0, int limit = 0)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
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);
}
}
}

View file

@ -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<string> statuses = new List<string> { "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<string, object>
{
{ "status", status }
}
);
}
}
}

View file

@ -60,7 +60,9 @@
<Compile Include="V3\PacksTest.cs" />
<Compile Include="V3\StoresTest.cs" />
<Compile Include="V4\OrdersTest.cs" />
<Compile Include="V4\ReferencesTest.cs" />
<Compile Include="V5\OrdersTest.cs" />
<Compile Include="V5\ReferencesTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

View file

@ -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<string, object> pack = new Dictionary<string, object>();
_client.PacksCreate(pack);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException), "Parameter `pack` must contains a data")]
public void PacksUpdateArgumentExeption()
{
Dictionary<string, object> pack = new Dictionary<string, object>();
_client.PacksUpdate(pack);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException), "Parameter `pack` must contains an id")]
public void PacksUpdateWithoutIdArgumentExeption()
{
Dictionary<string, object> pack = new Dictionary<string, object>
{
{ "quantity", 2 }
};
_client.PacksUpdate(pack);
}
}
}

View file

@ -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<object> offers = new List<object>();
_client.StoreInventoriesUpload(offers);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException), "Parameter `offers` must contain 250 or less records")]
public void StoreInventoriesUploadLimitArgumentExeption()
{
List<object> offers = new List<object>();
for (int i = 0; i < 300; i++)
{
offers.Add(
new Dictionary<string, object>
{
{ "xmlId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
{ "stores", new List<object>
{
new Dictionary<string, object>
{
{ "code", _appSettings["store"] },
{ "available", 700 },
{ "purchasePrice", 400}
}
}
}
}
);
}
_client.StoreInventoriesUpload(offers);
}
}
}

View file

@ -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"));
}
}
}

View file

@ -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"));
}
}
}