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 =
"http://www.kapow.co.uk/scripts/sendsms.php"
VALID_OPTIONS =
[:flash, :from_id, :long_sms]

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ SMS

Required values are: username, password

:username

Your account username.

:password

Your account password.



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

def initialize(username, password)
  @username = username
  @password = password
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)



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kapow/sms.rb', line 28

def deliver(mobile, sms, options={})
  options = options.reject { |k,v| !VALID_OPTIONS.include?(k) }
  if options.include?(:flash) && options[:flash] == true
    sms = "FLASH#{sms}"
  end
  sms_parameters = {
    :username => @username,
    :password => @password,
    :mobile => mobile,
    :sms => sms
  }.merge(options)
  response = Response.parse(Net::HTTP.post_form(URI.parse(MESSAGE_URL), sms_parameters))
end