Ruby Code Samples - Legacy


Sending SMS Messages
- Code Examples:

Send A Single Message

#!/usr/bin/env ruby
require 'net/https'
require 'uri'

url = URI.parse('https://app.clubtexting.com/api/sending')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword' , 'phonenumber'=>'2125551234', 'subject'=>'test', 'message'=>'test message', 'express'=>'1'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}

Send Multiple Messages

#!/usr/bin/env ruby
require 'net/https'
require 'uri'

messages = [
 {:phone=>'2125551234', :subject=>'test', :message=>'test message'},
 {:phone=>'2127846501', :subject=>'test2', :message=>'test message2'},
 {:phone=>'2127846502', :subject=>'test3', :message=>'test message3'}
]


url = URI.parse('https://app.clubtexting.com/api/sending')



http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {

  messages.each {|msg|
    #prepare post data
    req = Net::HTTP::Post.new(url.path)
    req.set_form_data({'user'=>'username', 'pass'=>'userpassword' , 'phonenumber'=>msg[:phone], 'subject'=>msg[:subject], 'message'=>msg[:message], 'express'=>'1'})
    http.request(req) {|res|
      puts msg[:phone] +": "+ res.body
    }
  }
}


Receiving Keyword Submissions
- Code Examples:

class Ex3Controller < ApplicationController
  def index
    sender = params['PhoneNumber']
    message = params['Message']
    if !sender.nil? && sender > ""
      #Save incoming messages
      File.open("receivelog.txt", 'a') {|f| f.write(sender+"\n") }

      #Return a response SMS message
      responsetext = "Thank you for the message!"
      render :text => "{SMS:TEXT}{}{}{"+sender+"}{"+responsetext+"}"
    else
      render :text => "The Ruby on Rails script is waiting for messages"
    end
  end

end


Check Credit Balance
- Code Examples:

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/credits/check/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword'})
#req.set_form_data({'user'=>'exampleuser', 'pass'=>'texting'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Check Keyword Availability
- Code Examples:

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/keyword/check/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'keyword'=>'userkeyword'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Buy More Credits
- Code Examples:

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/credits/buy/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'credits' => 5, 'firstname'=> 'firstname', 'lastname'=> 'lastname', 'address'=> 'address', 'city'=> 'newyork', 'state'=> 'ny', 'zip'=> '08902', 'country'=> 'usa', 'type'=> 'visa', 'ccnumber'=> 'rIhLJUiXl8M0JIcrelxH9A', 'cccode'=> '111', 'expm'=> '11', 'expy'=> '12'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Rent a Keyword:
- Code Examples

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/keyword/rent/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'keyword' => 'keywordtorent', 'firstname'=> 'firstname', 'lastname'=> 'lastname', 'address'=> 'address', 'city'=> 'newyork', 'state'=> 'ny', 'zip'=> '08902', 'country'=> 'usa', 'type'=> 'visa', 'ccnumber'=> 'rIhLJUiXl8M0JIcrelxH9A', 'cccode'=> '111', 'expm'=> '11', 'expy'=> '12'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Configure a Keyword
- Code Examples:

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/keyword/setup/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'keyword' => 'keywordtoconfigure', 'group'=> 'test', 'autoreply'=> 'autoreply', 'url'=> 'http://test.com/test'})
puts req.body

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Voice Broadcast
- Code Examples:


(Single Number)

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/voicemessages/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'phonenumbers' => '2125551234', 'soundsource'=> 'http://mydomain.com/sounds/voice.wav', 'callerid'=> '2127847840'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}

(An Array Of Numbers)

#!/usr/bin/env ruby
require 'net/https'
require 'uri'


url = URI.parse('https://app.clubtexting.com/api/voicemessages/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword', 'soundfile'=> '1236019718.wav', 'callerid'=> '2127847840'})
req.body = req.body+"&phonenumbers[]=phone1&phonenumbers[]=phone2&phonenumbers[]=phone3"
puts req.body


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}


Receiving Inbox Message Replies
- Code Examples:

class Ex11Controller < ApplicationController
  def index
    sender = params['from']
    message = params['message']
    if !sender.nil? && sender > ""
      #Save incoming messages
      File.open("forwardlog.txt", 'a') {|f| f.write(sender+"\n") }
    end
    render :text => ""
  end

end


Carrier Lookup
- Code Examples:

#!/usr/bin/env ruby
require 'net/https'
require 'uri'

url = URI.parse('https://app.clubtexting.com/api/lookup/')

#prepare post data
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'user'=>'username', 'pass'=>'userpassword' , 'phonenumber'=>'2125551234'})


http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.start {
  http.request(req) {|res|
    puts res.body
  }
}

Get started for free!

Sign up now