Ruby Code Samples

REST SMS API: Ruby Code Samples

Text Message

Sending SMS Messages

Sends SMS text messages to a single phone number or an array of phone numbers.

Code Samples

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/sending/messages')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'PhoneNumbers[0]'=>'2123456785', 
    'PhoneNumbers[1]'=>'2123456786', 
    'Subject'=>'From Winnie', 
    'Message'=>'I am a Bear of Very Little Brain, and long words bother me', 
    'StampToSend'=>'1305582245'
})

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })
    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Message ID: ' + ruObj['Entry']['ID'].to_s() + "\n"
      print 'Subject: ' + ruObj['Entry']['Subject'].to_s() + "\n"
      print 'Message: ' + ruObj['Entry']['Message'].to_s() + "\n"
      print 'Total Recipients: ' + ruObj['Entry']['RecipientsCount'].to_s() + "\n"
      print 'Credits Charged: ' + ruObj['Entry']['Credits'].to_s() + "\n"
      print 'Time To Send: ' + ruObj['Entry']['StampToSend'].to_s() + "\n"
      if !ruObj['Entry']['PhoneNumbers'].nil?
        numbers = ruObj['Entry']['PhoneNumbers']['PhoneNumber']
        print 'Phone Numbers: ' + (numbers.kind_of?(Array) ? numbers.join(', ') : numbers) + "\n"
      end
      if !ruObj['Entry']['LocalOptOuts'].nil?
        numbers = ruObj['Entry']['LocalOptOuts']['PhoneNumber']
        print 'Locally Opted Out Numbers: '+ (numbers.kind_of?(Array) ? numbers.join(', ') : numbers) + "\n"
      end
      if !ruObj['Entry']['GlobalOptOuts'].nil?
        numbers = ruObj['Entry']['GlobalOptOuts']['PhoneNumber']
        print 'Globally Opted Out Numbers: '+ (numbers.kind_of?(Array) ? numbers.join(', ') : numbers) + "\n"
      end
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end
  
  }
}

                      
Ruby - JSON
require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/sending/messages')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'PhoneNumbers[0]'=>'2123456785', 
    'PhoneNumbers[1]'=>'2123456786', 
    'Subject'=>'From Winnie', 
    'Message'=>'I am a Bear of Very Little Brain, and long words bother me', 
    'StampToSend'=>'1305582245'

})

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

    print res.body+"\n===================================\n"
    ruObj = JSON.parse(res.body)
    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Message ID: ' + ruObj['Response']['Entry']['ID'].to_s() + "\n"
      print 'Subject: ' + ruObj['Response']['Entry']['Subject'].to_s() + "\n"
      print 'Message: ' + ruObj['Response']['Entry']['Message'].to_s() + "\n"
      print 'Total Recipients: ' + ruObj['Response']['Entry']['RecipientsCount'].to_s() + "\n"
      print 'Credits Charged: ' + ruObj['Response']['Entry']['Credits'].to_s() + "\n"
      print 'Time To Send: ' + ruObj['Response']['Entry']['StampToSend'].to_s() + "\n"
      if !ruObj['Response']['Entry']['PhoneNumbers'].nil?
        print 'Phone Numbers: ' + ruObj['Response']['Entry']['PhoneNumbers'].join(', ') + "\n"
      end
      if !ruObj['Response']['Entry']['LocalOptOuts'].nil?
        print 'Locally Opted Out Numbers: ' + ruObj['Response']['Entry']['LocalOptOuts'].join(', ') + "\n"
      end
      if !ruObj['Response']['Entry']['GlobalOptOuts'].nil?
        print 'Globally Opted Out Numbers: ' + ruObj['Response']['Entry']['GlobalOptOuts'].join(', ') + "\n"
      end
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end
  }
}

                      




Inbox & Folders

