/* * Construct attatched to a number */ public Source(Number number, string name, string referring_url, string not_referrer_url, string landing_url, string not_landing_url, int position, bool online) { this.token = number.token; this.name = name; this.referring_url = referring_url; this.not_referrer_url = not_referrer_url; this.landing_url = landing_url; this.not_landing_url = not_landing_url; this.online = online; this.position = position; if (number.id == ""){ this.error = "Number has no id"; return; } string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/numbers/" + number.id + "/tracking_sources.json"; CTM.Response res = new CTM.Request(url, token).post(this.params_hash()); if (res.error != null){ this.error = res.error; }else{ this.update_from(res.data.source); } }
/* * Construct new attached to Number */ public ReceivingNumber(Number number, string digits) { this.token = number.token; if (number.id == ""){ this.error = "Number has no id"; return; } string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/numbers/" + number.id + "/receiving_numbers.json"; Hashtable parameters = new Hashtable(); parameters["number"] = number.number; CTM.Request req = new CTM.Request(url, number.token); CTM.Response res = req.post(parameters); if (res.error != null){ this.error = res.error; } else { this.update_from(res.data.receiving_number); } }
/* * GET a receiving number by id */ public static ReceivingNumber get(CTM.AuthToken token, string id) { string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/receiving_numbers/" + id + ".json"; CTM.Request request = new CTM.Request(url, token); CTM.Response res = request.get(); if (res.error != null){ return new ReceivingNumber(res.error, token); } return new ReceivingNumber(res.data, token); }
/* * Update a receiving number */ public bool save() { string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/receiving_numbers/" + this.id + ".json"; Hashtable parameters = new Hashtable(); parameters["name"] = this.name; parameters["number"] = this.number; CTM.Request req = new CTM.Request(url, this.token); CTM.Response res = req.put(parameters); if (res.error != null){ this.error = res.error; } return res.error == null; }
/* * Reload the receiving number */ public bool reload() { string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/receiving_numbers/" + this.id + ".json"; CTM.Request req = new CTM.Request(url, token); CTM.Response res = req.get(); if (res.error != null){ this.error = res.error; } else{ this.update_from(res.data); } return res.error == null; }
/* * Release the receiving_number */ public bool release() { string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/receiving_numbers/" + this.id + ".json"; CTM.Request req = new CTM.Request(url, this.token); CTM.Response res = req.delete(); if (res.error != null){ this.error = res.error; } return res.error == null; }
/* * List receiving numbers in the current account */ public static Page<ReceivingNumber> list(CTM.AuthToken token, int page=0) { string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/receiving_numbers.json"; Hashtable parameters = new Hashtable(); parameters["page"] = page.ToString(); CTM.Request req = new CTM.Request(url, token); CTM.Response res = req.get(parameters); if (res.error != null){ return new Page<ReceivingNumber>(res.error); } else { int index = 0; ReceivingNumber[] numbers = new ReceivingNumber[res.data.receiving_numbers.Count]; foreach (JObject number in res.data.receiving_numbers.Children<JToken>()) { numbers[index++] = new ReceivingNumber(number, token); } return new Page<ReceivingNumber>(numbers, page, (int)res.data.total_entries, (int)res.data.total_pages); } }
/* * Get source */ public static Source get(CTM.AuthToken token, string id) { string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/sources/" + id + ".json"; CTM.Response res = new CTM.Request(url, token).get(); if (res.error != null){ return new Source(res.error, token); }else{ return new Source(res.data, token); } }
/* * Update source */ public bool save() { string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/sources/" + this.id + ".json"; CTM.Response res = new CTM.Request(url, this.token).put(this.params_hash()); if (res.error != null){ this.error = res.error; } return res.error == null; }
/* * List sources in the current account */ public static Page<Source> list(CTM.AuthToken token, int page=0) { string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/sources.json"; Hashtable parameters = new Hashtable(); parameters["page"] = page.ToString(); CTM.Response res = new CTM.Request(url, token).get(parameters); if (res.error != null){ return new Page<Source>(res.error); } else { int index = 0; Source[] sources = new Source[res.data.sources.Count]; foreach (JObject item in res.data.sources.Children<JToken>()) { sources[index++] = new Source(item, token); } return new Page<Source>(sources, page, (int)res.data.total_entries, (int)res.data.total_pages); } }