mirror of
https://github.com/retailcrm/api-client-dotnet.git
synced 2024-11-21 20:36:02 +03:00
Merge pull request #4 from dmamontov/master
fix deserialize json && add new methods
This commit is contained in:
commit
596b2a9960
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
.NET-клиент для работы с [RetailCRM API](http://www.retailcrm.ru/docs/rest-api/index.html).
|
.NET-клиент для работы с [RetailCRM API](http://www.retailcrm.ru/docs/rest-api/index.html).
|
||||||
|
|
||||||
version: 3.0.2
|
version: 3.0.4
|
||||||
|
|
||||||
Обязательные требования
|
Обязательные требования
|
||||||
-----------------------
|
-----------------------
|
||||||
@ -82,7 +82,7 @@ catch (WebException e)
|
|||||||
Dictionary<string, object> tmpOrder = new Dictionary<string, object>(){
|
Dictionary<string, object> tmpOrder = new Dictionary<string, object>(){
|
||||||
{"number", "example"},
|
{"number", "example"},
|
||||||
{"externalId", "example"},
|
{"externalId", "example"},
|
||||||
{"createdAt", DateTime.Now.ToString("Y-m-d H:i:s")},
|
{"createdAt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||||
{"discount", 50},
|
{"discount", 50},
|
||||||
{"phone", "89263832233"},
|
{"phone", "89263832233"},
|
||||||
{"email", "example@gmail.com"},
|
{"email", "example@gmail.com"},
|
||||||
|
@ -4,8 +4,6 @@ using RetailCrm.Response;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace RetailCrm
|
namespace RetailCrm
|
||||||
{
|
{
|
||||||
@ -682,6 +680,15 @@ namespace RetailCrm
|
|||||||
return client.makeRequest("/reference/stores", Client.METHOD_GET);
|
return client.makeRequest("/reference/stores", Client.METHOD_GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns countries list
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>ApiResponse</returns>
|
||||||
|
public ApiResponse countriesList()
|
||||||
|
{
|
||||||
|
return client.makeRequest("/reference/countries", Client.METHOD_GET);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Edit deliveryService
|
/// Edit deliveryService
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -892,6 +899,118 @@ namespace RetailCrm
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Captures events call for the user
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="phone"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="code"></param>
|
||||||
|
/// <param name="hangupStatus"></param>
|
||||||
|
/// <returns>ApiResponse</returns>
|
||||||
|
public ApiResponse telephonyСallEventCreate(string phone, string type, string code, string hangupStatus)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(phone))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Parameter \"phone\" can not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(type))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Option \"type\" can not be empty. Valid values: in, out, hangup.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(code))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Option \"code\" can not be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters.Add("phone", phone);
|
||||||
|
parameters.Add("type", type);
|
||||||
|
parameters.Add("code", code);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(hangupStatus))
|
||||||
|
{
|
||||||
|
parameters.Add("hangupStatus", hangupStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.makeRequest("/telephony/call/event", Client.METHOD_POST, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// It allows you to save your call history
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="calls"></param>
|
||||||
|
/// <returns>ApiResponse</returns>
|
||||||
|
public ApiResponse telephonyСallsUpload(Dictionary<string, object> calls)
|
||||||
|
{
|
||||||
|
return client.makeRequest(
|
||||||
|
"/telephony/calls/upload",
|
||||||
|
Client.METHOD_POST,
|
||||||
|
new Dictionary<string, object>() {
|
||||||
|
{ "calls", JsonConvert.SerializeObject(calls) }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the responsible manager for the client with the phone
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="phone"></param>
|
||||||
|
/// <param name="details"></param>
|
||||||
|
/// <returns>ApiResponse</returns>
|
||||||
|
public ApiResponse telephonyManagerGet(string phone, bool details = false)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(phone))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Parameter \"phone\" can not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.makeRequest(
|
||||||
|
"/telephony/manager",
|
||||||
|
Client.METHOD_GET,
|
||||||
|
new Dictionary<string, object>() {
|
||||||
|
{ "phone", phone },
|
||||||
|
{ "details", details }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Allows you to create/activate/deactivate the phone in the system and specify the necessary settings for the job
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="code"></param>
|
||||||
|
/// <param name="clientId"></param>
|
||||||
|
/// <param name="makeCallUrl"></param>
|
||||||
|
/// <param name="active"></param>
|
||||||
|
/// <returns>ApiResponse</returns>
|
||||||
|
public ApiResponse telephonySettingEdit(string code, string clientId, string makeCallUrl, bool active = true)
|
||||||
|
{
|
||||||
|
Dictionary<string, object> parameters = new Dictionary<string, object>();
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(code))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Parameter \"code\" can not be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(clientId))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Option \"clientId\" can not be empty.");
|
||||||
|
}
|
||||||
|
|
||||||
|
parameters.Add("code", code);
|
||||||
|
parameters.Add("clientId", clientId);
|
||||||
|
parameters.Add("active", active);
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(makeCallUrl))
|
||||||
|
{
|
||||||
|
parameters.Add("makeCallUrl", makeCallUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.makeRequest("/telephony/setting/" + code, Client.METHOD_POST, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update CRM basic statistic
|
/// Update CRM basic statistic
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace RetailCrm.Extra
|
namespace RetailCrm.Extra
|
||||||
{
|
{
|
||||||
@ -61,30 +57,38 @@ namespace RetailCrm.Extra
|
|||||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||||
foreach (KeyValuePair<string, object> kvp in data)
|
foreach (KeyValuePair<string, object> kvp in data)
|
||||||
{
|
{
|
||||||
System.Console.WriteLine(kvp.Key.ToString());
|
|
||||||
System.Console.WriteLine(kvp.Value.ToString());
|
|
||||||
System.Console.ReadLine();
|
|
||||||
object valueObj = kvp.Value;
|
object valueObj = kvp.Value;
|
||||||
string value = String.Empty;
|
string value = String.Empty;
|
||||||
|
|
||||||
if (valueObj.GetType() == typeof(JArray))
|
value = valueObj.ToString();
|
||||||
{
|
|
||||||
string tmpValue = JsonConvert.SerializeObject(((JArray)valueObj).ToArray<dynamic>());
|
|
||||||
char[] charsToTrim = { '[', ' ', ']'};
|
|
||||||
value = tmpValue.Trim(charsToTrim);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
value = valueObj.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value != "")
|
if (value != "")
|
||||||
{
|
{
|
||||||
if (valueObj.GetType() == typeof(JObject) || valueObj.GetType() == typeof(JArray))
|
if (valueObj.GetType() == typeof(JObject))
|
||||||
{
|
{
|
||||||
valueObj = jsonObjectToDictionary((Dictionary<string, object>)JsonConvert.DeserializeObject<Dictionary<string, object>>(value));
|
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);
|
||||||
}
|
}
|
||||||
result.Add(kvp.Key.ToString(), valueObj);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user