Ruby / Rails Code Examples

This example uses the HTTParty gem by jnunemaker. This gem makes it easier to do HTTP calls.

Example:

require 'httparty'

URL = 'https://gw1.tel.gigahost.dk/messages'
USERNAME = 'username'
PASSWORD = 'password'
SENDER_ID = '4512345678'
RECIPIENTS = '4587654321,4598765432' # comma separated for several recipients

def send_text_message(message)
  res = HTTParty.post URL, {
    :basic_auth => {:username => USERNAME,:password => PASSWORD},
    :headers => {"Accept" => "application/xml"},
    :body => {:sender => SENDER_ID, :recipients => RECIPIENTS, :message => message}
  }

  if res.code == 200
    puts "Send text message to #{RECIPIENTS}"  
  else
    puts "Couldn't send SMS!"
  end
end

send_text_message("Hello! This is a test! All the best.")