module Smsone::Sms

Constants

VERSION

Public Instance Methods

make_http_call(call, options={}) click to toggle source
# File lib/smsone/sms.rb, line 15
def make_http_call call, options={}
  uri = URI("http://sms.smsone.co.ug:8866/cgi-bin/#{call}")
  http_obj = Net::HTTP.new uri.host, uri.port
  request = Net::HTTP::Post.new uri

  response = http_obj.start do |http|
    post_data = URI.encode_www_form options[:payload]
    http.request(request, post_data)
  end
  response
end
request_balance(username, password) click to toggle source
# File lib/smsone/sms.rb, line 61
def request_balance username, password
  # Requests the amount of credit or balance left
  # Params:
  # +username+:: username to access the bloody system
  # +password+:: yeah, you need a password to get in

  response = make_http_call 'requestbalance',
                              :payload=>{
                                "mocean-username" => username,
                                "mocean-password" => password
                              }

  to_ret = {:response => response, :response_hash => nil}

  if response.body.match /status=0/
    to_ret[:response_hash] ={
      body: response.body,
      success: true,
      error_message: nil,
      api_status_code: 0,
      response_code: response.code
    }
  end

  if response.body.match /status=1/
    to_ret[:response_hash] = {
      body: response.body,
      success: false,
      error_message: "Authorization failed",
      api_status_code: 1,
      response_code: response.code
    }
  end

  if response.body.match /status=3/
    to_ret[:response_hash] = {
      body: response.body,
      success: false,
      error_message: "Unauthorized destination status",
      api_status_code: 3,
      response_code: response.code
    }
  end
  to_ret
end
send_sms(username, password, msidn, from_who, text) click to toggle source
# File lib/smsone/sms.rb, line 41
def send_sms username, password, msidn, from_who, text
  # Sends a message through a pre-configured short code
  # Params:
  # +username+:: username to access system
  # +password+:: password to access system
  # +msidn+:: MSIDN refers to the full phone number with country code
  # +from_who+:: keyword or label that identifies who sent SMS
  # +text+:: Text is the actual content or message

  response = make_http_call 'sendsms',
                        :payload => {
                          'mocean-username' => username,
                          'mocean-password' => password,
                          'mocean-to' => msidn,
                          'mocean-from' => from_who,
                          'mocean-text' => text
                        }
  response
end