When working with the Inbox and Folder you can perform nine actions: Post (Add New Folder), Put (Update A Folder/Move A Message Between Folders), Delete (Delete A Message/Folder), Get (Get Inbox Message/Folder By ID), Index (Get All Messages/All Folders). The code samples below use the shared library:
· SmsTextingAPI.rb
You can download them, along with the code samples here: RubyLib.zip.

Code Samples - Inbox Messages

Ruby - XML
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :xml
puts 'XML encoding.'

puts 'Get messages'
params = {
    'sortBy' => 'Message',
}
messages = sms.get_all('incoming-messages', params)
pp messages

message_id = messages[0]['ID']
message_id2 = messages[1]['ID']

puts 'Move messages to folder'
sms.move_message_to_folder([message_id, message_id2],  77)

puts 'Get message'
pp message = sms.get(message_id2,  'incoming-messages')

puts 'Delete message'
sms.del(message_id,  'incoming-messages')

puts 'Second delete. try to get error'
begin
  sms.del(message_id,  'incoming-messages')
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end
Ruby - JSON
require 'SmsTextingAPI.rb'
require 'pp'


sms = SmsTextingAPI.new "demouser", "password", :json
puts 'JSON encoding.'

puts 'Get messages'
messages = sms.get_all('incoming-messages', params)
pp messages

message_id = messages[0]['ID']

puts 'Move message to folder'
sms.move_message_to_folder(message_id,  93)


puts 'Get message'
pp message = sms.get(message_id,  'incoming-messages')

puts 'Delete message'
sms.del(message_id,  'incoming-messages')

puts 'Second delete. try to get error'
begin
  sms.del(message_id,  'incoming-messages')
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end

Code Samples - Inbox Folders

Ruby - XML
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :xml
puts 'XML encoding.'

puts 'Get folders'
pp sms.get_all('messages-folders')

folder = {
    'Name'        => 'Customer',
}

puts 'Create folder'
pp folder = sms.put(folder,  'messages-folders')
folder_id = folder['ID']

puts 'Get folder'
pp folder = sms.get(folder_id,  'messages-folders')

puts 'Update folder'
folder['Name'] = 'test'
folder['ID'] = folder_id
sms.put(folder,  'messages-folders')

puts 'Delete folder'
sms.del(folder_id,  'messages-folders')

puts 'Second delete. try to get error'
begin
  sms.del(folder_id,  'messages-folders')
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end
Ruby - JSON
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :json
puts 'JSON encoding.'

puts 'Get folders'
pp sms.get_all('messages-folders')

folder = {
    'Name'        => 'Customer',
}

puts 'Create folder'
pp folder = sms.put(folder,  'messages-folders')
folder_id = folder['ID']

puts 'Get folder'
pp folder = sms.get(folder_id,  'messages-folders')

puts 'Update folder'
folder['Name'] = 'test'
folder['ID'] = folder_id
sms.put(folder,  'messages-folders')

puts 'Delete folder'
sms.del(folder_id,  'messages-folders')

puts 'Second delete. try to get error'
begin
  sms.del(folder_id,  'messages-folders')
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end

Keywords

Check Keyword Availability

Check whether a Keyword is available to rent on Group Texting.

Code Samples

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com')

#prepare post data
req = Net::HTTP::Get.new('/keywords/new?format=xml&Keyword=honey&User=winnie&Password=the-pooh')

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword: ' + ruObj['Entry']['Keyword'].to_s() + "\n"
      print 'Availability: ' + ruObj['Entry']['Available'].to_s() + "\n"
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end

  }
}

                      
Ruby - JSON
require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com')

req = Net::HTTP::Get.new('/keywords/new?format=json&Keyword=honey&User=winnie&Password=the-pooh')

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

    print res.body+"\n===================================\n"

    ruObj = JSON.parse(res.body)

    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword: ' + ruObj['Response']['Entry']['Keyword'].to_s() + "\n"
      print 'Availability: ' + ruObj['Response']['Entry']['Available'].to_s() + "\n"
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}
                      

Rent Keyword

