mirror of
https://github.com/retailcrm/api-client-dotnet.git
synced 2024-11-21 20:36:02 +03:00
Multiversion client (#6)
* Multiversion sdk * Remove redundant code * More test coverage;
This commit is contained in:
parent
bdff2ffabe
commit
72cac6d6f0
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
###############################################################################
|
||||
# Set default behavior to automatically normalize line endings.
|
||||
###############################################################################
|
||||
* text=auto
|
||||
|
||||
###############################################################################
|
||||
# Set default behavior for command prompt diff.
|
||||
#
|
||||
# This is need for earlier builds of msysgit that does not have it on by
|
||||
# default for csharp files.
|
||||
# Note: This is only used by command line
|
||||
###############################################################################
|
||||
#*.cs diff=csharp
|
||||
|
||||
###############################################################################
|
||||
# Set the merge driver for project and solution files
|
||||
#
|
||||
# Merging from the command prompt will add diff markers to the files if there
|
||||
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||
# the diff markers are never inserted). Diff markers may cause the following
|
||||
# file extensions to fail to load in VS. An alternative would be to treat
|
||||
# these files as binary and thus will always conflict and require user
|
||||
# intervention with every merge. To do so, just uncomment the entries below
|
||||
###############################################################################
|
||||
#*.sln merge=binary
|
||||
#*.csproj merge=binary
|
||||
#*.vbproj merge=binary
|
||||
#*.vcxproj merge=binary
|
||||
#*.vcproj merge=binary
|
||||
#*.dbproj merge=binary
|
||||
#*.fsproj merge=binary
|
||||
#*.lsproj merge=binary
|
||||
#*.wixproj merge=binary
|
||||
#*.modelproj merge=binary
|
||||
#*.sqlproj merge=binary
|
||||
#*.wwaproj merge=binary
|
||||
|
||||
###############################################################################
|
||||
# behavior for image files
|
||||
#
|
||||
# image files are treated as binary by default.
|
||||
###############################################################################
|
||||
#*.jpg binary
|
||||
#*.png binary
|
||||
#*.gif binary
|
||||
|
||||
###############################################################################
|
||||
# diff behavior for common document formats
|
||||
#
|
||||
# Convert binary document formats to text before diffing them. This feature
|
||||
# is only available from the command line. Turn it on by uncommenting the
|
||||
# entries below.
|
||||
###############################################################################
|
||||
#*.doc diff=astextplain
|
||||
#*.DOC diff=astextplain
|
||||
#*.docx diff=astextplain
|
||||
#*.DOCX diff=astextplain
|
||||
#*.dot diff=astextplain
|
||||
#*.DOT diff=astextplain
|
||||
#*.pdf diff=astextplain
|
||||
#*.PDF diff=astextplain
|
||||
#*.rtf diff=astextplain
|
||||
#*.RTF diff=astextplain
|
106
.gitignore
vendored
106
.gitignore
vendored
@ -4,8 +4,14 @@
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
**/App.config
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
@ -13,19 +19,21 @@
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
build/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Roslyn cache directories
|
||||
*.ide/
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
#NUNIT
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
@ -34,6 +42,11 @@ TestResult.xml
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# DNX
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
@ -66,14 +79,18 @@ _Chutzpah*
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
@ -86,7 +103,7 @@ _ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding addin-in
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
@ -98,6 +115,7 @@ _TeamCity*
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
@ -127,37 +145,61 @@ publish/
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
#*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# If using the old MSBuild-Integrated Package Restore, uncomment this:
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Windows Azure Build Output
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Windows Store app package directory
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
sql/
|
||||
*.Cache
|
||||
ClientBin/
|
||||
[Ss]tyle[Cc]op.*
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
@ -181,3 +223,43 @@ UpgradeLog*.htm
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.nuspec
|
||||
*.nupkg
|
2
LICENSE
2
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
|
||||
|
157
README.md
157
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
|
||||
PM> Install-Package Retailcrm.SDK
|
||||
```
|
||||
|
||||
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<string, object> tmpOrder = new Dictionary<string, object>(){
|
||||
{"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<string, object>(){
|
||||
{"reciever_phone", "example"},
|
||||
{"reciever_name", "example"},
|
||||
{"ext_number", "example"}
|
||||
}
|
||||
},
|
||||
{"contragentType", "individual"},
|
||||
{"orderType", "eshop-individual"},
|
||||
{"orderMethod", "app"},
|
||||
{"customerId", "555"},
|
||||
{"managerId", 8},
|
||||
{"items", new Dictionary<string, object>(){
|
||||
{"0", new Dictionary<string, object>(){
|
||||
{"initialPrice", 100},
|
||||
{"quantity", 1},
|
||||
{"productId", 55},
|
||||
{"productName", "example"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"delivery", new Dictionary<string, object>(){
|
||||
{"code", "courier"},
|
||||
{"date", DateTime.Now.ToString("Y-m-d")},
|
||||
{"address", new Dictionary<string, object>(){
|
||||
{"text", "example"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ApiResponse response = null;
|
||||
try
|
||||
Client api = new Client("https://demo.retailcrm.ru", "T9DMPvuNt7FQJMszHUdG8Fkt6xHsqngH");
|
||||
Response response = api.OrdersCreate(new Dictionary<string, object>
|
||||
{
|
||||
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<object> {
|
||||
new Dictionary<string, object> {
|
||||
{"initialPrice", 100},
|
||||
{"quantity", 1},
|
||||
{"productId", 55},
|
||||
{"productName", "example"}
|
||||
},
|
||||
new Dictionary<string, object> {
|
||||
{"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()}]");
|
||||
}
|
||||
|
||||
```
|
||||
|
142
README.ru.md
142
README.ru.md
@ -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<string, object> tmpOrder = new Dictionary<string, object>(){
|
||||
{"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<string, object>(){
|
||||
{"reciever_phone", "example"},
|
||||
{"reciever_name", "example"},
|
||||
{"ext_number", "example"}
|
||||
}
|
||||
},
|
||||
{"contragentType", "individual"},
|
||||
{"orderType", "eshop-individual"},
|
||||
{"orderMethod", "app"},
|
||||
{"customerId", "555"},
|
||||
{"managerId", 8},
|
||||
{"items", new Dictionary<string, object>(){
|
||||
{"0", new Dictionary<string, object>(){
|
||||
{"initialPrice", 100},
|
||||
{"quantity", 1},
|
||||
{"productId", 55},
|
||||
{"productName", "example"}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{"delivery", new Dictionary<string, object>(){
|
||||
{"code", "courier"},
|
||||
{"date", DateTime.Now.ToString("Y-m-d")},
|
||||
{"address", new Dictionary<string, object>(){
|
||||
{"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"]
|
||||
);
|
||||
}
|
||||
|
||||
```
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace RetailCrm.Exceptions
|
||||
{
|
||||
public class InvalidJsonException : Exception
|
||||
{
|
||||
public InvalidJsonException()
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidJsonException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public InvalidJsonException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RetailCrm.Extra
|
||||
{
|
||||
class Tools
|
||||
{
|
||||
public static string httpBuildQuery(Dictionary<string, object> data)
|
||||
{
|
||||
if (data is Dictionary<string, object> == false)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
var parts = new List<string>();
|
||||
HandleItem(data, parts);
|
||||
return String.Join("&", parts);
|
||||
}
|
||||
|
||||
private static void HandleItem(object data, List<string> parts, string prefix = "")
|
||||
{
|
||||
if (data == null) return;
|
||||
|
||||
if (data is Dictionary<string, object>)
|
||||
{
|
||||
parts.Add(FormatDictionary((Dictionary<string, object>)data, prefix));
|
||||
}
|
||||
else
|
||||
{
|
||||
parts.Add(String.IsNullOrEmpty(data.ToString()) ? String.Empty : String.Format("{0}={1}", prefix, data.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatDictionary(Dictionary<string, object> obj, string prefix = "")
|
||||
{
|
||||
var parts = new List<string>();
|
||||
foreach (KeyValuePair<string, object> kvp in obj)
|
||||
{
|
||||
string newPrefix = string.IsNullOrEmpty(prefix) ?
|
||||
String.Format("{0}{1}", prefix, kvp.Key) :
|
||||
String.Format("{0}[{1}]", prefix, kvp.Key);
|
||||
HandleItem(kvp.Value, parts, newPrefix);
|
||||
}
|
||||
|
||||
return String.Join("&", parts);
|
||||
}
|
||||
|
||||
public static Dictionary<string, object> jsonDecode(string json)
|
||||
{
|
||||
return jsonObjectToDictionary((Dictionary<string, object>)JsonConvert.DeserializeObject<Dictionary<string, object>>(json));
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> jsonObjectToDictionary(Dictionary<string, object> data)
|
||||
{
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
foreach (KeyValuePair<string, object> kvp in data)
|
||||
{
|
||||
object valueObj = kvp.Value;
|
||||
string value = String.Empty;
|
||||
|
||||
value = valueObj.ToString();
|
||||
|
||||
if (value != "")
|
||||
{
|
||||
if (valueObj.GetType() == typeof(JObject))
|
||||
{
|
||||
valueObj = jsonObjectToDictionary((Dictionary<string, object>)JsonConvert.DeserializeObject<Dictionary<string, object>>(value));
|
||||
result.Add(kvp.Key.ToString(), valueObj);
|
||||
}
|
||||
else if (valueObj.GetType() == typeof(JArray))
|
||||
{
|
||||
var items = new List<object>();
|
||||
|
||||
dynamic dynamicObject = JsonConvert.DeserializeObject(value);
|
||||
Dictionary<string, object> newObject = new Dictionary<string, object>();
|
||||
|
||||
int j = 0;
|
||||
foreach (var item in dynamicObject)
|
||||
{
|
||||
newObject.Add(j.ToString(), jsonObjectToDictionary(item.ToObject<Dictionary<string, object>>()));
|
||||
j++;
|
||||
}
|
||||
|
||||
result.Add(kvp.Key.ToString(), newObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(kvp.Key.ToString(), valueObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
using RetailCrm.Extra;
|
||||
using RetailCrm.Response;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RetailCrm.Http
|
||||
{
|
||||
/// <summary>
|
||||
/// HTTP client
|
||||
/// </summary>
|
||||
public class Client
|
||||
{
|
||||
public const string METHOD_GET = "GET";
|
||||
public const string METHOD_POST = "POST";
|
||||
private const string USER_AGENT = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
|
||||
private const string CONTENT_TYPE = "application/x-www-form-urlencoded";
|
||||
|
||||
protected string url;
|
||||
protected Dictionary<string, object> defaultParameter;
|
||||
|
||||
/// <summary>
|
||||
/// Creating HTTP client
|
||||
/// </summary>
|
||||
/// <param name="apiUrl"></param>
|
||||
/// <param name="parameters"></param>
|
||||
public Client(string apiUrl, Dictionary<string, object> parameters = null)
|
||||
{
|
||||
if (apiUrl.IndexOf("https://") == -1)
|
||||
{
|
||||
throw new ArgumentException("API schema requires HTTPS protocol");
|
||||
}
|
||||
|
||||
url = apiUrl;
|
||||
defaultParameter = parameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make HTTP request
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="timeout"></param>
|
||||
/// <returns></returns>
|
||||
public ApiResponse makeRequest(string path, string method, Dictionary<string, object> parameters = null, int timeout = 30)
|
||||
{
|
||||
string[] allowedMethods = new string[] { METHOD_GET, METHOD_POST };
|
||||
if (allowedMethods.Contains(method) == false)
|
||||
{
|
||||
throw new ArgumentException("Method \"" + method + "\" is not valid. Allowed methods are " + String.Join(", ", allowedMethods));
|
||||
}
|
||||
if (parameters == null) {
|
||||
parameters = new Dictionary<string, object>();
|
||||
}
|
||||
parameters = defaultParameter.Union(parameters).ToDictionary(k => k.Key, v => v.Value);
|
||||
path = url + path;
|
||||
string httpQuery = Tools.httpBuildQuery(parameters);
|
||||
|
||||
if (method.Equals(METHOD_GET) && parameters.Count > 0)
|
||||
{
|
||||
path += "?" + httpQuery;
|
||||
}
|
||||
|
||||
Exception exception = null;
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(path);
|
||||
request.Method = method;
|
||||
|
||||
if (method.Equals(METHOD_POST))
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
byte[] bytes = encoding.GetBytes(httpQuery);
|
||||
request.ContentLength = bytes.Length;
|
||||
request.ContentType = CONTENT_TYPE;
|
||||
request.UserAgent = USER_AGENT;
|
||||
|
||||
Stream post = request.GetRequestStream();
|
||||
post.Write(bytes, 0, bytes.Length);
|
||||
post.Flush();
|
||||
post.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
exception = ex;
|
||||
}
|
||||
|
||||
if (request == null || response == null)
|
||||
{
|
||||
throw new WebException(exception.ToString(), exception);
|
||||
}
|
||||
|
||||
StreamReader reader = new StreamReader((Stream) response.GetResponseStream());
|
||||
string responseBody = reader.ReadToEnd();
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
return new ApiResponse(statusCode, responseBody);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using RetailCrm.Exceptions;
|
||||
using RetailCrm.Extra;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RetailCrm.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Response from retailCRM API
|
||||
/// </summary>
|
||||
public class ApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// HTTP response status code
|
||||
/// </summary>
|
||||
protected int statusCode;
|
||||
|
||||
/// <summary>
|
||||
/// Response
|
||||
/// </summary>
|
||||
protected Dictionary<string, object> response;
|
||||
|
||||
/// <summary>
|
||||
/// Creating ApiResponse
|
||||
/// </summary>
|
||||
/// <param name="statusCode"></param>
|
||||
/// <param name="responseBody"></param>
|
||||
public ApiResponse(int statusCode, string responseBody = null)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
|
||||
if (responseBody != null && responseBody.Length > 0)
|
||||
{
|
||||
Dictionary<string, object> response = new Dictionary<string, object>();
|
||||
try
|
||||
{
|
||||
response = Tools.jsonDecode(responseBody);
|
||||
}
|
||||
catch (JsonReaderException e)
|
||||
{
|
||||
throw new InvalidJsonException("Invalid JSON in the API response body. " + e.ToString());
|
||||
}
|
||||
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return HTTP response status code
|
||||
/// </summary>
|
||||
/// <returns>int</returns>
|
||||
public int getStatusCode()
|
||||
{
|
||||
return this.statusCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HTTP request was successful
|
||||
/// </summary>
|
||||
/// <returns>boolean</returns>
|
||||
public bool isSuccessful()
|
||||
{
|
||||
return this.statusCode < 400;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return response
|
||||
/// </summary>
|
||||
/// <returns>Dictionary</returns>
|
||||
public object this[string code]
|
||||
{
|
||||
get {
|
||||
if (this.response.ContainsKey(code))
|
||||
{
|
||||
return this.response[code];
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Dictionary<string, object>();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new ArgumentException("Property \"" + code + "\" is not writable");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
34
Retailcrm.sln
Normal file
34
Retailcrm.sln
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Retailcrm", "Retailcrm\Retailcrm.csproj", "{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RetailcrmUnitTest", "RetailcrmUnitTest\RetailcrmUnitTest.csproj", "{4069C2BC-C277-48A3-96AE-DA5934A75F4D}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41} = {9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4069C2BC-C277-48A3-96AE-DA5934A75F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4069C2BC-C277-48A3-96AE-DA5934A75F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4069C2BC-C277-48A3-96AE-DA5934A75F4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4069C2BC-C277-48A3-96AE-DA5934A75F4D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7EB29423-9A10-4953-B3E8-563908B2D206}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
53
Retailcrm/Connection.cs
Normal file
53
Retailcrm/Connection.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm
|
||||
{
|
||||
/// <summary>
|
||||
/// Unversioned API Client
|
||||
/// </summary>
|
||||
public class Connection
|
||||
{
|
||||
private readonly Request _request;
|
||||
|
||||
/// <summary>
|
||||
/// Unversioned API Client Constructor
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="key"></param>
|
||||
public Connection(string url, string key)
|
||||
{
|
||||
if ("/" != url.Substring(url.Length - 1, 1))
|
||||
{
|
||||
url += "/";
|
||||
}
|
||||
|
||||
url += "api/";
|
||||
|
||||
_request = new Request(url, new Dictionary<string, object> { { "apiKey", key } });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get available API versions
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Versions()
|
||||
{
|
||||
return _request.MakeRequest(
|
||||
"api-versions",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get available API methods
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Credentials()
|
||||
{
|
||||
return _request.MakeRequest(
|
||||
"credentials",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
35
Retailcrm/Properties/AssemblyInfo.cs
Normal file
35
Retailcrm/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Общие сведения об этой сборке предоставляются следующим набором
|
||||
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
|
||||
// связанные со сборкой.
|
||||
[assembly: AssemblyTitle("Retailcrm.SDK")]
|
||||
[assembly: AssemblyDescription("Multiversion API client for RetailCRM")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("RetailDriver LLC")]
|
||||
[assembly: AssemblyProduct("Retailcrm.SDK")]
|
||||
[assembly: AssemblyCopyright("Copyright © RetailDriver LLC 2017")]
|
||||
[assembly: AssemblyTrademark("RetailDriver LLC")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
|
||||
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
|
||||
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
|
||||
[assembly: ComVisible(true)]
|
||||
|
||||
// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
|
||||
[assembly: Guid("9c378ef4-9f9b-4214-a9aa-1fc3c44edb41")]
|
||||
|
||||
// Сведения о версии сборки состоят из следующих четырех значений:
|
||||
//
|
||||
// Основной номер версии
|
||||
// Дополнительный номер версии
|
||||
// Номер сборки
|
||||
// Редакция
|
||||
//
|
||||
// Можно задать все значения или принять номер сборки и номер редакции по умолчанию.
|
||||
// используя "*", как показано ниже:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("5.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("5.0.0.0")]
|
156
Retailcrm/QueryBuilder.cs
Normal file
156
Retailcrm/QueryBuilder.cs
Normal file
@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Retailcrm
|
||||
{
|
||||
/// <summary>
|
||||
/// QueryBuilder
|
||||
/// </summary>
|
||||
public class QueryBuilder
|
||||
{
|
||||
private readonly List<KeyValuePair<string, object>> _keyValuePairs
|
||||
= new List<KeyValuePair<string, object>>();
|
||||
|
||||
/// <summary>
|
||||
/// Build PHP like query string
|
||||
/// </summary>
|
||||
/// <param name="queryData"></param>
|
||||
/// <param name="argSeperator"></param>
|
||||
/// <returns></returns>
|
||||
public static string BuildQueryString(object queryData, string argSeperator = "&")
|
||||
{
|
||||
var encoder = new QueryBuilder();
|
||||
encoder.AddEntry(null, queryData, allowObjects: true);
|
||||
|
||||
return encoder.GetUriString(argSeperator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetUriString
|
||||
/// </summary>
|
||||
/// <param name="argSeperator"></param>
|
||||
/// <returns></returns>
|
||||
private string GetUriString(string argSeperator)
|
||||
{
|
||||
return String.Join(argSeperator,
|
||||
_keyValuePairs.Select(kvp =>
|
||||
{
|
||||
var key = Uri.EscapeDataString(kvp.Key);
|
||||
var value = Uri.EscapeDataString(kvp.Value.ToString());
|
||||
return $"{key}={value}";
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AddEntry
|
||||
/// </summary>
|
||||
/// <param name="prefix"></param>
|
||||
/// <param name="instance"></param>
|
||||
/// <param name="allowObjects"></param>
|
||||
private void AddEntry(string prefix, object instance, bool allowObjects)
|
||||
{
|
||||
var dictionary = instance as IDictionary;
|
||||
var collection = instance as ICollection;
|
||||
|
||||
if (dictionary != null)
|
||||
{
|
||||
Add(prefix, GetDictionaryAdapter(dictionary));
|
||||
}
|
||||
else if (collection != null)
|
||||
{
|
||||
Add(prefix, GetArrayAdapter(collection));
|
||||
}
|
||||
else if (allowObjects)
|
||||
{
|
||||
Add(prefix, GetObjectAdapter(instance));
|
||||
}
|
||||
else
|
||||
{
|
||||
_keyValuePairs.Add(new KeyValuePair<string, object>(prefix, instance));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add
|
||||
/// </summary>
|
||||
/// <param name="prefix"></param>
|
||||
/// <param name="datas"></param>
|
||||
private void Add(string prefix, IEnumerable<Entry> datas)
|
||||
{
|
||||
foreach (var item in datas)
|
||||
{
|
||||
var newPrefix = String.IsNullOrEmpty(prefix)
|
||||
? item.Key
|
||||
: $"{prefix}[{item.Key}]";
|
||||
|
||||
AddEntry(newPrefix, item.Value, allowObjects: false);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry
|
||||
/// </summary>
|
||||
private struct Entry
|
||||
{
|
||||
public string Key;
|
||||
public object Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetObjectAdapter
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<Entry> GetObjectAdapter(object data)
|
||||
{
|
||||
var properties = data.GetType().GetProperties();
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
yield return new Entry
|
||||
{
|
||||
Key = property.Name,
|
||||
Value = property.GetValue(data)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetArrayAdapter
|
||||
/// </summary>
|
||||
/// <param name="collection"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<Entry> GetArrayAdapter(ICollection collection)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (var item in collection)
|
||||
{
|
||||
yield return new Entry
|
||||
{
|
||||
Key = i.ToString(),
|
||||
Value = item
|
||||
};
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetDictionaryAdapter
|
||||
/// </summary>
|
||||
/// <param name="collection"></param>
|
||||
/// <returns></returns>
|
||||
private IEnumerable<Entry> GetDictionaryAdapter(IDictionary collection)
|
||||
{
|
||||
foreach (DictionaryEntry item in collection)
|
||||
{
|
||||
yield return new Entry
|
||||
{
|
||||
Key = item.Key.ToString(),
|
||||
Value = item.Value
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
123
Retailcrm/Request.cs
Normal file
123
Retailcrm/Request.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace Retailcrm
|
||||
{
|
||||
/// <summary>
|
||||
/// Request
|
||||
/// </summary>
|
||||
public class Request
|
||||
{
|
||||
/// <summary>
|
||||
/// Get method
|
||||
/// </summary>
|
||||
public const string MethodGet = "GET";
|
||||
/// <summary>
|
||||
/// Post method
|
||||
/// </summary>
|
||||
public const string MethodPost = "POST";
|
||||
private const string UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
|
||||
private const string ContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
private readonly string _url;
|
||||
private readonly Dictionary<string, object> _defaultParameters;
|
||||
|
||||
/// <summary>
|
||||
/// Request constructor
|
||||
/// </summary>
|
||||
/// <param name="apiUrl"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public Request(string apiUrl, Dictionary<string, object> parameters = null)
|
||||
{
|
||||
if (apiUrl.IndexOf("https://", StringComparison.Ordinal) == -1)
|
||||
{
|
||||
throw new ArgumentException("API schema requires HTTPS protocol");
|
||||
}
|
||||
|
||||
_url = apiUrl;
|
||||
_defaultParameters = parameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make request method
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
/// <exception cref="WebException"></exception>
|
||||
public Response MakeRequest(string path, string method, Dictionary<string, object> parameters = null)
|
||||
{
|
||||
string[] allowedMethods = { MethodGet, MethodPost };
|
||||
|
||||
if (allowedMethods.Contains(method) == false)
|
||||
{
|
||||
throw new ArgumentException($"Method {method} is not valid. Allowed HTTP methods are {string.Join(", ", allowedMethods)}");
|
||||
}
|
||||
|
||||
if (parameters == null)
|
||||
{
|
||||
parameters = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
parameters = _defaultParameters.Union(parameters).ToDictionary(k => k.Key, v => v.Value);
|
||||
path = _url + path;
|
||||
|
||||
string httpQuery = QueryBuilder.BuildQueryString(parameters);
|
||||
|
||||
if (method.Equals(MethodGet) && parameters.Count > 0)
|
||||
{
|
||||
path += "?" + httpQuery;
|
||||
}
|
||||
|
||||
Exception exception = null;
|
||||
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(path);
|
||||
request.Method = method;
|
||||
|
||||
if (method.Equals(MethodPost))
|
||||
{
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
byte[] bytes = encoding.GetBytes(httpQuery);
|
||||
request.ContentLength = bytes.Length;
|
||||
request.ContentType = ContentType;
|
||||
request.UserAgent = UserAgent;
|
||||
|
||||
Stream post = request.GetRequestStream();
|
||||
post.Write(bytes, 0, bytes.Length);
|
||||
post.Flush();
|
||||
post.Close();
|
||||
}
|
||||
|
||||
HttpWebResponse response;
|
||||
|
||||
try
|
||||
{
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException webException)
|
||||
{
|
||||
response = (HttpWebResponse)webException.Response;
|
||||
exception = webException;
|
||||
}
|
||||
|
||||
if (request == null || response == null)
|
||||
{
|
||||
throw new WebException(exception.ToString(), exception);
|
||||
}
|
||||
|
||||
// ReSharper disable once AssignNullToNotNullAttribute
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
string responseBody = reader.ReadToEnd();
|
||||
int statusCode = (int)response.StatusCode;
|
||||
|
||||
return new Response(statusCode, responseBody);
|
||||
}
|
||||
}
|
||||
}
|
73
Retailcrm/Response.cs
Normal file
73
Retailcrm/Response.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm
|
||||
{
|
||||
/// <summary>
|
||||
/// Response
|
||||
/// </summary>
|
||||
public class Response
|
||||
{
|
||||
private readonly int _statusCode;
|
||||
private readonly string _rawResponse;
|
||||
private readonly Dictionary<string, object> _responseData;
|
||||
|
||||
/// <summary>
|
||||
/// Response constructor
|
||||
/// </summary>
|
||||
/// <param name="statusCode"></param>
|
||||
/// <param name="responseBody"></param>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public Response(int statusCode, string responseBody = null)
|
||||
{
|
||||
_statusCode = statusCode;
|
||||
|
||||
if (string.IsNullOrEmpty(responseBody))
|
||||
{
|
||||
throw new ArgumentException("Response body is empty");
|
||||
}
|
||||
|
||||
_rawResponse = responseBody;
|
||||
|
||||
var jsSerializer = new JavaScriptSerializer();
|
||||
_responseData = (Dictionary<string, object>)jsSerializer.DeserializeObject(responseBody);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get response status code
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetStatusCode()
|
||||
{
|
||||
return _statusCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get response body data
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<string, object> GetResponse()
|
||||
{
|
||||
return _responseData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get raw response body
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetRawResponse()
|
||||
{
|
||||
return _rawResponse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check response is successfull
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool IsSuccessfull()
|
||||
{
|
||||
return _statusCode < 400;
|
||||
}
|
||||
}
|
||||
}
|
91
Retailcrm/Retailcrm.csproj
Normal file
91
Retailcrm/Retailcrm.csproj
Normal file
@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{9C378EF4-9F9B-4214-A9AA-1FC3C44EDB41}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Retailcrm</RootNamespace>
|
||||
<AssemblyName>Retailcrm</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\Retailcrm.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="JetBrains.Annotations, Version=11.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\Marwin\packages\JetBrains.Annotations.11.0.0\lib\net20\JetBrains.Annotations.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Connection.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="QueryBuilder.cs" />
|
||||
<Compile Include="Request.cs" />
|
||||
<Compile Include="Response.cs" />
|
||||
<Compile Include="Versions\V3\References.cs" />
|
||||
<Compile Include="Versions\V3\Statistic.cs" />
|
||||
<Compile Include="Versions\V3\Client.cs" />
|
||||
<Compile Include="Versions\V3\Orders.cs" />
|
||||
<Compile Include="Versions\V3\Customers.cs" />
|
||||
<Compile Include="Versions\V3\Packs.cs" />
|
||||
<Compile Include="Versions\V3\Stores.cs" />
|
||||
<Compile Include="Versions\V3\Telephony.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\Telephony.cs" />
|
||||
<Compile Include="Versions\V4\Users.cs" />
|
||||
<Compile Include="Versions\V5\Client.cs" />
|
||||
<Compile Include="Versions\V5\Costs.cs" />
|
||||
<Compile Include="Versions\V5\CustomFields.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\Telephony.cs" />
|
||||
<Compile Include="Versions\V5\Users.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Retailcrm.nuspec" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
90
Retailcrm/Versions/V3/Client.cs
Normal file
90
Retailcrm/Versions/V3/Client.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
/// <summary>
|
||||
/// V3 Client
|
||||
/// </summary>
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Request
|
||||
/// </summary>
|
||||
protected Request Request;
|
||||
/// <summary>
|
||||
/// Site code
|
||||
/// </summary>
|
||||
protected string SiteCode;
|
||||
|
||||
/// <summary>
|
||||
/// V3 Client Constructor
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="site"></param>
|
||||
public Client(string url, string key, string site = "")
|
||||
{
|
||||
if ("/" != url.Substring(url.Length - 1, 1))
|
||||
{
|
||||
url += "/";
|
||||
}
|
||||
|
||||
url += "api/v3";
|
||||
|
||||
Request = new Request(url, new Dictionary<string, object> { { "apiKey", key } });
|
||||
SiteCode = site;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return current site
|
||||
/// </summary>
|
||||
/// <returns>string</returns>
|
||||
public string GetSite()
|
||||
{
|
||||
return SiteCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return current site
|
||||
/// </summary>
|
||||
public void SetSite(string site)
|
||||
{
|
||||
SiteCode = site;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check ID parameter
|
||||
/// </summary>
|
||||
/// <param name="by"></param>
|
||||
protected static void CheckIdParameter(string by)
|
||||
{
|
||||
string[] allowedForBy = { "externalId", "id" };
|
||||
if (allowedForBy.Contains(by) == false)
|
||||
{
|
||||
throw new ArgumentException($"Value {by} for parameter `by` is not valid. Allowed values are {string.Join(", ", allowedForBy)}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fill params by site value
|
||||
/// </summary>
|
||||
/// <param name="site"></param>
|
||||
/// <param name="param"></param>
|
||||
/// <returns>Dictionary</returns>
|
||||
protected Dictionary<string, object> FillSite(string site, Dictionary<string, object> param)
|
||||
{
|
||||
if (site.Length > 1)
|
||||
{
|
||||
param.Add("site", site);
|
||||
}
|
||||
else if (SiteCode.Length > 1)
|
||||
{
|
||||
param.Add("site", SiteCode);
|
||||
}
|
||||
|
||||
return param;
|
||||
}
|
||||
}
|
||||
}
|
176
Retailcrm/Versions/V3/Customers.cs
Normal file
176
Retailcrm/Versions/V3/Customers.cs
Normal file
@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Create customer
|
||||
/// </summary>
|
||||
/// <param name="customer"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public Response CustomersCreate(Dictionary<string, object> customer, string site = "")
|
||||
{
|
||||
if (customer.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customer` must contains a data");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/customers/create",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customer", new JavaScriptSerializer().Serialize(customer) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update customer
|
||||
/// </summary>
|
||||
/// <param name="customer"></param>
|
||||
/// <param name="by"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public Response CustomersUpdate(Dictionary<string, object> customer, string by = "externalId", string site = "")
|
||||
{
|
||||
if (customer.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customer` must contains a data");
|
||||
}
|
||||
|
||||
if (!customer.ContainsKey("id") && !customer.ContainsKey("externalId"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customer` must contains an id or externalId");
|
||||
}
|
||||
|
||||
CheckIdParameter(by);
|
||||
|
||||
string uid = by == "externalId" ? customer["externalId"].ToString() : customer["id"].ToString();
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/customers/{uid}/edit",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "by", by },
|
||||
{ "customer", new JavaScriptSerializer().Serialize(customer) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get customer
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="by"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomersGet(string id, string by = "externalId", string site = "")
|
||||
{
|
||||
CheckIdParameter(by);
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/customers/{id}",
|
||||
Request.MethodGet,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "by", by }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get customers list
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomersList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fix external id
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomersFixExternalIds(Dictionary<string, object>[] ids)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/customers/fix-external-ids",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customers", new JavaScriptSerializer().Serialize(ids) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload customers
|
||||
/// </summary>
|
||||
/// <param name="customers"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
public Response CustomersUpload(List<object> customers, string site = "")
|
||||
{
|
||||
if (customers.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customers` must contains a data");
|
||||
}
|
||||
|
||||
if (customers.Count > 50)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customers` must contain 50 or less records");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/customers/upload",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customers", new JavaScriptSerializer().Serialize(customers) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
256
Retailcrm/Versions/V3/Orders.cs
Normal file
256
Retailcrm/Versions/V3/Orders.cs
Normal file
@ -0,0 +1,256 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Create order
|
||||
/// </summary>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersCreate(Dictionary<string, object> order, string site = "")
|
||||
{
|
||||
if (order.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must contains a data");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/create",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "order", new JavaScriptSerializer().Serialize(order) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update order
|
||||
/// </summary>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="by"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersUpdate(Dictionary<string, object> order, string by = "externalId", string site = "")
|
||||
{
|
||||
if (order.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must contains a data");
|
||||
}
|
||||
|
||||
if (!order.ContainsKey("id") && !order.ContainsKey("externalId"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must contains an id or externalId");
|
||||
}
|
||||
|
||||
CheckIdParameter(by);
|
||||
|
||||
string uid = by == "externalId" ? order["externalId"].ToString() : order["id"].ToString();
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/orders/{uid}/edit",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "by", by },
|
||||
{ "order", new JavaScriptSerializer().Serialize(order) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get order
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="by"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersGet(string id, string by = "externalId", string site = "")
|
||||
{
|
||||
CheckIdParameter(by);
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/orders/{id}",
|
||||
Request.MethodGet,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "by", by }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
|
||||
if (filter != null && filter.Count > 0)
|
||||
{
|
||||
parameters.Add("filter", filter);
|
||||
}
|
||||
|
||||
if (page > 1)
|
||||
{
|
||||
parameters.Add("page", page);
|
||||
}
|
||||
|
||||
if (limit > 20)
|
||||
{
|
||||
parameters.Add("limit", limit);
|
||||
}
|
||||
|
||||
return Request.MakeRequest("/orders", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fix external ids
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersFixExternalIds(Dictionary<string, object>[] ids)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/orders/fix-external-ids",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "orders", new JavaScriptSerializer().Serialize(ids) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get orders history
|
||||
/// </summary>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <param name="offset"></param>
|
||||
/// <param name="skipMyChanges"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersHistory(DateTime? startDate = null, DateTime? endDate = null, int limit = 200, int offset = 0, bool skipMyChanges = true)
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
|
||||
if (startDate != null)
|
||||
{
|
||||
parameters.Add("startDate", startDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
if (endDate != null)
|
||||
{
|
||||
parameters.Add("endDate", endDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
if (limit > 0)
|
||||
{
|
||||
parameters.Add("limit", limit);
|
||||
}
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
parameters.Add("offset", offset);
|
||||
}
|
||||
|
||||
parameters.Add("skipMyChanges", skipMyChanges);
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/history",
|
||||
Request.MethodGet,
|
||||
parameters
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get orders statuses
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="externalIds"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersStatuses(List<string> ids, List<string> externalIds = null)
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
|
||||
if (ids == null && externalIds == null)
|
||||
{
|
||||
throw new ArgumentException("You must set the array of `ids` or `externalIds`.");
|
||||
}
|
||||
|
||||
if (
|
||||
ids != null && externalIds != null && ids.Count + externalIds.Count > 500 ||
|
||||
ids == null && externalIds != null && externalIds.Count > 500 ||
|
||||
ids != null && externalIds == null && ids.Count > 500
|
||||
)
|
||||
{
|
||||
throw new ArgumentException("Too many ids or externalIds. Maximum number of elements is 500");
|
||||
}
|
||||
|
||||
if (ids != null && ids.Count > 0)
|
||||
{
|
||||
parameters.Add("ids", ids);
|
||||
}
|
||||
|
||||
if (externalIds != null && externalIds.Count > 0)
|
||||
{
|
||||
parameters.Add("externalIds", externalIds);
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/statuses",
|
||||
Request.MethodGet,
|
||||
parameters
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orders upload
|
||||
/// </summary>
|
||||
/// <param name="orders"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersUpload(List<object> orders, string site = "")
|
||||
{
|
||||
if (orders.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `orders` must contains a data");
|
||||
}
|
||||
|
||||
if (orders.Count > 50)
|
||||
{
|
||||
throw new ArgumentException("Parameter `orders` must contain 50 or less records");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/upload",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "orders", new JavaScriptSerializer().Serialize(orders) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
142
Retailcrm/Versions/V3/Packs.cs
Normal file
142
Retailcrm/Versions/V3/Packs.cs
Normal file
@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get packs list
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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("/orders/packs", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create pack
|
||||
/// </summary>
|
||||
/// <param name="pack"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksCreate(Dictionary<string, object> pack)
|
||||
{
|
||||
if (pack.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `pack` must contains a data");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/packs/create",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "pack", new JavaScriptSerializer().Serialize(pack) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update pack data
|
||||
/// </summary>
|
||||
/// <param name="pack"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksUpdate(Dictionary<string, object> pack)
|
||||
{
|
||||
if (pack.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `pack` must contains a data");
|
||||
}
|
||||
|
||||
if (!pack.ContainsKey("id"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `pack` must contains an id");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/orders/packs/{pack["id"].ToString()}/edit",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "pack", new JavaScriptSerializer().Serialize(pack) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete pack
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksDelete(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/orders/packs/{id}/delete",
|
||||
Request.MethodPost
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get pack by id
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksGet(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/orders/packs/{id}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get packs history
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response PacksHistory(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
|
||||
if (filter != null && filter.Count > 0)
|
||||
{
|
||||
parameters.Add("filter", filter);
|
||||
}
|
||||
|
||||
if (page > 1)
|
||||
{
|
||||
parameters.Add("page", page);
|
||||
}
|
||||
|
||||
if (limit > 0)
|
||||
{
|
||||
parameters.Add("limit", limit);
|
||||
}
|
||||
|
||||
return Request.MakeRequest("/orders/packs/history", Request.MethodGet, parameters);
|
||||
}
|
||||
}
|
||||
}
|
461
Retailcrm/Versions/V3/References.cs
Normal file
461
Retailcrm/Versions/V3/References.cs
Normal file
@ -0,0 +1,461 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Countries
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Countries()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/countries",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delivery services
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response DeliveryServices()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/delivery-services",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delivery types
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response DeliveryTypes()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/delivery-types",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order methods
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response OrderMethods()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/order-methods",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order types
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response OrderTypes()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/order-types",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Payment statuses
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response PaymentStatuses()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/payment-statuses",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Payment types
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response PaymentTypes()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/payment-types",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Product statuses
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response ProductStatuses()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/product-statuses",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sites
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Sites()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/sites",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statuses groups
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response StatusGroups()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/status-groups",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statuses
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Statuses()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/statuses",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response Stores()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/stores",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delivery services edit
|
||||
/// </summary>
|
||||
/// <param name="service"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delivery types edit
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Orders methods edit
|
||||
/// </summary>
|
||||
/// <param name="method"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Order types edit
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Payment statuses edit
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Payment types edit
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Product statuses edit
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sites edit
|
||||
/// </summary>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Statuses edit
|
||||
/// </summary>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stores edit
|
||||
/// </summary>
|
||||
/// <param name="store"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
17
Retailcrm/Versions/V3/Statistic.cs
Normal file
17
Retailcrm/Versions/V3/Statistic.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Update statistic
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response StatisticUpdate()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/statistic/update",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
69
Retailcrm/Versions/V3/Stores.cs
Normal file
69
Retailcrm/Versions/V3/Stores.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get inventories
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreInventoriesGet(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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/inventories", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload inventories
|
||||
/// </summary>
|
||||
/// <param name="offers"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreInventoriesUpload(List<object> offers, string site = "")
|
||||
{
|
||||
if (offers.Count< 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `offers` must contains a data");
|
||||
}
|
||||
|
||||
if (offers.Count > 250)
|
||||
{
|
||||
throw new ArgumentException("Parameter `offers` must contain 250 or less records");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/store/inventories/upload",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "offers", new JavaScriptSerializer().Serialize(offers) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
150
Retailcrm/Versions/V3/Telephony.cs
Normal file
150
Retailcrm/Versions/V3/Telephony.cs
Normal file
@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V3
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get manager
|
||||
/// </summary>
|
||||
/// <param name="phone"></param>
|
||||
/// <param name="details"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonyManagerGet(string phone, string details = "1")
|
||||
{
|
||||
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||
|
||||
if (string.IsNullOrEmpty(phone))
|
||||
{
|
||||
throw new ArgumentException("Parameter `phone` must contains a data");
|
||||
}
|
||||
|
||||
parameters.Add("details", details);
|
||||
parameters.Add("phone", phone);
|
||||
|
||||
return Request.MakeRequest("/telephony/manager", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send call event
|
||||
/// </summary>
|
||||
/// <param name="phone"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonyCallEvent(string phone, string type, string status, string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(phone))
|
||||
{
|
||||
throw new ArgumentException("Parameter `phone` must contains a data");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
throw new ArgumentException("Parameter `phone` must contains a data");
|
||||
}
|
||||
|
||||
List<string> statuses = new List<string> { "answered", "busy", "cancel", "failed", "no answered" };
|
||||
List<string> types = new List<string> { "hangup", "in", "out" };
|
||||
|
||||
if (!statuses.Contains(status))
|
||||
{
|
||||
throw new ArgumentException("Parameter `status` must be equal one of `answered|busy|cancel|failed|no answered`");
|
||||
}
|
||||
|
||||
if (!types.Contains(type))
|
||||
{
|
||||
throw new ArgumentException("Parameter `type` must be equal one of `hangup|in|out`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/telephony/call/event",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "phone", phone },
|
||||
{ "type", type },
|
||||
{ "hangupStatus", status},
|
||||
{ "code", code }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload calls
|
||||
/// </summary>
|
||||
/// <param name="calls"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonyCallsUpload(List<object> calls)
|
||||
{
|
||||
if (calls.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `calls` must contains a data");
|
||||
}
|
||||
|
||||
if (calls.Count > 50)
|
||||
{
|
||||
throw new ArgumentException("Parameter `calls` must contain 50 or less records");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/telephony/calls/upload",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "calls", new JavaScriptSerializer().Serialize(calls) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit telephony settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="logo"></param>
|
||||
/// <param name="active"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonySettingsEdit(string code, string clientId, string url, string name, string logo, string active = "true")
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new ArgumentException("Parameter `name` must contains a data");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
throw new ArgumentException("Parameter `phone` must contains a data");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentException("Parameter `url` must contains a data");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(clientId))
|
||||
{
|
||||
throw new ArgumentException("Parameter `clientId` must contains a data");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/telephony/setting/{code}",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", code },
|
||||
{ "name", name },
|
||||
{ "clientId", clientId},
|
||||
{ "makeCallUrl", url },
|
||||
{ "image", logo },
|
||||
{ "active", active }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
31
Retailcrm/Versions/V4/Client.cs
Normal file
31
Retailcrm/Versions/V4/Client.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
using ParentClass = V3.Client;
|
||||
|
||||
/// <summary>
|
||||
/// V4 Client
|
||||
/// </summary>
|
||||
public partial class Client : ParentClass
|
||||
{
|
||||
/// <summary>
|
||||
/// V4 Client Constructor
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="site"></param>
|
||||
public Client(string url, string key, string site = "") : base(url, key, site)
|
||||
{
|
||||
if ("/" != url.Substring(url.Length - 1, 1))
|
||||
{
|
||||
url += "/";
|
||||
}
|
||||
|
||||
url += "api/v4";
|
||||
|
||||
Request = new Request(url, new Dictionary<string, object> { { "apiKey", key } });
|
||||
SiteCode = site;
|
||||
}
|
||||
}
|
||||
}
|
36
Retailcrm/Versions/V4/Customers.cs
Normal file
36
Retailcrm/Versions/V4/Customers.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Customers history
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomersHistory(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
97
Retailcrm/Versions/V4/Delivery.cs
Normal file
97
Retailcrm/Versions/V4/Delivery.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get delivery settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit delivery settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update delivery tracking
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="statusUpdate"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
41
Retailcrm/Versions/V4/Marketplace.cs
Normal file
41
Retailcrm/Versions/V4/Marketplace.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Edit marketplace module settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
36
Retailcrm/Versions/V4/Orders.cs
Normal file
36
Retailcrm/Versions/V4/Orders.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get orders history
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersHistory(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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("/orders/history", Request.MethodGet, parameters);
|
||||
}
|
||||
}
|
||||
}
|
48
Retailcrm/Versions/V4/References.cs
Normal file
48
Retailcrm/Versions/V4/References.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Price types
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response PriceTypes()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/price-types",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Price type edit
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
125
Retailcrm/Versions/V4/Stores.cs
Normal file
125
Retailcrm/Versions/V4/Stores.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get products
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreProducts(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload prices
|
||||
/// </summary>
|
||||
/// <param name="prices"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get store settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreSettingGet(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
throw new ArgumentException("Parameter `code` is mandatory");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/store/setting/{code}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit store settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
116
Retailcrm/Versions/V4/Telephony.cs
Normal file
116
Retailcrm/Versions/V4/Telephony.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Send call event
|
||||
/// </summary>
|
||||
/// <param name="ievent"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonyCallEvent(Dictionary<string, object> ievent)
|
||||
{
|
||||
if (ievent.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `event` must contain data");
|
||||
}
|
||||
|
||||
if (!ievent.ContainsKey("phone"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `phone` must contains a data");
|
||||
}
|
||||
|
||||
if (!ievent.ContainsKey("type"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `type` must contains a data");
|
||||
}
|
||||
|
||||
if (!ievent.ContainsKey("hangupStatus"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `hangupStatus` must contains a data");
|
||||
}
|
||||
|
||||
List<string> statuses = new List<string> { "answered", "busy", "cancel", "failed", "no answered" };
|
||||
List<string> types = new List<string> { "hangup", "in", "out" };
|
||||
|
||||
if (!statuses.Contains(ievent["hangupStatus"].ToString()))
|
||||
{
|
||||
throw new ArgumentException("Parameter `status` must be equal one of `answered|busy|cancel|failed|no answered`");
|
||||
}
|
||||
|
||||
if (!types.Contains(ievent["type"].ToString()))
|
||||
{
|
||||
throw new ArgumentException("Parameter `type` must be equal one of `hangup|in|out`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/telephony/call/event",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "event", new JavaScriptSerializer().Serialize(ievent) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get telephony settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonySettingsGet(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
throw new ArgumentException("Parameter `code` should contain data");
|
||||
}
|
||||
|
||||
return Request.MakeRequest($"/telephony/setting/{code}", Request.MethodGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit telephony settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public Response TelephonySettingsEdit(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`");
|
||||
}
|
||||
|
||||
if (!configuration.ContainsKey("makeCallUrl"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `configuration` should contain `makeCallUrl`");
|
||||
}
|
||||
|
||||
if (!configuration.ContainsKey("clientId"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `configuration` should contain `clientId`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/telephony/setting/{configuration["code"].ToString()}/edit",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "configuration", new JavaScriptSerializer().Serialize(configuration) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
69
Retailcrm/Versions/V4/Users.cs
Normal file
69
Retailcrm/Versions/V4/Users.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V4
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get users
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get users groups
|
||||
/// </summary>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response UsersGroups(int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response User(int id)
|
||||
{
|
||||
return Request.MakeRequest($"/users/{id}", Request.MethodGet);
|
||||
}
|
||||
}
|
||||
}
|
31
Retailcrm/Versions/V5/Client.cs
Normal file
31
Retailcrm/Versions/V5/Client.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
using ParentClass = V4.Client;
|
||||
|
||||
/// <summary>
|
||||
/// V5 Client
|
||||
/// </summary>
|
||||
public partial class Client : ParentClass
|
||||
{
|
||||
/// <summary>
|
||||
/// V5 Client Constructor
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="site"></param>
|
||||
public Client(string url, string key, string site = "") : base(url, key, site)
|
||||
{
|
||||
if ("/" != url.Substring(url.Length - 1, 1))
|
||||
{
|
||||
url += "/";
|
||||
}
|
||||
|
||||
url += "api/v5";
|
||||
|
||||
Request = new Request(url, new Dictionary<string, object> { { "apiKey", key } });
|
||||
SiteCode = site;
|
||||
}
|
||||
}
|
||||
}
|
187
Retailcrm/Versions/V5/Costs.cs
Normal file
187
Retailcrm/Versions/V5/Costs.cs
Normal file
@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get costs
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response CostsList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create cost
|
||||
/// </summary>
|
||||
/// <param name="cost"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response CostsCreate(Dictionary<string, object> cost, string site = "")
|
||||
{
|
||||
if (cost.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `cost` must contains a data");
|
||||
}
|
||||
|
||||
if (!cost.ContainsKey("costItem"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `costItem` must be set");
|
||||
}
|
||||
|
||||
if (!cost.ContainsKey("summ"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `summ` must be set");
|
||||
}
|
||||
|
||||
if (!cost.ContainsKey("dateFrom"))
|
||||
{
|
||||
throw new ArgumentException("`dateFrom`: Time interval lower bound must not be blank");
|
||||
}
|
||||
|
||||
if (!cost.ContainsKey("dateTo"))
|
||||
{
|
||||
throw new ArgumentException("`dateTo`: Time interval upper bound must not be blank");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/costs/create",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "cost", new JavaScriptSerializer().Serialize(cost) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete cost
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Upload costs
|
||||
/// </summary>
|
||||
/// <param name="costs"></param>
|
||||
/// <returns></returns>
|
||||
public Response CostsUpload(List<object> costs)
|
||||
{
|
||||
if (costs.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `costs` must contains a data");
|
||||
}
|
||||
|
||||
if (costs.Count > 50)
|
||||
{
|
||||
throw new ArgumentException("Parameter `costs` must contain 50 or less records");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/costs/upload",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "costs", new JavaScriptSerializer().Serialize(costs) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get cost
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response CostsGet(int id)
|
||||
{
|
||||
return Request.MakeRequest($"/costs/{id}", Request.MethodGet);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Batch delete
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response CostsDelete(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/costs/{id}/delete",
|
||||
Request.MethodPost
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update cost
|
||||
/// </summary>
|
||||
/// <param name="cost"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
244
Retailcrm/Versions/V5/CustomFields.cs
Normal file
244
Retailcrm/Versions/V5/CustomFields.cs
Normal file
@ -0,0 +1,244 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get custom fields
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomFieldsList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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("/custom-fields", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom field
|
||||
/// </summary>
|
||||
/// <param name="customField"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomFieldsCreate(Dictionary<string, object> customField)
|
||||
{
|
||||
List<string> types = new List<string>
|
||||
{
|
||||
"boolean", "date", "dictionary", "email", "integer", "numeric", "string", "text"
|
||||
};
|
||||
|
||||
if (customField.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` must contains a data");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("code"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `code`");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("name"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `name`");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("type"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `type`");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("entity"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `entity`");
|
||||
}
|
||||
|
||||
if (!types.Contains(customField["type"].ToString()))
|
||||
{
|
||||
throw new ArgumentException(
|
||||
"Parameter `customField` should contain `type` & value of type should be on of `boolean|date|dictionary|email|integer|numeric|string|text`"
|
||||
);
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/custom-fields/{customField["entity"].ToString()}/create",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customField", new JavaScriptSerializer().Serialize(customField) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get custom field
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomFieldsGet(string code, string entity)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/custom-fields/{entity}/{code}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update custom field
|
||||
/// </summary>
|
||||
/// <param name="customField"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomFieldsUpdate(Dictionary<string, object> customField)
|
||||
{
|
||||
if (customField.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` must contains a data");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("code"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `code`");
|
||||
}
|
||||
|
||||
if (!customField.ContainsKey("name"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customField` should contain `name`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/custom-fields/{customField["entity"].ToString()}/{customField["code"].ToString()}/edit",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customField", new JavaScriptSerializer().Serialize(customField) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get custom dictionaries
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomDictionaryList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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("/custom-fields/dictionaries", Request.MethodGet, parameters);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom dictionary
|
||||
/// </summary>
|
||||
/// <param name="customDictionary"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomDictionaryCreate(Dictionary<string, object> customDictionary)
|
||||
{
|
||||
if (customDictionary.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` must contains a data");
|
||||
}
|
||||
|
||||
if (!customDictionary.ContainsKey("code"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` should contain `code`");
|
||||
}
|
||||
|
||||
if (!customDictionary.ContainsKey("name"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` should contain `name`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/custom-fields/dictionaries/create",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customDictionary", new JavaScriptSerializer().Serialize(customDictionary) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get custom dictionary
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomDictionaryGet(string code)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/custom-fields/dictionaries/{code}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update custom dictionary
|
||||
/// </summary>
|
||||
/// <param name="customDictionary"></param>
|
||||
/// <returns></returns>
|
||||
public Response CustomDictionaryUpdate(Dictionary<string, object> customDictionary)
|
||||
{
|
||||
if (customDictionary.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` must contains a data");
|
||||
}
|
||||
|
||||
if (!customDictionary.ContainsKey("code"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` should contain `code`");
|
||||
}
|
||||
|
||||
if (!customDictionary.ContainsKey("name"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `customDictionary` should contain `name`");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/custom-fields/dictionaries/{customDictionary["code"].ToString()}/edit",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "customDictionary", new JavaScriptSerializer().Serialize(customDictionary) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
28
Retailcrm/Versions/V5/Delivery.cs
Normal file
28
Retailcrm/Versions/V5/Delivery.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get delivery settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public new Response DeliverySettingGet(string code)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5", code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update delivery settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public new Response DeliverySettingsEdit(Dictionary<string, object> configuration)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5");
|
||||
}
|
||||
}
|
||||
}
|
59
Retailcrm/Versions/V5/Integrations.cs
Normal file
59
Retailcrm/Versions/V5/Integrations.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get integration settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public Response IntegrationsSettingGet(string code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(code))
|
||||
{
|
||||
throw new ArgumentException("Parameter `code` is mandatory");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/integration-modules/{code}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create/Update integration settings
|
||||
/// </summary>
|
||||
/// <param name="integrationModule"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
77
Retailcrm/Versions/V5/Notes.cs
Normal file
77
Retailcrm/Versions/V5/Notes.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Create note
|
||||
/// </summary>
|
||||
/// <param name="note"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete note
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response NotesDelete(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/customers/notes/{id}/delete",
|
||||
Request.MethodPost
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get notes list
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response NotesList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
50
Retailcrm/Versions/V5/Orders.cs
Normal file
50
Retailcrm/Versions/V5/Orders.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Combine orders
|
||||
/// </summary>
|
||||
/// <param name="order"></param>
|
||||
/// <param name="resultOrder"></param>
|
||||
/// <param name="technique"></param>
|
||||
/// <returns></returns>
|
||||
public Response OrdersCombine(Dictionary<string, object> order, Dictionary<string, object> resultOrder, string technique = "ours")
|
||||
{
|
||||
if (order.Count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must contains a data");
|
||||
}
|
||||
|
||||
if (!order.ContainsKey("id"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must contains `id` key");
|
||||
}
|
||||
|
||||
if (resultOrder.Count <= 0)
|
||||
{
|
||||
throw new ArgumentException("Parameter `resultOrder` must contains a data");
|
||||
}
|
||||
|
||||
if (!resultOrder.ContainsKey("id"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `resultOrder` must contains `id` key");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/combine",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "technique", technique },
|
||||
{ "order", new JavaScriptSerializer().Serialize(order) },
|
||||
{ "resultOrder", new JavaScriptSerializer().Serialize(resultOrder) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
95
Retailcrm/Versions/V5/Payments.cs
Normal file
95
Retailcrm/Versions/V5/Payments.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Create payment
|
||||
/// </summary>
|
||||
/// <param name="payment"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
public Response PaymentsCreate(Dictionary<string, object> payment, string site = "")
|
||||
{
|
||||
if (payment.Count < 1)
|
||||
{
|
||||
throw new ArgumentException("Parameter `payment` must contains a data");
|
||||
}
|
||||
|
||||
if (!payment.ContainsKey("type"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `type` must be set");
|
||||
}
|
||||
|
||||
if (!payment.ContainsKey("order"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `order` must be set");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
"/orders/payments/create",
|
||||
Request.MethodPost,
|
||||
FillSite(
|
||||
site,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "payment", new JavaScriptSerializer().Serialize(payment) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update payment
|
||||
/// </summary>
|
||||
/// <param name="payment"></param>
|
||||
/// <param name="by"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete payment
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response PaymentsDelete(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/orders/payments/{id}/delete",
|
||||
Request.MethodPost
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
157
Retailcrm/Versions/V5/References.cs
Normal file
157
Retailcrm/Versions/V5/References.cs
Normal file
@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Costs groups
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response CostGroups()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/cost-groups",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Costs
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response CostItems()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/cost-items",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legal entities
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Response LegalEntities()
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
"/reference/legal-entities",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cost group edit
|
||||
/// </summary>
|
||||
/// <param name="group"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cost items edit
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
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");
|
||||
}
|
||||
|
||||
if (!item.ContainsKey("group"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `group` 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) }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legal entities edit
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
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");
|
||||
}
|
||||
|
||||
if (!entity.ContainsKey("countryIso"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `countryIso` is missing");
|
||||
}
|
||||
|
||||
if (!entity.ContainsKey("contragentType"))
|
||||
{
|
||||
throw new ArgumentException("Parameter `contragentType` is missing");
|
||||
}
|
||||
|
||||
return Request.MakeRequest(
|
||||
$"/reference/legal-entities/{entity["code"].ToString()}/edit",
|
||||
Request.MethodPost,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "legalEntity", new JavaScriptSerializer().Serialize(entity) }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
36
Retailcrm/Versions/V5/Segments.cs
Normal file
36
Retailcrm/Versions/V5/Segments.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get segments
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response Segments(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
86
Retailcrm/Versions/V5/Stores.cs
Normal file
86
Retailcrm/Versions/V5/Stores.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get external store settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public new Response StoreSettingGet(string code)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5", code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit external store settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public new Response StoreSettingsEdit(Dictionary<string, object> configuration)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get products groups
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreProductsGroups(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get products properties
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response StoreProductsProperties(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
108
Retailcrm/Versions/V5/Tasks.cs
Normal file
108
Retailcrm/Versions/V5/Tasks.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Script.Serialization;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a task
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update a task
|
||||
/// </summary>
|
||||
/// <param name="task"></param>
|
||||
/// <param name="site"></param>
|
||||
/// <returns></returns>
|
||||
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) }
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get task
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public Response TasksGet(string id)
|
||||
{
|
||||
return Request.MakeRequest(
|
||||
$"/tasks/{id}",
|
||||
Request.MethodGet
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get tasks list
|
||||
/// </summary>
|
||||
/// <param name="filter"></param>
|
||||
/// <param name="page"></param>
|
||||
/// <param name="limit"></param>
|
||||
/// <returns></returns>
|
||||
public Response TasksList(Dictionary<string, object> filter = null, int page = 1, int limit = 20)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
28
Retailcrm/Versions/V5/Telephony.cs
Normal file
28
Retailcrm/Versions/V5/Telephony.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Get telephony settings
|
||||
/// </summary>
|
||||
/// <param name="code"></param>
|
||||
/// <returns></returns>
|
||||
public new Response TelephonySettingsGet(string code)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5", code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit telephony settings
|
||||
/// </summary>
|
||||
/// <param name="configuration"></param>
|
||||
/// <returns></returns>
|
||||
public new Response TelephonySettingsEdit(Dictionary<string, object> configuration)
|
||||
{
|
||||
throw new ArgumentException("This method is unavailable in API V5", configuration.ToString());
|
||||
}
|
||||
}
|
||||
}
|
33
Retailcrm/Versions/V5/Users.cs
Normal file
33
Retailcrm/Versions/V5/Users.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Retailcrm.Versions.V5
|
||||
{
|
||||
public partial class Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Update user status
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="status"></param>
|
||||
/// <returns></returns>
|
||||
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 }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
4
Retailcrm/packages.config
Normal file
4
Retailcrm/packages.config
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="JetBrains.Annotations" version="11.0.0" targetFramework="net45" />
|
||||
</packages>
|
39
RetailcrmUnitTest/ApiTest.cs
Normal file
39
RetailcrmUnitTest/ApiTest.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
|
||||
namespace RetailcrmUnitTest
|
||||
{
|
||||
[TestClass]
|
||||
public class ApiTest
|
||||
{
|
||||
private readonly Connection _connection;
|
||||
|
||||
public ApiTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_connection = new Connection(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Versions()
|
||||
{
|
||||
Response response = _connection.Versions();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("versions"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Credentials()
|
||||
{
|
||||
Response response = _connection.Credentials();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("credentials"));
|
||||
}
|
||||
}
|
||||
}
|
12
RetailcrmUnitTest/App.config.dist
Normal file
12
RetailcrmUnitTest/App.config.dist
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="apiUrl" value="https://example.retailcrm.ru"/>
|
||||
<add key="apiKey" value="BBBBBBBBBBBBBBBBBBBBBBBBBBBB"/>
|
||||
<add key="site" value="default"/>
|
||||
<add key="store" value="test-store"/>
|
||||
<add key="manager" value="1"/>
|
||||
<add key="customer" value="1" />
|
||||
<add key="phone" value="+79999999999"/>
|
||||
</appSettings>
|
||||
</configuration>
|
19
RetailcrmUnitTest/Properties/AssemblyInfo.cs
Normal file
19
RetailcrmUnitTest/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("RetailcrmUnitTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RetailcrmUnitTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
[assembly: Guid("4069c2bc-c277-48a3-96ae-da5934a75f4d")]
|
||||
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
106
RetailcrmUnitTest/RetailcrmUnitTest.csproj
Normal file
106
RetailcrmUnitTest/RetailcrmUnitTest.csproj
Normal file
@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4069C2BC-C277-48A3-96AE-DA5934A75F4D}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RetailcrmUnitTest</RootNamespace>
|
||||
<AssemblyName>RetailcrmUnitTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<NuGetPackageImportStamp>
|
||||
</NuGetPackageImportStamp>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ApiTest.cs" />
|
||||
<Compile Include="V3\ClientTest.cs" />
|
||||
<Compile Include="V3\CustomersTest.cs" />
|
||||
<Compile Include="V3\OrdersTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="V3\PacksTest.cs" />
|
||||
<Compile Include="V3\ReferencesTest.cs" />
|
||||
<Compile Include="V3\StoresTest.cs" />
|
||||
<Compile Include="V3\TelephonyTest.cs" />
|
||||
<Compile Include="V4\CustomersTest.cs" />
|
||||
<Compile Include="V4\MarketplaceTest.cs" />
|
||||
<Compile Include="V4\OrdersTest.cs" />
|
||||
<Compile Include="V4\ReferencesTest.cs" />
|
||||
<Compile Include="V4\StoresTest.cs" />
|
||||
<Compile Include="V4\TelephonyTest.cs" />
|
||||
<Compile Include="V4\UsersTest.cs" />
|
||||
<Compile Include="V5\CostsTest.cs" />
|
||||
<Compile Include="V5\CustomFieldsTest.cs" />
|
||||
<Compile Include="V5\IntegrationTest.cs" />
|
||||
<Compile Include="V5\NotesTest.cs" />
|
||||
<Compile Include="V5\PaymentsTest.cs" />
|
||||
<Compile Include="V5\TasksTest.cs" />
|
||||
<Compile Include="V5\TelephonyTest.cs" />
|
||||
<Compile Include="V5\UsersTest.cs" />
|
||||
<Compile Include="V5\OrdersTest.cs" />
|
||||
<Compile Include="V5\ReferencesTest.cs" />
|
||||
<Compile Include="V5\SegmentsTest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="App.config.dist" />
|
||||
<None Include="packages.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Retailcrm\Retailcrm.csproj">
|
||||
<Project>{9c378ef4-9f9b-4214-a9aa-1fc3c44edb41}</Project>
|
||||
<Name>Retailcrm</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
|
||||
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
|
||||
</Project>
|
42
RetailcrmUnitTest/V3/ClientTest.cs
Normal file
42
RetailcrmUnitTest/V3/ClientTest.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class ClientTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public ClientTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"], appSettings["site"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InitTest()
|
||||
{
|
||||
Assert.IsInstanceOfType(_client, typeof(Client));
|
||||
|
||||
string siteCode = "default";
|
||||
|
||||
_client.SetSite(siteCode);
|
||||
|
||||
Assert.AreEqual(_client.GetSite(), siteCode);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StatisticUpdate()
|
||||
{
|
||||
Response response = _client.StatisticUpdate();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
}
|
||||
}
|
||||
}
|
210
RetailcrmUnitTest/V3/CustomersTest.cs
Normal file
210
RetailcrmUnitTest/V3/CustomersTest.cs
Normal file
@ -0,0 +1,210 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class CustomersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public CustomersTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomersCreateReadUpdate()
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>
|
||||
{
|
||||
{"externalId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
|
||||
{"lastName", "Baggins"},
|
||||
{"firstName", "Frodo"},
|
||||
{"email", "frodo@example.com"},
|
||||
{"phone", "+78888888888"}
|
||||
};
|
||||
|
||||
Response createResponse = _client.CustomersCreate(customer);
|
||||
|
||||
Assert.IsTrue(createResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetStatusCode() == 201);
|
||||
Assert.IsTrue(createResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
string id = createResponse.GetResponse()["id"].ToString();
|
||||
|
||||
Response getResponse = _client.CustomersGet(id, "id");
|
||||
Assert.IsTrue(getResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(getResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetStatusCode() == 201);
|
||||
Assert.IsTrue(getResponse.GetResponse().ContainsKey("customer"));
|
||||
|
||||
Dictionary<string, object> update = new Dictionary<string, object>
|
||||
{
|
||||
{"id", id},
|
||||
{"email", "frodobaggins@example.com"}
|
||||
};
|
||||
|
||||
Response updateResponse = _client.CustomersUpdate(update, "id");
|
||||
Assert.IsTrue(updateResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(updateResponse, typeof(Response));
|
||||
Assert.IsTrue(updateResponse.GetStatusCode() == 200);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomersFixExternalId()
|
||||
{
|
||||
long epochTicks = new DateTime(1970, 1, 1).Ticks;
|
||||
long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
|
||||
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>
|
||||
{
|
||||
{"externalId", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
|
||||
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Bull"},
|
||||
{"firstName", "John"},
|
||||
{"email", "bull@example.com"},
|
||||
{"phone", "+77777777777"}
|
||||
};
|
||||
|
||||
Response createResponse = _client.CustomersCreate(customer);
|
||||
string id = createResponse.GetResponse()["id"].ToString();
|
||||
string externalId = $"{unixTime}ID";
|
||||
|
||||
Dictionary<string, object>[] fix =
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "id", id },
|
||||
{ "externalId", externalId }
|
||||
}
|
||||
};
|
||||
|
||||
Assert.IsTrue(createResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetStatusCode() == 201);
|
||||
Assert.IsTrue(createResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
Response fixResponse = _client.CustomersFixExternalIds(fix);
|
||||
Assert.IsTrue(fixResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(fixResponse, typeof(Response));
|
||||
Assert.IsTrue(fixResponse.GetStatusCode() == 200);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomersList()
|
||||
{
|
||||
_client.SetSite(_appSettings["site"]);
|
||||
|
||||
Response response = _client.CustomersList();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("customers"));
|
||||
|
||||
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "dateTo", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
Response responseFiltered = _client.CustomersList(filter, 2, 100);
|
||||
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("customers"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomersUpload()
|
||||
{
|
||||
List<object> customers = new List<object>();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>
|
||||
{
|
||||
{ "createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "lastName", $"Doe{i}" },
|
||||
{ "firstName", $"John{i}" },
|
||||
{ "email", $"john{i}@example.com" },
|
||||
{ "phone", $"+7999999999{i}" }
|
||||
};
|
||||
|
||||
customers.Add(customer);
|
||||
}
|
||||
|
||||
Response response = _client.CustomersUpload(customers);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("uploadedCustomers"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `customer` must contains a data")]
|
||||
public void CustomersCreateArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>();
|
||||
_client.CustomersCreate(customer);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `customer` must contains a data")]
|
||||
public void CustomersUpdateEmptyCustomerArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>();
|
||||
_client.CustomersUpdate(customer);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `customer` must contains an id or externalId")]
|
||||
public void CustomersUpdateIdArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object> { { "lastName", "Doe" } };
|
||||
_client.CustomersUpdate(customer);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `customers` must contains a data")]
|
||||
public void CustomersUploadEmptyCustomersArgumentExeption()
|
||||
{
|
||||
List<object> customers = new List<object>();
|
||||
_client.CustomersUpload(customers);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `customers` must contain 50 or less records")]
|
||||
public void CustomersUploadLimitArgumentExeption()
|
||||
{
|
||||
List<object> customers = new List<object>();
|
||||
|
||||
for (int i = 0; i < 51; i++)
|
||||
{
|
||||
Dictionary<string, object> customer = new Dictionary<string, object>
|
||||
{
|
||||
{ "createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "lastName", $"Doe{i}" },
|
||||
{ "firstName", $"John{i}" },
|
||||
{ "email", $"john{i}@example.com" },
|
||||
{ "phone", $"+7999999999{i}" }
|
||||
};
|
||||
|
||||
customers.Add(customer);
|
||||
}
|
||||
|
||||
_client.CustomersUpload(customers);
|
||||
}
|
||||
}
|
||||
}
|
300
RetailcrmUnitTest/V3/OrdersTest.cs
Normal file
300
RetailcrmUnitTest/V3/OrdersTest.cs
Normal file
@ -0,0 +1,300 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class OrdersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public OrdersTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersCreateReadUpdate()
|
||||
{
|
||||
long epochTicks = new DateTime(1970, 1, 1).Ticks;
|
||||
long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
|
||||
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{"number", unixTime},
|
||||
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Doe"},
|
||||
{"firstName", "John"},
|
||||
{"email", "john@example.com"},
|
||||
{"phone", "+79999999999"}
|
||||
};
|
||||
|
||||
|
||||
Response createResponse = _client.OrdersCreate(order);
|
||||
Assert.IsTrue(createResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
string id = createResponse.GetResponse()["id"].ToString();
|
||||
|
||||
Response getResponse = _client.OrdersGet(id, "id");
|
||||
Assert.IsTrue(getResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(getResponse, typeof(Response));
|
||||
Assert.IsTrue(getResponse.GetResponse().ContainsKey("order"));
|
||||
|
||||
Dictionary<string, object> update = new Dictionary<string, object>
|
||||
{
|
||||
{"id", id},
|
||||
{"status", "cancel-other"}
|
||||
};
|
||||
|
||||
Response updateResponse = _client.OrdersUpdate(update, "id");
|
||||
Assert.IsTrue(updateResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(updateResponse, typeof(Response));
|
||||
Assert.IsTrue(updateResponse.GetStatusCode() == 200);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersFixExternalId()
|
||||
{
|
||||
long epochTicks = new DateTime(1970, 1, 1).Ticks;
|
||||
long unixTime = ((DateTime.UtcNow.Ticks - epochTicks) / TimeSpan.TicksPerSecond);
|
||||
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{"number", unixTime},
|
||||
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Doe"},
|
||||
{"firstName", "John"},
|
||||
{"email", "john@example.com"},
|
||||
{"phone", "+79999999999"}
|
||||
};
|
||||
|
||||
Response createResponse = _client.OrdersCreate(order);
|
||||
string id = createResponse.GetResponse()["id"].ToString();
|
||||
string externalId = $"{unixTime}ID";
|
||||
|
||||
Dictionary<string, object>[] fix =
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "id", id },
|
||||
{ "externalId", externalId }
|
||||
}
|
||||
};
|
||||
|
||||
Assert.IsTrue(createResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
Response fixResponse = _client.OrdersFixExternalIds(fix);
|
||||
Assert.IsTrue(fixResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(fixResponse, typeof(Response));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersList()
|
||||
{
|
||||
Response response = _client.OrdersList();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("orders"));
|
||||
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "extendedStatus", "new" },
|
||||
{ "createdAtTo", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
Response responseFiltered = _client.OrdersList(filter, 2, 100);
|
||||
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("orders"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersHistory()
|
||||
{
|
||||
Response response = _client.OrdersHistory();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("orders"));
|
||||
|
||||
|
||||
DateTime datetime = DateTime.Now;
|
||||
DateTime from = datetime.AddHours(-24);
|
||||
DateTime to = datetime.AddHours(-1);
|
||||
|
||||
Response responseFiltered = _client.OrdersHistory(from, to, 50, 1, false);
|
||||
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("orders"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersStatuses()
|
||||
{
|
||||
List<string> ids = new List<string>();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
string[] statuses = new string[5];
|
||||
|
||||
statuses[0] = "new";
|
||||
statuses[1] = "cancel-other";
|
||||
statuses[2] = "complete";
|
||||
statuses[3] = "assembling-complete";
|
||||
statuses[4] = "client-confirmed";
|
||||
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", $"order-{i}" },
|
||||
{ "createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "lastName", $"Doe{i}" },
|
||||
{ "firstName", $"John{i}" },
|
||||
{ "email", $"john{i}@example.com" },
|
||||
{ "phone", $"+7999999999{i}" },
|
||||
{ "status", statuses[i] }
|
||||
};
|
||||
|
||||
Response createResponse = _client.OrdersCreate(order);
|
||||
ids.Add(createResponse.GetResponse()["id"].ToString());
|
||||
}
|
||||
|
||||
Response response = _client.OrdersStatuses(ids);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("orders"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersUpload()
|
||||
{
|
||||
List<object> orders = new List<object>();
|
||||
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
string[] statuses = new string[5];
|
||||
|
||||
statuses[0] = "new";
|
||||
statuses[1] = "cancel-other";
|
||||
statuses[2] = "complete";
|
||||
statuses[3] = "assembling-complete";
|
||||
statuses[4] = "client-confirmed";
|
||||
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", $"order-{i}" },
|
||||
{ "createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "lastName", $"Doe{i}" },
|
||||
{ "firstName", $"John{i}" },
|
||||
{ "email", $"john{i}@example.com" },
|
||||
{ "phone", $"+7999999999{i}" },
|
||||
{ "status", statuses[i] }
|
||||
};
|
||||
|
||||
orders.Add(order);
|
||||
}
|
||||
|
||||
Response response = _client.OrdersUpload(orders);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("uploadedOrders"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `order` must contains a data")]
|
||||
public void OrdersCreateArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> order = new Dictionary<string, object>();
|
||||
_client.OrdersCreate(order);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `order` must contains a data")]
|
||||
public void OrdersUpdateEmptyOrderArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> order = new Dictionary<string, object>();
|
||||
_client.OrdersUpdate(order);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `order` must contains an id or externalId")]
|
||||
public void OrdersUpdateIdArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> order = new Dictionary<string, object> {{"status", "cancel-other"}};
|
||||
_client.OrdersUpdate(order);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "You must set the array of `ids` or `externalIds`.")]
|
||||
public void OrdersStatusesArgumentExeption()
|
||||
{
|
||||
_client.OrdersStatuses(null);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Too many ids or externalIds. Maximum number of elements is 500")]
|
||||
public void OrdersStatusesLimitArgumentExeption()
|
||||
{
|
||||
List<string> ids = new List<string>();
|
||||
|
||||
for (int i = 0; i <= 501; i++)
|
||||
{
|
||||
ids.Add(i.ToString());
|
||||
}
|
||||
|
||||
_client.OrdersStatuses(ids);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `orders` must contains a data")]
|
||||
public void OrdersUploadEmptyOrdersArgumentExeption()
|
||||
{
|
||||
List<object> orders = new List<object>();
|
||||
_client.OrdersUpload(orders);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `orders` must contain 50 or less records")]
|
||||
public void OrdersUploadLimitArgumentExeption()
|
||||
{
|
||||
List<object> orders = new List<object>();
|
||||
|
||||
for (int i = 0; i < 51; i++)
|
||||
{
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", $"order-{i}" },
|
||||
{ "createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "lastName", $"Doe{i}" },
|
||||
{ "firstName", $"John{i}" },
|
||||
{ "email", $"john{i}@example.com" },
|
||||
{ "phone", $"+7999999999{i}" }
|
||||
};
|
||||
|
||||
orders.Add(order);
|
||||
}
|
||||
|
||||
_client.OrdersUpload(orders);
|
||||
}
|
||||
}
|
||||
}
|
183
RetailcrmUnitTest/V3/PacksTest.cs
Normal file
183
RetailcrmUnitTest/V3/PacksTest.cs
Normal file
@ -0,0 +1,183 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class PacksTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public PacksTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PacksCreateUpdateReadDelete()
|
||||
{
|
||||
string uid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12);
|
||||
|
||||
Dictionary<string, object> order = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", $"packs-test-{uid}" },
|
||||
{ "firstName", $"John_{uid}" },
|
||||
{ "lastName", $"Doe_{uid}"},
|
||||
{ "email", $"{uid}@example.com"},
|
||||
{
|
||||
"items", new List<object>
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "initialPrice", 500 },
|
||||
{ "quantity", 2},
|
||||
{ "productId", "_jAjMfjjgs6ukFxOiTE433"},
|
||||
{ "productName", "Test"}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Response orderCreateResponse = _client.OrdersCreate(order);
|
||||
|
||||
Assert.IsTrue(orderCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(orderCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(orderCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(orderCreateResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
Response orderGetResponse = _client.OrdersGet(orderCreateResponse.GetResponse()["id"].ToString(), "id");
|
||||
|
||||
Assert.IsTrue(orderGetResponse.IsSuccessfull());
|
||||
Assert.IsTrue(orderGetResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(orderGetResponse, typeof(Response));
|
||||
Assert.IsTrue(orderGetResponse.GetResponse().ContainsKey("order"));
|
||||
|
||||
Dictionary<string, object> orderFromResponse =
|
||||
(Dictionary<string, object>) orderGetResponse.GetResponse()["order"];
|
||||
|
||||
object[] arr = (object[])orderFromResponse["items"];
|
||||
int[] id = new int[1];
|
||||
|
||||
|
||||
foreach (Dictionary<string, object> s in arr.OfType<Dictionary<string, object>>())
|
||||
{
|
||||
int itemId;
|
||||
int.TryParse(s["id"].ToString(), NumberStyles.Any, null, out itemId);
|
||||
id[0] = itemId;
|
||||
}
|
||||
|
||||
Dictionary<string, object> pack = new Dictionary<string, object>
|
||||
{
|
||||
{ "purchasePrice", 100 },
|
||||
{ "quantity", 1},
|
||||
{ "store", _appSettings["store"]},
|
||||
{ "itemId", id[0]}
|
||||
};
|
||||
|
||||
Response packsCreateResponse = _client.PacksCreate(pack);
|
||||
|
||||
Assert.IsTrue(packsCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(packsCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(packsCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(packsCreateResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
string packId = packsCreateResponse.GetResponse()["id"].ToString();
|
||||
|
||||
Dictionary<string, object> packEdit = new Dictionary<string, object>
|
||||
{
|
||||
{ "id", packId },
|
||||
{ "quantity", 2}
|
||||
};
|
||||
|
||||
Response packsUpdateResponse = _client.PacksUpdate(packEdit);
|
||||
|
||||
Assert.IsTrue(packsUpdateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(packsUpdateResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(packsUpdateResponse, typeof(Response));
|
||||
Assert.IsTrue(packsUpdateResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
Response packsGetResponse = _client.PacksGet(packId);
|
||||
|
||||
Assert.IsTrue(packsGetResponse.IsSuccessfull());
|
||||
Assert.IsTrue(packsGetResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(packsGetResponse, typeof(Response));
|
||||
Assert.IsTrue(packsGetResponse.GetResponse().ContainsKey("pack"));
|
||||
|
||||
Response packsDeleteResponse = _client.PacksDelete(packId);
|
||||
|
||||
Assert.IsTrue(packsDeleteResponse.IsSuccessfull());
|
||||
Assert.IsTrue(packsDeleteResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(packsDeleteResponse, typeof(Response));
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PacksList()
|
||||
{
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "store", _appSettings["store"]}
|
||||
};
|
||||
|
||||
Response response = _client.PacksList(filter, 1, 100);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("packs"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PacksHistory()
|
||||
{
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "endDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
349
RetailcrmUnitTest/V3/ReferencesTest.cs
Normal file
349
RetailcrmUnitTest/V3/ReferencesTest.cs
Normal file
@ -0,0 +1,349 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class ReferencesTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public ReferencesTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Countries()
|
||||
{
|
||||
Response response = _client.Countries();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeliveryServices()
|
||||
{
|
||||
Response response = _client.DeliveryServices();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeliveryTypes()
|
||||
{
|
||||
Response response = _client.DeliveryTypes();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrderMethods()
|
||||
{
|
||||
Response response = _client.OrderMethods();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrderTypes()
|
||||
{
|
||||
Response response = _client.OrderTypes();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PaymentStatuses()
|
||||
{
|
||||
Response response = _client.PaymentStatuses();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PaymentTypes()
|
||||
{
|
||||
Response response = _client.PaymentTypes();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductStatuses()
|
||||
{
|
||||
Response response = _client.ProductStatuses();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Sites()
|
||||
{
|
||||
Response response = _client.Sites();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StatusGroups()
|
||||
{
|
||||
Response response = _client.StatusGroups();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Statuses()
|
||||
{
|
||||
Response response = _client.Statuses();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Stores()
|
||||
{
|
||||
Response response = _client.Stores();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeliveryServicesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.DeliveryServicesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestDeliveryService-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DeliveryTypesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.DeliveryTypesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestDeliveryType-{guid}" },
|
||||
{ "defaultCost", 300 },
|
||||
{ "defaultNetCost", 250}
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrderMethodsEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.OrderMethodsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestOrderMethod-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrderTypesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.OrderTypesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestOrderType-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PaymentStatusesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.PaymentStatusesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestPaymentStatus-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PaymentTypesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.PaymentTypesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestPaymentType-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProductStatusesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.ProductStatusesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestProductStatus-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SitesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.SitesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestProductStatus-{guid}" },
|
||||
{ "url", $"http://{guid}.example.org" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsFalse(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StatusesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.StatusesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestProductStatus-{guid}" },
|
||||
{ "ordering", 40},
|
||||
{ "group", "cancel"}
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StoresEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.StoresEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestProductStatus-{guid}" },
|
||||
{ "type", "store-type-warehouse"}
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
137
RetailcrmUnitTest/V3/StoresTest.cs
Normal file
137
RetailcrmUnitTest/V3/StoresTest.cs
Normal file
@ -0,0 +1,137 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class StoresTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public StoresTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void InventoriesUpload()
|
||||
{
|
||||
List<object> offers = new List<object>
|
||||
{
|
||||
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", 500 },
|
||||
{ "purchasePrice", 300}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
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", 600 },
|
||||
{ "purchasePrice", 350}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
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}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Response response = _client.StoreInventoriesUpload(offers);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("processedOffersCount"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Inventories()
|
||||
{
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "site", _appSettings["site"]},
|
||||
{ "details", 1}
|
||||
};
|
||||
|
||||
Response response = _client.StoreInventoriesGet(filter, 1, 50);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("offers"));
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
33
RetailcrmUnitTest/V3/TelephonyTest.cs
Normal file
33
RetailcrmUnitTest/V3/TelephonyTest.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V3;
|
||||
|
||||
namespace RetailcrmUnitTest.V3
|
||||
{
|
||||
[TestClass]
|
||||
public class TelephonyTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public TelephonyTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TelephonyManagerGet()
|
||||
{
|
||||
Response response = _client.TelephonyManagerGet(_appSettings["phone"]);
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
48
RetailcrmUnitTest/V4/CustomersTest.cs
Normal file
48
RetailcrmUnitTest/V4/CustomersTest.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class CustomersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public CustomersTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomersHistory()
|
||||
{
|
||||
Response response = _client.CustomersHistory();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("history"));
|
||||
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
Response responseFiltered = _client.CustomersHistory(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "startDate", datetime.AddMonths(-2).ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "endDate", datetime.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("history"));
|
||||
}
|
||||
}
|
||||
}
|
43
RetailcrmUnitTest/V4/MarketplaceTest.cs
Normal file
43
RetailcrmUnitTest/V4/MarketplaceTest.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class MarketplaceTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public MarketplaceTest()
|
||||
{
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MarketplaceSettingsEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.MarketplaceSettingsEdit(
|
||||
new Dictionary<string, object>()
|
||||
{
|
||||
{ "name", $"MarketplaceApp-{guid}" },
|
||||
{ "code", guid},
|
||||
{ "configurationUrl", $"http://{guid}.example.com"},
|
||||
{ "active", false}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
41
RetailcrmUnitTest/V4/OrdersTest.cs
Normal file
41
RetailcrmUnitTest/V4/OrdersTest.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class OrdersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public OrdersTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersHistory()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
Dictionary<string, object> filter = new Dictionary<string, object>
|
||||
{
|
||||
{ "startDate", datetime.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") },
|
||||
{ "endDate", datetime.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss")}
|
||||
};
|
||||
|
||||
Response response = _client.OrdersHistory(filter, 1, 50);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("history"));
|
||||
}
|
||||
}
|
||||
}
|
52
RetailcrmUnitTest/V4/ReferencesTest.cs
Normal file
52
RetailcrmUnitTest/V4/ReferencesTest.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.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"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PriceTypesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.PriceTypesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestPriceType-{guid}" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
37
RetailcrmUnitTest/V4/StoresTest.cs
Normal file
37
RetailcrmUnitTest/V4/StoresTest.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class StoresTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public StoresTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"], _appSettings["site"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void StoreProducts()
|
||||
{
|
||||
Response response = _client.StoreProducts();
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("products"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
84
RetailcrmUnitTest/V4/TelephonyTest.cs
Normal file
84
RetailcrmUnitTest/V4/TelephonyTest.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class TelephonyTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
private readonly string _phoneCode = "100";
|
||||
private readonly string _logoUrl = "http://www.onsitemaintenance.com/img/voip.svg";
|
||||
private readonly string _telephonyCode = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
public TelephonyTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TelephonySettingsEdit()
|
||||
{
|
||||
Response response = _client.TelephonySettingsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
|
||||
{ "code", _telephonyCode},
|
||||
{ "clientId", _appSettings["customer"] },
|
||||
{ "makeCallUrl", $"http://{_telephonyCode}.example.com/call"},
|
||||
{ "name", $"TestTelephony-{_telephonyCode}"},
|
||||
{ "image", _logoUrl},
|
||||
{ "inputEventSupported", true},
|
||||
{ "outputEventSupported", true},
|
||||
{ "hangupEventSupported", true},
|
||||
{
|
||||
"additionalCodes",
|
||||
new List<object>
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "userId", _appSettings["manager"] },
|
||||
{ "code", _phoneCode }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TelephonyCallEvent()
|
||||
{
|
||||
Response response = _client.TelephonyCallEvent(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "phone", _appSettings["phone"] },
|
||||
{ "type", "in" },
|
||||
{ "hangupStatus", "failed"},
|
||||
{ "codes", new List<string> { _phoneCode }},
|
||||
{ "userIds", new List<int> { int.Parse(_appSettings["customer"]) }}
|
||||
}
|
||||
|
||||
);
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
41
RetailcrmUnitTest/V4/UsersTest.cs
Normal file
41
RetailcrmUnitTest/V4/UsersTest.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V4;
|
||||
|
||||
namespace RetailcrmUnitTest.V4
|
||||
{
|
||||
[TestClass]
|
||||
public class UsersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public UsersTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UsersGroups()
|
||||
{
|
||||
Response usersGroups = _client.UsersGroups();
|
||||
Assert.IsTrue(usersGroups.IsSuccessfull());
|
||||
Assert.IsTrue(usersGroups.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(usersGroups, typeof(Response));
|
||||
Assert.IsTrue(usersGroups.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void User()
|
||||
{
|
||||
Response usersGroups = _client.User(int.Parse(_appSettings["manager"]));
|
||||
Assert.IsTrue(usersGroups.IsSuccessfull());
|
||||
Assert.IsTrue(usersGroups.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(usersGroups, typeof(Response));
|
||||
Assert.IsTrue(usersGroups.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
226
RetailcrmUnitTest/V5/CostsTest.cs
Normal file
226
RetailcrmUnitTest/V5/CostsTest.cs
Normal file
@ -0,0 +1,226 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class CostsTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public CostsTest()
|
||||
{
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostsCreateUpdateReadDelete()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response groupResponse = _client.CostGroupsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", groupGuid},
|
||||
{ "name", $"TestCostGroup-{groupGuid}" },
|
||||
{ "color", "#60b29a" }
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(groupResponse.GetRawResponse());
|
||||
Assert.IsTrue(groupResponse.IsSuccessfull());
|
||||
Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(groupResponse, typeof(Response));
|
||||
Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response itemCostResponse = _client.CostItemsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "group", groupGuid },
|
||||
{ "name", $"TestCostItem-{guid}" },
|
||||
{ "type", "const" }
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(itemCostResponse.GetRawResponse());
|
||||
Assert.IsTrue(itemCostResponse.IsSuccessfull());
|
||||
Assert.IsTrue(itemCostResponse.GetStatusCode() == 200 || itemCostResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(itemCostResponse, typeof(Response));
|
||||
Assert.IsTrue(itemCostResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response costsCreateResponse = _client.CostsCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "summ", 20000 },
|
||||
{ "comment", "test cost" },
|
||||
{ "costItem", guid },
|
||||
{ "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")},
|
||||
{ "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")},
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(costsCreateResponse.GetRawResponse());
|
||||
Assert.IsTrue(costsCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(costsCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(costsCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(costsCreateResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response costsUpdateResponse = _client.CostsUpdate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "id", costsCreateResponse.GetResponse()["id"].ToString()},
|
||||
{ "summ", 30000 },
|
||||
{ "comment", "test cost update" },
|
||||
{ "costItem", guid },
|
||||
{ "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")},
|
||||
{ "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")},
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(costsUpdateResponse.GetRawResponse());
|
||||
Assert.IsTrue(costsUpdateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(costsUpdateResponse.GetStatusCode() == 200 || costsUpdateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(costsUpdateResponse, typeof(Response));
|
||||
Assert.IsTrue(costsUpdateResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response responseGet = _client.CostsGet(int.Parse(costsCreateResponse.GetResponse()["id"].ToString()));
|
||||
|
||||
Debug.WriteLine(responseGet.GetRawResponse());
|
||||
Assert.IsTrue(responseGet.IsSuccessfull());
|
||||
Assert.IsTrue(responseGet.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseGet, typeof(Response));
|
||||
Assert.IsTrue(responseGet.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response response = _client.CostsDelete(costsCreateResponse.GetResponse()["id"].ToString());
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostsList()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
Response responseFiltered = _client.CostsList(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "createdAtFrom", datetime.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss") }
|
||||
},
|
||||
2,
|
||||
50
|
||||
);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("costs"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostsUploadDelete()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response groupResponse = _client.CostGroupsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", groupGuid},
|
||||
{ "name", $"TestCostGroup-{groupGuid}" },
|
||||
{ "color", "#60b29a" }
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(groupResponse.GetRawResponse());
|
||||
Assert.IsTrue(groupResponse.IsSuccessfull());
|
||||
Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(groupResponse, typeof(Response));
|
||||
Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response itemCostResponse = _client.CostItemsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "group", groupGuid },
|
||||
{ "name", $"TestCostItem-{guid}" },
|
||||
{ "type", "const" }
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(itemCostResponse.GetRawResponse());
|
||||
Assert.IsTrue(itemCostResponse.IsSuccessfull());
|
||||
Assert.IsTrue(itemCostResponse.GetStatusCode() == 200 || itemCostResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(itemCostResponse, typeof(Response));
|
||||
Assert.IsTrue(itemCostResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response costsUploadResponse = _client.CostsUpload(
|
||||
new List<object>
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "summ", 10000 },
|
||||
{ "comment", "test cost 1" },
|
||||
{ "costItem", guid },
|
||||
{ "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")},
|
||||
{ "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")},
|
||||
},
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "summ", 20000 },
|
||||
{ "comment", "test cost 2" },
|
||||
{ "costItem", guid },
|
||||
{ "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")},
|
||||
{ "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")},
|
||||
},
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "summ", 30000 },
|
||||
{ "comment", "test cost 3" },
|
||||
{ "costItem", guid },
|
||||
{ "dateFrom", datetime.AddDays(-3).ToString("yyyy-MM-dd")},
|
||||
{ "dateTo", datetime.AddDays(+3).ToString("yyyy-MM-dd")},
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(costsUploadResponse.GetRawResponse());
|
||||
Assert.IsTrue(costsUploadResponse.IsSuccessfull());
|
||||
Assert.IsTrue(costsUploadResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(costsUploadResponse, typeof(Response));
|
||||
Assert.IsTrue(costsUploadResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
List<string> uploadedCosts = new List<string>();
|
||||
object[] uids = (object[]) costsUploadResponse.GetResponse()["uploadedCosts"];
|
||||
|
||||
foreach (var uid in uids)
|
||||
{
|
||||
uploadedCosts.Add(uid.ToString());
|
||||
}
|
||||
|
||||
Response costsDeleteResponse = _client.CostsDelete(uploadedCosts);
|
||||
|
||||
Debug.WriteLine(costsDeleteResponse.GetRawResponse());
|
||||
Assert.IsTrue(costsDeleteResponse.IsSuccessfull());
|
||||
Assert.IsTrue(costsDeleteResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(costsUploadResponse, typeof(Response));
|
||||
Assert.IsTrue(costsUploadResponse.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
163
RetailcrmUnitTest/V5/CustomFieldsTest.cs
Normal file
163
RetailcrmUnitTest/V5/CustomFieldsTest.cs
Normal file
@ -0,0 +1,163 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class CustomFieldsTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public CustomFieldsTest()
|
||||
{
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomFieldsList()
|
||||
{
|
||||
Response responseFiltered = _client.CustomFieldsList(new Dictionary<string, object> { { "entity", "order" } }, 2, 50);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("customFields"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomFieldsCreateUpdateRead()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response customFieldsCreateResponse = _client.CustomFieldsCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customfield{guid}" },
|
||||
{ "name", $"CustomField-{guid}"},
|
||||
{ "type", "string"},
|
||||
{ "entity", "order"}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(customFieldsCreateResponse.GetRawResponse());
|
||||
Assert.IsTrue(customFieldsCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customFieldsCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(customFieldsCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(customFieldsCreateResponse.GetResponse().ContainsKey("code"));
|
||||
|
||||
Response customFieldGetResponse = _client.CustomFieldsGet($"customfield{guid}", "order");
|
||||
|
||||
Debug.WriteLine(customFieldGetResponse.GetRawResponse());
|
||||
Assert.IsTrue(customFieldGetResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customFieldGetResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(customFieldGetResponse, typeof(Response));
|
||||
Assert.IsTrue(customFieldGetResponse.GetResponse().ContainsKey("customField"));
|
||||
|
||||
Response customFieldsUpdateResponse = _client.CustomFieldsUpdate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customfield{guid}" },
|
||||
{ "name", $"CustomField-{guid}"},
|
||||
{ "type", "string"},
|
||||
{ "entity", "order"},
|
||||
{ "inList", false}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(customFieldsUpdateResponse.GetRawResponse());
|
||||
Assert.IsTrue(customFieldsUpdateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customFieldsUpdateResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(customFieldsUpdateResponse, typeof(Response));
|
||||
Assert.IsTrue(customFieldsUpdateResponse.GetResponse().ContainsKey("code"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomDictionaryList()
|
||||
{
|
||||
Response responseFiltered = _client.CustomDictionaryList(new Dictionary<string, object>(), 2, 50);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("customDictionaries"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CustomDictionariesCreateUpdateRead()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
string fuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response customDictionaryCreateResponse = _client.CustomDictionaryCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customdict{guid}" },
|
||||
{ "name", $"CustomDict-{guid}"},
|
||||
{
|
||||
"elements",
|
||||
new List<object>
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customdictelement-{fuid}" },
|
||||
{ "name", $"CustomDictElement-{fuid}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(customDictionaryCreateResponse.GetRawResponse());
|
||||
Assert.IsTrue(customDictionaryCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customDictionaryCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(customDictionaryCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(customDictionaryCreateResponse.GetResponse().ContainsKey("code"));
|
||||
|
||||
Response customDictionaryGetResponse = _client.CustomDictionaryGet(customDictionaryCreateResponse.GetResponse()["code"].ToString());
|
||||
|
||||
Debug.WriteLine(customDictionaryGetResponse.GetRawResponse());
|
||||
Assert.IsTrue(customDictionaryGetResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customDictionaryGetResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(customDictionaryGetResponse, typeof(Response));
|
||||
Assert.IsTrue(customDictionaryGetResponse.GetResponse().ContainsKey("customDictionary"));
|
||||
|
||||
Response customDictionaryEditResponse = _client.CustomDictionaryUpdate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customdict{guid}" },
|
||||
{ "name", $"CustomDict-{guid}Edited"},
|
||||
{
|
||||
"elements",
|
||||
new List<object>
|
||||
{
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customdictelement-{fuid}" },
|
||||
{ "name", $"CustomDictElement-{fuid}" }
|
||||
},
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", $"customdictelement-{fuid}1" },
|
||||
{ "name", $"CustomDictElement-{fuid}1" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(customDictionaryEditResponse.GetRawResponse());
|
||||
Assert.IsTrue(customDictionaryEditResponse.IsSuccessfull());
|
||||
Assert.IsTrue(customDictionaryEditResponse.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(customDictionaryEditResponse, typeof(Response));
|
||||
Assert.IsTrue(customDictionaryEditResponse.GetResponse().ContainsKey("code"));
|
||||
}
|
||||
}
|
||||
}
|
51
RetailcrmUnitTest/V5/IntegrationTest.cs
Normal file
51
RetailcrmUnitTest/V5/IntegrationTest.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class IntegrationTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public IntegrationTest()
|
||||
{
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IntegrationsSettingsEditSettingsGet()
|
||||
{
|
||||
string uid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.IntegrationsSettingsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", uid},
|
||||
{ "name", $"TestIntegration-{uid}"},
|
||||
{ "active", true},
|
||||
{ "accountUrl", $"http://{uid}.example.com"},
|
||||
{ "logo", "https://www.ibm.com/cloud-computing/images/cloud/products/cloud-integration/api-economy-icon.svg"},
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response responseGet = _client.IntegrationsSettingGet(uid);
|
||||
|
||||
Debug.WriteLine(responseGet.GetRawResponse());
|
||||
Assert.IsTrue(responseGet.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(responseGet, typeof(Response));
|
||||
Assert.IsTrue(responseGet.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
72
RetailcrmUnitTest/V5/NotesTest.cs
Normal file
72
RetailcrmUnitTest/V5/NotesTest.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class NotesTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public NotesTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NotesCreateDelete()
|
||||
{
|
||||
Response responseFiltered = _client.NotesCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "text", "test task" },
|
||||
{ "customer", new Dictionary<string, object> { { "id", "2015" } }},
|
||||
{ "managerId", _appSettings["manager"]}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response response = _client.NotesDelete(responseFiltered.GetResponse()["id"].ToString());
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NotesList()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
Response responseFiltered = _client.NotesList(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "createdAtFrom", datetime.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss") }
|
||||
},
|
||||
2,
|
||||
50
|
||||
);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("notes"));
|
||||
}
|
||||
}
|
||||
}
|
140
RetailcrmUnitTest/V5/OrdersTest.cs
Normal file
140
RetailcrmUnitTest/V5/OrdersTest.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class OrdersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public OrdersTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void OrdersCombine()
|
||||
{
|
||||
Dictionary<string, object> firstOrder = new Dictionary<string, object>
|
||||
{
|
||||
{"number", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
|
||||
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Doe"},
|
||||
{"firstName", "John"},
|
||||
{"email", $"{Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}@example.com"},
|
||||
{"phone", "+79999999999"}
|
||||
};
|
||||
|
||||
|
||||
Response createFirstResponse = _client.OrdersCreate(firstOrder);
|
||||
Assert.IsTrue(createFirstResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createFirstResponse, typeof(Response));
|
||||
Assert.IsTrue(createFirstResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
string firstId = createFirstResponse.GetResponse()["id"].ToString();
|
||||
|
||||
Dictionary<string, object> secondOrder = new Dictionary<string, object>
|
||||
{
|
||||
{"number", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)},
|
||||
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Doe"},
|
||||
{"firstName", "John"},
|
||||
{"email", $"{Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12)}@example.com"},
|
||||
{"phone", "+79999999999"}
|
||||
};
|
||||
|
||||
|
||||
Response createSecondResponse = _client.OrdersCreate(secondOrder);
|
||||
Assert.IsTrue(createSecondResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createSecondResponse, typeof(Response));
|
||||
Assert.IsTrue(createSecondResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
string secondId = createSecondResponse.GetResponse()["id"].ToString();
|
||||
|
||||
Dictionary<string, object> firstCombineOrder = new Dictionary<string, object>
|
||||
{
|
||||
{"id", firstId }
|
||||
};
|
||||
|
||||
Dictionary<string, object> secondCombineOrder = new Dictionary<string, object>
|
||||
{
|
||||
{"id", secondId }
|
||||
};
|
||||
|
||||
Response combineResponse = _client.OrdersCombine(firstCombineOrder, secondCombineOrder);
|
||||
|
||||
Debug.WriteLine(combineResponse.GetRawResponse());
|
||||
|
||||
Assert.IsTrue(combineResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(combineResponse, typeof(Response));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `order` must contains a data")]
|
||||
public void OrdersCombineEmptyOrderArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> firstOrder = new Dictionary<string, object>();
|
||||
Dictionary<string, object> secondOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "id", "111" }
|
||||
};
|
||||
|
||||
_client.OrdersCombine(firstOrder, secondOrder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `resultOrder` must contains a data")]
|
||||
public void OrdersCombineEmptyResultOrderArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> secondOrder = new Dictionary<string, object>();
|
||||
Dictionary<string, object> firstOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "id", "111" }
|
||||
};
|
||||
|
||||
_client.OrdersCombine(firstOrder, secondOrder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `order` must contains `id` key")]
|
||||
public void OrdersCombineEmptyIdOrderArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> firstOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12) }
|
||||
};
|
||||
|
||||
Dictionary<string, object> secondOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "id", "111" }
|
||||
};
|
||||
|
||||
_client.OrdersCombine(firstOrder, secondOrder);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "Parameter `resultOrder` must contains `id` key")]
|
||||
public void OrdersCombineEmptyIdResultOrderArgumentExeption()
|
||||
{
|
||||
Dictionary<string, object> secondOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "number", Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 12) }
|
||||
};
|
||||
|
||||
Dictionary<string, object> firstOrder = new Dictionary<string, object>
|
||||
{
|
||||
{ "id", "111" }
|
||||
};
|
||||
|
||||
_client.OrdersCombine(firstOrder, secondOrder);
|
||||
}
|
||||
}
|
||||
}
|
83
RetailcrmUnitTest/V5/PaymentsTest.cs
Normal file
83
RetailcrmUnitTest/V5/PaymentsTest.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class PaymentsTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public PaymentsTest()
|
||||
{
|
||||
var appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void PaymentsCreateUpdateDelete()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response createResponse = _client.OrdersCreate(new Dictionary<string, object>
|
||||
{
|
||||
{"externalId", guid},
|
||||
{"createdAt", datetime.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{"lastName", "Doe"},
|
||||
{"firstName", "John"},
|
||||
{"email", "john@example.com"},
|
||||
{"phone", "+79999999999"}
|
||||
});
|
||||
|
||||
Debug.WriteLine(createResponse.GetRawResponse());
|
||||
Assert.IsTrue(createResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(createResponse, typeof(Response));
|
||||
Assert.IsTrue(createResponse.GetResponse().ContainsKey("id"));
|
||||
|
||||
Response paymentCreateResponse = _client.PaymentsCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "externalId", guid },
|
||||
{ "type", "cash" },
|
||||
{ "comment", "test payment" },
|
||||
{ "order", new Dictionary<string, object> { { "id", createResponse.GetResponse()["id"].ToString() } } },
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(paymentCreateResponse.GetRawResponse());
|
||||
Assert.IsTrue(paymentCreateResponse.IsSuccessfull());
|
||||
Assert.IsTrue(paymentCreateResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(paymentCreateResponse, typeof(Response));
|
||||
Assert.IsTrue(paymentCreateResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response paymentUpdateResponse = _client.PaymentsUpdate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "id", paymentCreateResponse.GetResponse()["id"].ToString()},
|
||||
{ "status", "paid"},
|
||||
{ "paidAt", datetime.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{ "amount", 4000 }
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(paymentUpdateResponse.GetRawResponse());
|
||||
Assert.IsTrue(paymentUpdateResponse.IsSuccessfull());
|
||||
Assert.IsInstanceOfType(paymentUpdateResponse, typeof(Response));
|
||||
Assert.IsTrue(paymentUpdateResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response response = _client.PaymentsDelete(paymentCreateResponse.GetResponse()["id"].ToString());
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
133
RetailcrmUnitTest/V5/ReferencesTest.cs
Normal file
133
RetailcrmUnitTest/V5/ReferencesTest.cs
Normal file
@ -0,0 +1,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.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"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostItems()
|
||||
{
|
||||
Response response = _client.CostItems();
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("costItems"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LegalEntities()
|
||||
{
|
||||
Response response = _client.LegalEntities();
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("legalEntities"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostGroupsEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.CostGroupsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "name", $"TestCostGroup-{guid}" },
|
||||
{ "color", "#da5c98" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CostItemsEdit()
|
||||
{
|
||||
string groupGuid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response groupResponse = _client.CostGroupsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", groupGuid},
|
||||
{ "name", $"TestCostGroup-{groupGuid}" },
|
||||
{ "color", "#60b29a" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(groupResponse.IsSuccessfull());
|
||||
Assert.IsTrue(groupResponse.GetStatusCode() == 200 || groupResponse.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(groupResponse, typeof(Response));
|
||||
Assert.IsTrue(groupResponse.GetResponse().ContainsKey("success"));
|
||||
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.CostItemsEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "group", groupGuid },
|
||||
{ "name", $"TestCostItem-{guid}" },
|
||||
{ "type", "const" }
|
||||
}
|
||||
);
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void LegalEntitiesEdit()
|
||||
{
|
||||
string guid = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 6);
|
||||
|
||||
Response response = _client.LegalEntitiesEdit(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "code", guid},
|
||||
{ "legalName", $"Test LegalEntity-{guid}" },
|
||||
{ "contragentType", "legal-entity"},
|
||||
{ "countryIso", "RU"}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200 || response.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
39
RetailcrmUnitTest/V5/SegmentsTest.cs
Normal file
39
RetailcrmUnitTest/V5/SegmentsTest.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class SegmentsTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public SegmentsTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Segments()
|
||||
{
|
||||
Response responseFiltered = _client.Segments(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "active", "1" }
|
||||
},
|
||||
2,
|
||||
50
|
||||
);
|
||||
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("segments"));
|
||||
}
|
||||
}
|
||||
}
|
91
RetailcrmUnitTest/V5/TasksTest.cs
Normal file
91
RetailcrmUnitTest/V5/TasksTest.cs
Normal file
@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class TasksTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public TasksTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TasksCreateUpdateGet()
|
||||
{
|
||||
DateTime datetime = DateTime.Now;
|
||||
|
||||
Response responseFiltered = _client.TasksCreate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "text", "test task" },
|
||||
{ "commentary", "test commentary"},
|
||||
{ "datetime", datetime.AddHours(+3).ToString("yyyy-MM-dd HH:mm")},
|
||||
{ "performerId", _appSettings["manager"]}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 201);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response response = _client.TasksUpdate(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "id", responseFiltered.GetResponse()["id"].ToString()},
|
||||
{ "text", "test task edited" },
|
||||
{ "commentary", "test commentary"},
|
||||
{ "datetime", datetime.AddHours(+4).ToString("yyyy-MM-dd HH:mm")},
|
||||
{ "performerId", _appSettings["manager"]}
|
||||
}
|
||||
);
|
||||
|
||||
Debug.WriteLine(response.GetRawResponse());
|
||||
Assert.IsTrue(response.IsSuccessfull());
|
||||
Assert.IsTrue(response.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(response, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
|
||||
Response responseGet = _client.TasksGet(responseFiltered.GetResponse()["id"].ToString());
|
||||
|
||||
Debug.WriteLine(responseGet.GetRawResponse());
|
||||
Assert.IsTrue(responseGet.IsSuccessfull());
|
||||
Assert.IsTrue(responseGet.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseGet, typeof(Response));
|
||||
Assert.IsTrue(response.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TasksList()
|
||||
{
|
||||
Response responseFiltered = _client.TasksList(
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ "performers", new List<string> { _appSettings["manager"] } },
|
||||
{ "status", "performing" }
|
||||
},
|
||||
2,
|
||||
50
|
||||
);
|
||||
|
||||
Debug.WriteLine(responseFiltered.GetRawResponse());
|
||||
Assert.IsTrue(responseFiltered.IsSuccessfull());
|
||||
Assert.IsTrue(responseFiltered.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(responseFiltered, typeof(Response));
|
||||
Assert.IsTrue(responseFiltered.GetResponse().ContainsKey("tasks"));
|
||||
}
|
||||
}
|
||||
}
|
36
RetailcrmUnitTest/V5/TelephonyTest.cs
Normal file
36
RetailcrmUnitTest/V5/TelephonyTest.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class TelephonyTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
private readonly NameValueCollection _appSettings;
|
||||
|
||||
public TelephonyTest()
|
||||
{
|
||||
_appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(_appSettings["apiUrl"], _appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "This method is unavailable in API V5")]
|
||||
public void TelephonySettingsGetArgumentExeption()
|
||||
{
|
||||
_client.TelephonySettingsGet("anycode");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(ArgumentException), "This method is unavailable in API V5")]
|
||||
public void TelephonySettingsGetTelephonySettingsEditArgumentExeption()
|
||||
{
|
||||
_client.TelephonySettingsEdit(new Dictionary<string, object>());
|
||||
}
|
||||
}
|
||||
}
|
43
RetailcrmUnitTest/V5/UsersTest.cs
Normal file
43
RetailcrmUnitTest/V5/UsersTest.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Retailcrm;
|
||||
using Retailcrm.Versions.V5;
|
||||
|
||||
namespace RetailcrmUnitTest.V5
|
||||
{
|
||||
[TestClass]
|
||||
public class UsersTest
|
||||
{
|
||||
private readonly Client _client;
|
||||
|
||||
public UsersTest()
|
||||
{
|
||||
NameValueCollection appSettings = ConfigurationManager.AppSettings;
|
||||
_client = new Client(appSettings["apiUrl"], appSettings["apiKey"]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UsersStatus()
|
||||
{
|
||||
Response users = _client.Users();
|
||||
Assert.IsTrue(users.IsSuccessfull());
|
||||
Assert.IsTrue(users.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(users, typeof(Response));
|
||||
Assert.IsTrue(users.GetResponse().ContainsKey("success"));
|
||||
|
||||
object[] list = (object[])users.GetResponse()["users"];
|
||||
var user = list[0] as Dictionary<string, object>;
|
||||
Debug.Assert(user != null, nameof(user) + " != null");
|
||||
int uid = int.Parse(user["id"].ToString());
|
||||
|
||||
Response status = _client.UsersStatus(uid, "break");
|
||||
Assert.IsTrue(status.IsSuccessfull());
|
||||
Assert.IsTrue(status.GetStatusCode() == 200);
|
||||
Assert.IsInstanceOfType(status, typeof(Response));
|
||||
Assert.IsTrue(status.GetResponse().ContainsKey("success"));
|
||||
}
|
||||
}
|
||||
}
|
5
RetailcrmUnitTest/packages.config
Normal file
5
RetailcrmUnitTest/packages.config
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MSTest.TestAdapter" version="1.1.18" targetFramework="net45" />
|
||||
<package id="MSTest.TestFramework" version="1.1.18" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user