internal static T Get <T>(AmoCrmConfig crmConfig, params Parameter[] parameters) where T : class, IAmoCrmResponse, new() { var client = new RestClient(crmConfig.GetUrl <T>()) { CookieContainer = GetCookies(crmConfig) }; var request = new RestRequest(Method.GET); request.AddParameter("limit_rows", crmConfig.LimitRows ?? 500); request.AddParameter("limit_offset", crmConfig.LimitOffset ?? 0); foreach (var parameter in parameters) { request.AddParameter(parameter); } if (crmConfig.ModifiedSince.HasValue) { request.AddHeader("If-Modified-Since", crmConfig.ModifiedSince.Value.ToString("u")); } var response = client.Execute(request); if (response.ErrorException != null) { throw new AmoCrmException(response.ErrorMessage, response.ErrorException); } return(response.Content.DeserializeTo <T>()); }
internal static T Post <T>(IAmoCrmRequest data, AmoCrmConfig crmConfig) where T : class, IAmoCrmResponse, new() { var client = new RestClient(crmConfig.GetUrl <T>()) { CookieContainer = GetCookies(crmConfig) }; var request = new RestRequest(Method.POST); request.AddParameter(new Parameter { Name = "text/json", Value = JsonConvert.SerializeObject(data), Type = ParameterType.RequestBody }); var response = client.Execute(request); var result = response.Content.DeserializeTo <T>(); //if (result.Error!=null) throw new AmoCrmException(result.Error); return(result); }