Rents a Keyword for use on Group Texting. You may rent a Keyword using a credit card you have stored in your Group Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/keywords')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'demo', 
    'Password'=>'texting121212', 
    'Keyword'  => 'honey',
    'StoredCreditCard' => '1111'
})

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Entry']['ForwardEmail'].to_s() + "\n"
      print 'Forward url: ' + ruObj['Entry']['ForwardUrl'].to_s() + "\n"
      if !ruObj['Entry']['ContactGroupIDs'].nil?
        groups = ruObj['Entry']['ContactGroupIDs']['Group']
        print 'Groups: '+ (groups.kind_of?(Array) ? groups.join(', ') : groups) + "\n"
      end
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end

  }
}

                      
Ruby - JSON

require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/keywords')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'demo', 
    'Password'=>'texting121212', 
    'Keyword'  => 'honey',
    'StoredCreditCard' => '1111'

})

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

    print res.body+"\n===================================\n"

    ruObj = JSON.parse(res.body)

    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Response']['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Response']['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Response']['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Response']['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Response']['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Response']['Entry']['ForwardEmail'].to_s() + "\n"
      print 'Forward url: ' + ruObj['Response']['Entry']['ForwardUrl'].to_s() + "\n"
      print 'Groups: ' + ruObj['Response']['Entry']['ContactGroupIDs'].join(', ') + "\n"
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}


                      

Code Samples - Non-Stored Card

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/keywords')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'Keyword'  => 'honey',
    'FirstName'        => 'Winnie',
    'LastName'         => 'The Pooh',
    'Street'           => 'Hollow tree, under the name of Mr. Sanders',
    'City'             => 'Hundred Acre Woods',
    'State'            => 'New York',
    'Zip'              => '12345',
    'Country'          => 'US',
    'CreditCardTypeID' => 'Visa',
    'Number'           => '4111111111111111',
    'SecurityCode'     => '123',
    'ExpirationMonth'  => '10',
    'ExpirationYear'   => '2017'

})

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Entry']['ForwardEmail'].to_s() + "\n&qquot;
      print 'Forward url: ' + ruObj['Entry']['ForwardUrl'].to_s() + "\n"
      if !ruObj['Entry']['ContactGroupIDs'].nil?
        groups = ruObj['Entry']['ContactGroupIDs']['Group']
        print 'Groups: '+ (groups.kind_of?(Array) ? groups.join(', ') : groups) + "\n"
      end
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end

  }
}

                      
Ruby - JSON

require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/keywords')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'Keyword'  => 'honey',
    'FirstName'        => 'Winnie',
    'LastName'         => 'The Pooh',
    'Street'           => 'Hollow tree, under the name of Mr. Sanders',
    'City'             => 'Hundred Acre Woods',
    'State'            => 'New York',
    'Zip'              => '12345',
    'Country'          => 'US',
    'CreditCardTypeID' => 'Visa',
    'Number'           => '4111111111111111',
    'SecurityCode'     => '123',
    'ExpirationMonth'  => '10',
    'ExpirationYear'   => '2017'

})

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

    print res.body+"\n===================================\n"

    ruObj = JSON.parse(res.body)

    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Response']['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Response']['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Response']['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Response']['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Response']['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Response']['Entry']['ForwardEmail'].to_s() + "\n"
      print 'Forward url: ' + ruObj['Response']['Entry']['ForwardUrl'].to_s() + "\n"
      print 'Groups: ' + ruObj['Response']['Entry']['ContactGroupIDs'].join(', ') + "\n"
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}

                      

Setup A Keyword

Configures an active Keyword for use on Group Texting.

