Beispiel #1
0
        static string ListNumbers(AuthToken token, int? max_page = null)
        {
            int          page = 1;
              string       first_number_id = null;
              Page<Number> numbers;

              Console.WriteLine();

              do {
            numbers = Number.list(token, page);

            if (numbers.error != null){
              Console.WriteLine("Error listing numbers: " + numbers.error);
              return null;
            }

            Console.WriteLine("Numbers Page: " + page.ToString());

            foreach(Number num in numbers.items) {
              if (first_number_id == null){ first_number_id = num.id; }
              Console.WriteLine("  " + num.id + " " + num.number);
            }

            ++page;

              } while (numbers.page < numbers.total_pages && (max_page == null || numbers.page < max_page));
              return first_number_id;
        }
Beispiel #2
0
        /*
         * 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);
              }
        }
Beispiel #3
0
        // +-----------------+
        // | Listing Helpers |
        // +-----------------+
        static string ListAccounts(AuthToken token, int? max_page = null)
        {
            int           page = 1;
              string        second_account_id = null;
              bool          first_account = false;
              Page<Account> accounts;

              Console.WriteLine();

              do {
            accounts = Account.list(token, page);

            if (accounts.error != null){
              Console.WriteLine("Error listing accounts: " + accounts.error);
              return null;
            }

            Console.WriteLine("Accounts Page: " + page);

            foreach(Account act in accounts.items) {
              if (first_account == false){
            first_account = true;
              }else if(second_account_id == null){
            second_account_id = act.id;
              }

              Console.WriteLine("  Account " + act.id + ": " + act.name);
            }

            ++page;
              } while (accounts.page < accounts.total_pages && (max_page ==  null || accounts.page < max_page));
              return second_account_id;
        }
        /*
         * 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);
              }
        }
Beispiel #5
0
 public Request(string url, CTM.AuthToken token=null)
 {
     _token = token;
       _url = url;
       _req = (HttpWebRequest)WebRequest.Create(url);
 }
Beispiel #6
0
        static void PurchaseAndConfigureNewNumber(AuthToken token)
        {
            Number.SearchResult[] numbers = null;

              // search for some toll-free numbers
              numbers = Number.search_tollfree(token);

              Console.WriteLine();
              if (numbers.Length == 0){
            Console.WriteLine("No US toll free numbers found");

              } else if (numbers[0].error != null){
            Console.WriteLine("Error searching for US toll free numbers: "  + numbers[0].error);
            return;
              }

              foreach(Number.SearchResult num in numbers) {
            Console.WriteLine("US Toll free: " + num.friendly_name);
              }

              // search for some numbers in 410 area code
              numbers = Number.search(token, "410");

              Console.WriteLine();
              if (numbers.Length == 0) {
            Console.WriteLine("No numbers found for US 410 area code");
            return;

              } else if (numbers[0].error != null) {
            Console.WriteLine("Error searching for numbers local to US 410 area code: " + numbers[0].error);
            return;
              }

              foreach(Number.SearchResult num in numbers) {
            Console.WriteLine("Local to 410: " + num.friendly_name + " " + num.rate_center);
              }

              // Buy the number
              Number number = Number.buy(token, numbers[0].phone_number);
              if (number.error != null){
            Console.WriteLine("Error buying number [" + numbers[0].phone_number + "]: " + number.error);
            return;
              }

              Console.WriteLine();
              Console.WriteLine("Purchased Number: " + number.number + ", id: " + number.id);

              // Add a receiving number
              ReceivingNumber rn = number.addReceivingNumber("+18888980510");
              if (rn.error != null){
            Console.WriteLine("Error adding receiving number: " + rn.error);
            return;
              }

              Console.WriteLine("Added receiving number " + rn.id + " to number");
              PrintReceivingNumber(rn);
              ListReceivingNumbersOnNumber(number);

              // Add a tracking source
              Source source = number.addTrackingSource("Test Source2",
                                               "google.com", "",
                                               "gclid=.+",   "",
                                               100,          true);

              Console.WriteLine("Created source: " + source.name);
              PrintTrackingSource(source);

              // Remove the receiving number
              if (!number.remReceivingNumber(rn)){
            Console.WriteLine("Error removing receiving_number: " + number.error);
            number.error = null;
              }else{
            Console.WriteLine();
            Console.WriteLine("Removed receiving number " + rn.id + " from number");
            ListReceivingNumbersOnNumber(number);
              }

              // Release the receiving / tracking numbers
              Console.WriteLine();
              if (!number.release()){
            Console.WriteLine("Error releasing number: " + number.error);
              }else{
            Console.WriteLine("Released number " + number.formatted);
              }

              if (!rn.release()){
            Console.WriteLine("Error releasing receiving number: " + rn.error);
            return;
              }
              Console.WriteLine("Released receiving number " + rn.number);
        }
Beispiel #7
0
        static string ListSources(AuthToken token, int? max_page = null)
        {
            int          page = 1;
              string       id = null;
              Page<Source> sources;

              Console.WriteLine();

              do {
            sources = Source.list(token, page);

            if (sources.error != null){
              Console.WriteLine("Error listing sources: " + sources.error);
              return null;
            }

            Console.WriteLine("Sources Page: " + page);

            foreach(Source src in sources.items) {
              if (id == null){ id = src.id; }
              Console.WriteLine("  Source " + src.id + ": " + src.name);
            }

            ++page;
              } while (sources.page < sources.total_pages && (max_page ==  null || sources.page < max_page));
              return id;
        }
 /*
  * Construct from CTM.Response data
  */
 public ReceivingNumber(JObject src, CTM.AuthToken token)
 {
     this.token = token;
       this.update_from(src);
 }
 /*
  * Contruct to return errors
  */
 public ReceivingNumber(string error, CTM.AuthToken token)
 {
     this.token = token;
       this.error = error;
 }
Beispiel #10
0
 /*
  * Construct from CTM.Response data
  */
 public Source(JObject src, CTM.AuthToken token)
 {
     this.token = token;
       this.update_from(src);
 }
Beispiel #11
0
 /*
  * Construct an empty Source for error returns
  */
 public Source(string error, CTM.AuthToken token)
 {
     this.token = token;
       this.error = error;
 }