Class: Kapow::SMS

Inherits:
Object
  • Object
show all
Defined in:
lib/kapow/sms.rb

Overview

A class for creating and sending an sms message using the Kapow sms gateway.

Constant Summary collapse

MESSAGE_URL =
"https://www.kapow.co.uk/scripts/sendsms.php"
STATUS_URL =
"https://www.kapow.co.uk/scripts/chk_status.php"
VALID_OPTIONS =
[ :flash, :from_id, :long_sms, :returnid, :route, :url ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ SMS

Required values are: username, password

:username

Your account username.

:password

Your account password.



21
22
23
24
# File 'lib/kapow/sms.rb', line 21

def initialize(username, password)
  @username = username
  @password = password
end

Instance Attribute Details

#unique_idObject

Returns the value of attribute unique_id.



15
16
17
# File 'lib/kapow/sms.rb', line 15

def unique_id
  @unique_id
end

Instance Method Details

#deliver(mobile, sms, options = {}) ⇒ Object

Delivers the message

:mobile

Recipient number, or list of comma separated numbers.

:sms

Text for the message itself, truncated by gateway at 160 characters

Optional parameters passed in as a hash

:flash

Boolean - Send SMS as a flash

:from_id

The message originator (if enabled for your account)

:long_sms

Boolean (if enabled in your account)

:returnid

Boolean - Returns unique id in response, so status can be tracked

:route

Your shortcode - Enables premium sms messages (reverse billed)

:url

URL to call after sending the request



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kapow/sms.rb', line 38

def deliver(mobile, sms, options={})
  options = options.reject { |k,v| !VALID_OPTIONS.include?(k) }
  
  sms = "FLASH#{sms}" if options.include?(:flash) && options[:flash] == true
  
  options[:returnid] = "TRUE" if options.include?(:returnid) && options[:returnid] == true
  
  sms_parameters = {
    :username => @username,
    :password => @password,
    :mobile   => mobile,
    :sms      => sms
  }.merge(options)

  response = Net::HTTP.post_form(URI.parse(MESSAGE_URL), sms_parameters)
  Response.new(self, response).message
end

#status(returnid) ⇒ Object

Returns the delivery status of a message

:returnid

The unique id received when sending a message with returnid=TRUE



59
60
61
62
# File 'lib/kapow/sms.rb', line 59

def status(returnid)
  response = Net::HTTP.post_form(URI.parse(STATUS_URL), { :username => @username, :returnid => returnid } )
  Response.new(self, response).message
end