Code Samples

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/keywords/honey')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'EnableDoubleOptIn' => 1,
    'ConfirmMessage'    => 'Reply Y to join our sweetest list',
    'JoinMessage'       => 'The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.',
    'ForwardEmail'      => '[email protected]',
    'ForwardUrl'        => 'http://bear-alliance.co.uk/honey-donations/',
    'ContactGroupIDs[0]'   => 'honey',
    'ContactGroupIDs[1]'   => 'lovers'
})

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Entry']['ForwardEmail'].to_s() + "\n"
      print 'Forward url: ' + ruObj['Entry']['ForwardUrl'].to_s() + "\n"
      if !ruObj['Entry']['ContactGroupIDs'].nil?
        groups = ruObj['Entry']['ContactGroupIDs']['Group']
        print 'Groups: '+ (groups.kind_of?(Array) ? groups.join(', ') : groups) + "\n"
      end
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end

  }
}
                      
Ruby - JSON

require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/keywords/honey')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'EnableDoubleOptIn' => 1,
    'ConfirmMessage'    => 'Reply Y to join our sweetest list',
    'JoinMessage'       => 'The only reason for being a bee that I know of, is to make honey. And the only reason for making honey, is so as I can eat it.',
    'ForwardEmail'      => '[email protected]',
    'ForwardUrl'        => 'http://bear-alliance.co.uk/honey-donations/',
    'ContactGroupIDs[0]'   => 'honey',
    'ContactGroupIDs[1]'   => 'lovers'
})

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

    print res.body+"\n===================================\n"

    ruObj = JSON.parse(res.body)

    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Keyword ID: ' + ruObj['Response']['Entry']['ID'].to_s() + "\n"
      print 'Keyword: ' + ruObj['Response']['Entry']['Keyword'].to_s() + "\n"
      print 'Is double opt-in enabled: ' + ruObj['Response']['Entry']['EnableDoubleOptIn'].to_s() + "\n"
      print 'Confirm message: ' + ruObj['Response']['Entry']['ConfirmMessage'].to_s() + "\n"
      print 'Join message: ' + ruObj['Response']['Entry']['JoinMessage'].to_s() + "\n"
      print 'Forward email: ' + ruObj['Response']['Entry']['ForwardEmail'].to_s() + "\n"
      print 'Forward url: ' + ruObj['Response']['Entry']['ForwardUrl'].to_s() + "\n"
      print 'Groups: ' + ruObj['Response']['Entry']['ContactGroupIDs'].join(', ') + "\n"
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}

                      

Cancel A Keyword

Cancels an active Keyword on Group Texting.

Code Samples

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/keywords/honey')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    '_method'=>'DELETE',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
})

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

    case res
    when Net::HTTPSuccess
      print "Success!"
    else
      print res.body+"\n===================================\n"

      ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

      print 'Status: ' + ruObj['Status'].to_s() + "\n"
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
   end

  }
}

                      
Ruby - JSON
require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/keywords/honey')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    '_method'=>'DELETE',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
})

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == "https"  # enable SSL/TLS
http.ca_file = "cacert.pem"
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.start {
  http.request(req) {|res|
    case res
    when Net::HTTPSuccess
      print "Success!"
    else
      print res.body+"\n===================================\n"

      ruObj = JSON.parse(res.body)

      print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}

                      

Credits

Check Credit Balance

Checks credit balances on your account.

Code Samples

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com')

#prepare post data
req = Net::HTTP::Get.new('/billing/credits/get?format=xml&User=winnie&Password=the-pooh')

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

    print res.body+"\n===================================\n"

    ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })

    print 'Status: ' + ruObj['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
      print 'Plan credits: ' + ruObj['Entry']['PlanCredits'].to_s() + "\n"
      print 'Anytime credits: ' + ruObj['Entry']['AnytimeCredits'].to_s() + "\n"
      print 'Total: ' + ruObj['Entry']['TotalCredits'].to_s() + "\n"
    else
      if !ruObj['Errors'].nil?
        errors = ruObj['Errors']['Error']
        print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
      end
    end

  }
}

                      
Ruby - JSON
require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com')

