diff --git a/README.md b/README.md index cc3b641..727105c 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ .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 tmpOrder = new Dictionary(){ {"number", "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}, {"phone", "89263832233"}, {"email", "example@gmail.com"}, diff --git a/RetailCrm/ApiClient.cs b/RetailCrm/ApiClient.cs index 12dda5c..20fd743 100644 --- a/RetailCrm/ApiClient.cs +++ b/RetailCrm/ApiClient.cs @@ -4,8 +4,6 @@ using RetailCrm.Response; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace RetailCrm { @@ -682,6 +680,15 @@ namespace RetailCrm return client.makeRequest("/reference/stores", Client.METHOD_GET); } + /// + /// Returns countries list + /// + /// ApiResponse + public ApiResponse countriesList() + { + return client.makeRequest("/reference/countries", Client.METHOD_GET); + } + /// /// Edit deliveryService /// @@ -892,6 +899,118 @@ namespace RetailCrm ); } + /// + /// Captures events call for the user + /// + /// + /// + /// + /// + /// ApiResponse + public ApiResponse telephonyСallEventCreate(string phone, string type, string code, string hangupStatus) + { + Dictionary parameters = new Dictionary(); + + 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); + } + + /// + /// It allows you to save your call history + /// + /// + /// ApiResponse + public ApiResponse telephonyСallsUpload(Dictionary calls) + { + return client.makeRequest( + "/telephony/calls/upload", + Client.METHOD_POST, + new Dictionary() { + { "calls", JsonConvert.SerializeObject(calls) } + } + ); + } + + /// + /// Returns the responsible manager for the client with the phone + /// + /// + /// + /// ApiResponse + 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() { + { "phone", phone }, + { "details", details } + } + ); + } + + /// + /// Allows you to create/activate/deactivate the phone in the system and specify the necessary settings for the job + /// + /// + /// + /// + /// + /// ApiResponse + public ApiResponse telephonySettingEdit(string code, string clientId, string makeCallUrl, bool active = true) + { + Dictionary parameters = new Dictionary(); + + 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); + } + /// /// Update CRM basic statistic /// diff --git a/RetailCrm/Extra/Tools.cs b/RetailCrm/Extra/Tools.cs index 16180f6..a0f8c0e 100644 --- a/RetailCrm/Extra/Tools.cs +++ b/RetailCrm/Extra/Tools.cs @@ -1,11 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace RetailCrm.Extra { @@ -61,30 +57,38 @@ namespace RetailCrm.Extra Dictionary result = new Dictionary(); foreach (KeyValuePair kvp in data) { - System.Console.WriteLine(kvp.Key.ToString()); - System.Console.WriteLine(kvp.Value.ToString()); - System.Console.ReadLine(); object valueObj = kvp.Value; string value = String.Empty; - if (valueObj.GetType() == typeof(JArray)) - { - string tmpValue = JsonConvert.SerializeObject(((JArray)valueObj).ToArray()); - char[] charsToTrim = { '[', ' ', ']'}; - value = tmpValue.Trim(charsToTrim); - } - else - { - value = valueObj.ToString(); - } + value = valueObj.ToString(); if (value != "") { - if (valueObj.GetType() == typeof(JObject) || valueObj.GetType() == typeof(JArray)) + if (valueObj.GetType() == typeof(JObject)) { valueObj = jsonObjectToDictionary((Dictionary)JsonConvert.DeserializeObject>(value)); + result.Add(kvp.Key.ToString(), valueObj); + } + else if (valueObj.GetType() == typeof(JArray)) + { + var items = new List(); + + dynamic dynamicObject = JsonConvert.DeserializeObject(value); + Dictionary newObject = new Dictionary(); + + int j = 0; + foreach (var item in dynamicObject) + { + newObject.Add(j.ToString(), jsonObjectToDictionary(item.ToObject>())); + j++; + } + + result.Add(kvp.Key.ToString(), newObject); + } + else + { + result.Add(kvp.Key.ToString(), valueObj); } - result.Add(kvp.Key.ToString(), valueObj); } } return result;