public Appointment Update(int scheduleId, int appointmentId, Dictionary <string, string> attributes, bool form = false, bool webhook = false) { string path = "/bookings/" + appointmentId.ToString(); JsonArgs appointmentData = new JsonArgs { }; foreach (KeyValuePair <string, string> entry in attributes) { appointmentData.Add(entry.Key, entry.Value); } NestedJsonArgs data = new NestedJsonArgs { { "booking", appointmentData } }; JsonArgs query = new JsonArgs { { "schedule_id", scheduleId.ToString() } }; if (webhook) { query.Add("webhook", "true"); } if (form) { query.Add("form", "true"); } return(this.Client.Put <Appointment>(path, data, query)); }
public User Update(int userId, Dictionary <string, string> attributes, bool webhook = false) { string path = "/users/" + userId; JsonArgs query = null; JsonArgs userData = new JsonArgs { }; foreach (KeyValuePair <string, string> entry in attributes) { userData.Add(entry.Key, entry.Value); } NestedJsonArgs data = new NestedJsonArgs { { "user", userData } }; if (webhook) { query = new JsonArgs { { "webhook", "true" } }; } return(this.Client.Put <User>(path, data, query)); }
public void Create(Dictionary <string, string> attributes, string userId = null, bool webhook = false) { string path = "/users"; if (userId != null) { path += "/" + userId; } JsonArgs userData = new JsonArgs { }; foreach (KeyValuePair <string, string> entry in attributes) { userData.Add(entry.Key, entry.Value); } NestedJsonArgs data = new NestedJsonArgs { { "user", userData } }; JsonArgs query = null; if (webhook) { query = new JsonArgs { { "webhook", "true" } }; } this.Client.Post <User>(path, data, query); }
public void PutTest() { NestedJsonArgs data = new NestedJsonArgs { { "user", new JsonArgs { { "test", "true" } } } }; Assert.AreEqual(default(object), this.Client.Put <object>("/test", data)); }
public Appointment Create(int scheduleId, int userId, Dictionary <string, string> attributes, bool form = false, bool webhook = false) { string path = "/bookings"; JsonArgs appointmentData = new JsonArgs { }; foreach (KeyValuePair <string, string> entry in attributes) { appointmentData.Add(entry.Key, entry.Value); } NestedJsonArgs data = new NestedJsonArgs { { "booking", appointmentData } }; JsonArgs query = new JsonArgs { { "schedule_id", scheduleId.ToString() }, { "user_id", userId.ToString() } }; if (webhook) { query.Add("webhook", "true"); } if (form) { query.Add("form", "true"); } Client.Post <Appointment>(path, data, query); Appointment model = new Appointment(); int id = Client.GetResourceIdFromHeader(); if (id > 0) { model.id = id; } return(model); }
private T Request <T>(string httpMethod, string path, NestedJsonArgs postData = null, JsonArgs queryData = null) { string url = this.Host + "/" + path + ".json" + this.dictionaryToQuerystring(queryData); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = httpMethod; request.Accept = "application/json"; request.ContentType = "application/json"; request.Headers.Add("Authorization", this.basicAuth()); request.UserAgent = this.userAgent(); request.Timeout = TIMEOUT_SECONDS; string json = null; if (postData != null) { json = JsonConvert.SerializeObject(postData); } this.LastRequest = request; if (this.Test) { return(default(T)); } if (json != null) { using (Stream stream = request.GetRequestStream()) { using (StreamWriter streamOut = new StreamWriter(stream, System.Text.Encoding.ASCII)) { streamOut.Write(json); } } } string body = ""; try { using (WebResponse response = request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { if (stream != null) { using (StreamReader streamIn = new StreamReader(stream)) { body = streamIn.ReadToEnd(); streamIn.Close(); } stream.Close(); } } response.Close(); } } catch (Exception ex) { if (ex is WebException && ((WebException)ex).Status == WebExceptionStatus.ProtocolError) { using (WebResponse response = ((WebException)ex).Response) { using (Stream stream = response.GetResponseStream()) { if (stream != null) { using (StreamReader r = new StreamReader(stream)) { body = r.ReadToEnd(); r.Close(); } stream.Close(); } } response.Close(); } throw new SSSException(body); } else { throw new SSSException(ex.Message); } } if (body.Length > 0) { JsonSerializerSettings settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }; T result = JsonConvert.DeserializeObject <T>(body, settings); return(result); } else { return(default(T)); } }
public T Delete <T>(string path, NestedJsonArgs postData = null, JsonArgs queryData = null) { return(this.Request <T>(HttpMethod.DELETE, path, postData)); }
public T Put <T>(string path, NestedJsonArgs postData = null, JsonArgs queryData = null) { return(this.Request <T>(HttpMethod.PUT, path, postData)); }