#prepare post data
req = Net::HTTP::Get.new('/billing/credits/get?format=json&User=winnie&Password=the-pooh')

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

    print res.body+"\n===================================\n"

    ruObj = JSON.parse(res.body)

    print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
    print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
    case res
    when Net::HTTPSuccess
        print 'Plan credits: ' + ruObj['Response']['Entry']['PlanCredits'].to_s() + "\n"
        print 'Anytime credits: ' + ruObj['Response']['Entry']['AnytimeCredits'].to_s() + "\n"
        print 'Total: ' + ruObj['Response']['Entry']['TotalCredits'].to_s() + "\n"
    else
      if !ruObj['Response']['Errors'].nil?
        print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
      end
    end

  }
}

                      

Buy Credits

Buys more credits for your account. You may purchase credits using a credit card you have stored in your Group Texting account, or you may pass credit card details when you call the API.

Code Samples - Stored Card

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/billing/credits')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'demo', 
    'Password'=>'texting121212', 
    'NumberOfCredits'  => '1000',
    'CouponCode'       => 'honey2011',
    'StoredCreditCard' => '1111'
})

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

    print res.body+"\n===================================\n"
    if res.body.length > 0
      ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })
      print 'Status: ' + ruObj['Status'].to_s() + "\n"
      print 'Code: ' + ruObj['Code'].to_s() + "\n"
      case res
      when Net::HTTPSuccess
          print 'Credits purchased: ' + ruObj['Entry']['BoughtCredits'].to_s() + "\n"
          print 'Amount charged: ' + ruObj['Entry']['Amount'].to_s() + "\n"
          print 'Discount: ' + ruObj['Entry']['Discount'].to_s() + "\n"
          print 'Plan credits: ' + ruObj['Entry']['PlanCredits'].to_s() + "\n"
          print 'Anytime credits: ' + ruObj['Entry']['AnytimeCredits'].to_s() + "\n"
          print 'Total: ' + ruObj['Entry']['TotalCredits'].to_s() + "\n"
      else
        if !ruObj['Errors'].nil?
          errors = ruObj['Errors']['Error']
          print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
        end
      end
    end

  }
}


                      
Ruby - JSON
require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/billing/credits')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'demo', 
    'Password'=>'texting121212', 
    'NumberOfCredits'  => '1000',
    'CouponCode'       => 'honey2011',
    'StoredCreditCard' => '1111'
})

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

    print res.body+"\n===================================\n"

    if res.body.length > 0
      ruObj = JSON.parse(res.body)
      print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
      print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
      case res
      when Net::HTTPSuccess
        print 'Credits purchased: ' + ruObj['Response']['Entry']['BoughtCredits'].to_s() + "\n"
        print 'Amount charged: ' + ruObj['Response']['Entry']['Amount'].to_s() + "\n"
        print 'Discount: ' + ruObj['Response']['Entry']['Discount'].to_s() + "\n"
        print 'Plan credits: ' + ruObj['Response']['Entry']['PlanCredits'].to_s() + "\n"
        print 'Anytime credits: ' + ruObj['Response']['Entry']['AnytimeCredits'].to_s() + "\n"
        print 'Total: ' + ruObj['Response']['Entry']['TotalCredits'].to_s() + "\n"
      else
        if !ruObj['Response']['Errors'].nil?
          print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
        end
      end
    end

  }
}
                      

Code Samples - Non-Stored Card

Ruby - XML
require 'net/https'
require 'uri'
require 'xmlsimple'

