using System;
using System.Collections.Generic;
using System.Linq;
namespace Retailcrm.Versions.V3
{
///
/// V3 Client
///
public partial class Client
{
///
/// Request
///
protected Request Request;
///
/// Site code
///
protected string SiteCode;
///
/// V3 Client Constructor
///
///
///
///
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 { { "apiKey", key } });
SiteCode = site;
}
///
/// Return current site
///
/// string
public string GetSite()
{
return SiteCode;
}
///
/// Return current site
///
public void SetSite(string site)
{
SiteCode = site;
}
///
/// Check ID parameter
///
///
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)}");
}
}
///
/// Fill params by site value
///
///
///
/// Dictionary
protected Dictionary FillSite(string site, Dictionary param)
{
if (site.Length > 1)
{
param.Add("site", site);
}
else if (SiteCode.Length > 1)
{
param.Add("site", SiteCode);
}
return param;
}
}
}