Exemple #1
0
        /*
         * Get the stats for a single account
         */
        public static Account get(CTM.AuthToken token, string account_id)
        {
            CTM.Request  request = new CTM.Request(CTM.Config.Endpoint() + "/accounts/" + account_id + ".json", token);
              CTM.Response res     = request.get(new Hashtable());

              if (res.error != null){
            return ErrorAccount(token, res.error, account_id);
              }

              return new Account(res.data, token);
        }
Exemple #2
0
        /*
         * Purchase a number, the number should be the full digit string from the .number within the list of numbers returned from
         * Number#search
         */
        public static Number buy(CTM.AuthToken token, string number)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/numbers.json";

              Hashtable parameters = new Hashtable();
              parameters["phone_number"] = number;

              CTM.Request  req = new CTM.Request(url, token);
              CTM.Response res = req.post(parameters);

              if (res.error != null) {
            return ErrorNumber(token, res.error);

              } else{
            return new Number(res.data.number, token);
              }
        }
        public static AuthToken authorize(string api_key, string api_secret)
        {
            string url = CTM.Config.Endpoint() + "/authentication.json";

              // if (api_key == null || api_secret == null){
              //   Console.WriteLine("Error: missing API_KEY, API_SECRET ");
              //   return null;
              // }

              Hashtable options = new Hashtable();

              options["token"]  = api_key;
              options["secret"] = api_secret;

              CTM.Request  req = new CTM.Request(url);
              CTM.Response res = req.post(options);

              return (res.error != null ? new AuthToken(res.error)
                                : new AuthToken((string)res.data.token,
                                                (string)res.data.first_account.id)
              );
        }
Exemple #4
0
        /*
         * GET a number by id
         */
        public static Number get(CTM.AuthToken token, string id)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/numbers/" + id + ".json";

              CTM.Request request = new CTM.Request(url, token);
              CTM.Response res    = request.get();

              if (res.error != null){
            return ErrorNumber(token, res.error, id);
              }
              return new Number(res.data, token);
        }
Exemple #5
0
        /*
         * Update the number e.g. save the name
         */
        public bool save()
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/numbers/" + this.id + ".json";

              Hashtable parameters = new Hashtable();
              parameters["name"]      = this.name;
              parameters["active"]    = this.active ? "1" : "0";
              parameters["formatted"] = this.formatted;

              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;
        }
Exemple #6
0
        public bool remReceivingNumber(ReceivingNumber num)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/numbers/" + this.id + "/receiving_numbers/" + num.id + "/rem.json";

              CTM.Response res = new CTM.Request(url, this.token).delete();

              if (res.error != null){ this.error = res.error; }
              return res.error == null;
        }
Exemple #7
0
        /*
         * Reload the number
         */
        public bool reload()
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/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;
        }
Exemple #8
0
        public bool release()
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/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;
        }
Exemple #9
0
        /*
         * List receiving numbers on a number
         */
        public Page<ReceivingNumber> receiving_numbers(int page = 0)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.token.account_id + "/numbers/" + this.id + "/receiving_numbers.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<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);
              }
        }
Exemple #10
0
        /*
         * Find numbers available for purchase within the given areacode and country code
         * toll free is US or UK
         */
        public static SearchResult[] search_tollfree(CTM.AuthToken token, string areacode = null, string country_code="US", string pattern="")
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/numbers/search.json";

              Hashtable parameters = new Hashtable();
              parameters["area_code"]    = areacode;
              parameters["searchby"]     = "tollfree";
              parameters["country_code"] = country_code;
              parameters["pattern"]      = pattern;

              CTM.Request  req = new CTM.Request(url, token);
              CTM.Response res = req.get(parameters);

              SearchResult[] numbers;
              if (res.error != null){
            numbers = new SearchResult[1];
            numbers[0] = SearchResult.ErrorResult(token, res.error);

              } else {
            int index = 0;

            if (res.data.results != null) {
              numbers = new SearchResult[res.data.results.Count];
              foreach (JObject number in res.data.results.Children<JToken>()) {
            numbers[index++] = new SearchResult(number, token);
              }
            } else {
              numbers = new SearchResult[0];
            }
              }
              return numbers;
        }
Exemple #11
0
        /*
         * List accounts accessible to the given auth token
         */
        public static Page<Account> list(CTM.AuthToken token, int page=0, string status="active")
        {
            CTM.Request request  = new CTM.Request(CTM.Config.Endpoint() + "/accounts.json", token);

              Hashtable parameters = new Hashtable();
              parameters["page"]   = page.ToString();
              parameters["status"] = status.ToString();

              CTM.Response res = request.get(parameters);

              if (res.error != null){
            return new Page<Account>(res.error);

              } else {
            int index = 0;
            Account[] accounts = new Account[res.data.accounts.Count];

            foreach (JObject account in res.data.accounts.Children<JToken>()) {
              accounts[index++] = new Account(account, token);
            }
            return new Page<Account>(accounts, (int)res.data.page, (int)res.data.total_entries, (int)res.data.total_pages);
              }
        }
Exemple #12
0
        /*
         * Update the account
         */
        public bool save()
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + this.id + ".json";

              Hashtable parameters            = new Hashtable();
              parameters["account[name]"]     = this.name;
              parameters["account[website]"]  = (this.website == null ? "" : this.website);
              parameters["account[timezone]"] = this.timezone;

              CTM.Request  request = new CTM.Request(url, token);
              CTM.Response res     = request.put(parameters);

              if (res.error != null){ this.error = res.error; }
              return res.error == null;
        }
Exemple #13
0
        /*
         * Add new account with billing linked to master account
         */
        public Account create()
        {
            string url = CTM.Config.Endpoint() + "/accounts.json";

              Hashtable parameters        = new Hashtable();
              parameters["account[name]"]        = this.name;
              parameters["account[website_url]"] = this.website;
              parameters["account[timezone]"]    = this.timezone;
              parameters["billing_type"]         = this.shared_billing ? "existing" : "new";

              CTM.Response res = new CTM.Request(url, token).post(parameters);

              if (res.error != null){ return ErrorAccount(token, res.error); }

              return new Account(res.data, token);
        }