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
        /*
         * 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 #3
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 #4
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 #5
0
        /*
         * List numbers in the current account
         */
        public static Page<Number> list(CTM.AuthToken token, int page=0)
        {
            string url = CTM.Config.Endpoint() + "/accounts/" + token.account_id + "/numbers.json";

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

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

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

              } else{
            int index = 0;
            Number[] numbers = new Number[res.data.numbers.Count];

            foreach (JObject number in res.data.numbers.Children<JToken>()) {
              numbers[index++] = new Number(number, token);
            }
            return new Page<Number>(numbers, page, (int)res.data.total_entries, (int)res.data.total_pages);
              }
        }
Exemple #6
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);
              }
        }