url = URI.parse('https://app.grouptexting.com/billing/credits')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'xml',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'NumberOfCredits'  => '1000',
    'CouponCode'       => 'honey2011',
    'FirstName'        => 'Winnie',
    'LastName'         => 'The Pooh',
    'Street'           => 'Hollow tree, under the name of Mr. Sanders',
    'City'             => 'Hundred Acre Woods',
    'State'            => 'New York',
    'Zip'              => '12345',
    'Country'          => 'US',
    'CreditCardTypeID' => 'Visa',
    'Number'           => '4111111111111111',
    'SecurityCode'     => '123',
    'ExpirationMonth'  => '10',
    'ExpirationYear'   => '2017'
})

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

    print res.body+"\n===================================\n"
    if res.body.length > 0
      ruObj = XmlSimple.xml_in(res.body, {'ForceArray' => false })
      print 'Status: ' + ruObj['Status'].to_s() + "\n"
      print 'Code: ' + ruObj['Code'].to_s() + "\n"
      case res
      when Net::HTTPSuccess
          print 'Credits purchased: ' + ruObj['Entry']['BoughtCredits'].to_s() + "\n"
          print 'Amount charged: ' + ruObj['Entry']['Amount'].to_s() + "\n"
          print 'Discount: ' + ruObj['Entry']['Discount'].to_s() + "\n"
          print 'Plan credits: ' + ruObj['Entry']['PlanCredits'].to_s() + "\n"
          print 'Anytime credits: ' + ruObj['Entry']['AnytimeCredits'].to_s() + "\n"
          print 'Total: ' + ruObj['Entry']['TotalCredits'].to_s() + "\n"
      else
        if !ruObj['Errors'].nil?
          errors = ruObj['Errors']['Error']
          print 'Errors: '+ (errors.kind_of?(Array) ? errors.join(', ') : errors) + "\n"
        end
      end
    end

  }
}

                      
Ruby - JSON

require 'net/https'
require 'uri'
require 'json'

url = URI.parse('https://app.grouptexting.com/billing/credits')

#prepare post data
req = Net::HTTP::Post.new(url.path)

req.set_form_data({
    'format'=>'json',
    'User'=>'winnie', 
    'Password'=>'the-pooh', 
    'NumberOfCredits'  => '1000',
    'CouponCode'       => 'honey2011',
    'FirstName'        => 'Winnie',
    'LastName'         => 'The Pooh',
    'Street'           => 'Hollow tree, under the name of Mr. Sanders',
    'City'             => 'Hundred Acre Woods',
    'State'            => 'New York',
    'Zip'              => '12345',
    'Country'          => 'US',
    'CreditCardTypeID' => 'Visa',
    'Number'           => '4111111111111111',
    'SecurityCode'     => '123',
    'ExpirationMonth'  => '10',
    'ExpirationYear'   => '2017'
})

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

    print res.body+"\n===================================\n"

    if res.body.length > 0
      ruObj = JSON.parse(res.body)
      print 'Status: ' + ruObj['Response']['Status'].to_s() + "\n"
      print 'Code: ' + ruObj['Response']['Code'].to_s() + "\n"
      case res
      when Net::HTTPSuccess
        print 'Credits purchased: ' + ruObj['Response']['Entry']['BoughtCredits'].to_s() + "\n"
        print 'Amount charged: ' + ruObj['Response']['Entry']['Amount'].to_s() + "\n"
        print 'Discount: ' + ruObj['Response']['Entry']['Discount'].to_s() + "\n"
        print 'Plan credits: ' + ruObj['Response']['Entry']['PlanCredits'].to_s() + "\n"
        print 'Anytime credits: ' + ruObj['Response']['Entry']['AnytimeCredits'].to_s() + "\n"
        print 'Total: ' + ruObj['Response']['Entry']['TotalCredits'].to_s() + "\n"
      else
        if !ruObj['Response']['Errors'].nil?
          print 'Errors: ' + ruObj['Response']['Errors'].join(', ') + "\n"
        end
      end
    end

  }
}

                      

Contacts

Contacts

When working with Contacts you can perform five actions: Post (Add New Contact), Put (Update/Edit A Contact), Delete (Delete A Contact), Get (Get Contact By ID), Index (Get All Contacts). The code samples below use the shared library:
· SmsTextingAPI.rb
You can download them, along with the code samples here: RubyLib.zip.

Code Samples

Ruby - XML
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :xml
puts 'XML encoding.'

puts 'Get contacts'
params = {
    'source'        => 'upload',
    'optout'        => 'false',
    'group'         => 'Honey Lovers',
    'sortBy'        => 'PhoneNumber',
    'sortDir'       => 'asc',
    'itemsPerPage'  => '10',
    'page'          => '3'
}
pp sms.get_all(:contacts, params)

contact = {
    'PhoneNumber' => '2123456985',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']
}

puts 'Create contact'
pp contact = sms.put(contact,  :contacts)

puts 'Get contact'
pp contact = sms.get(contact['ID'],  :contacts)

puts 'Update contact'
contact['LastName'] = 'test'
pp contact = sms.put(contact,  :contacts)

puts 'Delete contact'
sms.del(contact['ID'],  :contacts)

puts 'Second delete. try to get error'
begin
  sms.del(contact['ID'],  :contacts)
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end

                     
Ruby - JSON
require 'SmsTextingAPI.rb'
require 'pp'


sms = SmsTextingAPI.new "demouser", "password", :json
puts 'JSON encoding.'

puts 'Get contacts'
pp sms.get_all(:contacts, params)
       
contact = {
    'PhoneNumber' => '2123456985',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']
}

puts 'Create contact'
pp contact = sms.put(contact,  :contacts)

puts 'Get contact'
pp contact = sms.get(contact['ID'],  :contacts)

puts 'Update contact'
contact['LastName'] = 'test'
pp contact = sms.put(contact,  :contacts)

puts 'Delete contact'
sms.del(contact['ID'],  :contacts)

puts 'Second delete. try to get error'
begin
  sms.del(contact['ID'],  :contacts)
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end


                     

Groups

Groups

When working with Groups you can perform five actions: Post (Add New Group), Put (Update/Edit A Group), Delete (Delete A Group), Get (Get Group By ID), Index (Get All Groups). The code samples below use the shared library:
· SmsTextingAPI.rb
You can download them, along with the code samples here: RubyLib.zip.

Code Samples

Ruby - XML
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :xml
puts 'XML encoding.'

puts 'Get contacts'
params = {
    'source'        => 'upload',
    'optout'        => 'false',
    'group'         => 'Honey Lovers',
    'sortBy'        => 'PhoneNumber',
    'sortDir'       => 'asc',
    'itemsPerPage'  => '10',
    'page'          => '3'
}
pp sms.get_all(:contacts, params)

contact = {
    'PhoneNumber' => '2123456985',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']
}

puts 'Create contact'
pp contact = sms.put(contact,  :contacts)

puts 'Get contact'
pp contact = sms.get(contact['ID'],  :contacts)

puts 'Update contact'
contact['LastName'] = 'test'
pp contact = sms.put(contact,  :contacts)

puts 'Delete contact'
sms.del(contact['ID'],  :contacts)

puts 'Second delete. try to get error'
begin
  sms.del(contact['ID'],  :contacts)
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end
Ruby - JSON
require 'SmsTextingAPI.rb'
require 'pp'

sms = SmsTextingAPI.new "demouser", "password", :json
puts 'JSON encoding.'

puts 'Get contacts'
pp sms.get_all(:contacts, params)
       
contact = {
    'PhoneNumber' => '2123456985',
    'FirstName'   => 'Piglet',
    'LastName'    => 'P.',
    'Email'       => '[email protected]',
    'Note'        => 'It is hard to be brave, when you are only a Very Small Animal.',
    'Groups'   => ['Friends', 'Neighbors']
}

puts 'Create contact'
pp contact = sms.put(contact,  :contacts)

puts 'Get contact'
pp contact = sms.get(contact['ID'],  :contacts)

puts 'Update contact'
contact['LastName'] = 'test'
pp contact = sms.put(contact,  :contacts)

puts 'Delete contact'
sms.del(contact['ID'],  :contacts)

puts 'Second delete. try to get error'
begin
  sms.del(contact['ID'],  :contacts)
rescue SmsTextingAPIError, NameError => e
  puts 'Get SmsTextingAPIError code:' + e.code.to_s + ', ' + e  
end

No contracts, no setup fees, no kidding.


GroupTexting has partnered with EZ Texting to power its mass texting platform.
Signing up for GroupTexting will automatically create an EZ Texting account.


Get Started