Class: TatangoSMS::MT

Inherits:
Object
  • Object
show all
Defined in:
lib/tatango_sms/mt.rb

Overview

TatangoSMS::MT makes it easy to send a message through the Tatango SMS Gateway

Examples:

require 'tatango_sms/mt'
TatangoSMS::MT.send('tatangosmsgatewayKEY', 'password', '9998887777', 'A message')
# or
mt = TatangoSMS::MT.new 'tatangosmsgatewayKEY', 'password'
response = mt.send '9998887777', 'Another silly message'

Constant Summary collapse

@@gateway_url =
'http://gateway.tatango.com/messages'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, password) ⇒ MT

create an MT instance to avoid repetition of key and password



59
60
61
# File 'lib/tatango_sms/mt.rb', line 59

def initialize(key, password)
  @gateway_key, @gateway_password = key, password
end

Class Method Details

.send(key, password, phone_number, message) ⇒ Object

see MT#send



49
50
51
# File 'lib/tatango_sms/mt.rb', line 49

def send(key, password, phone_number, message)
  new(key, password).send(phone_number, message)
end

.url=(url) ⇒ Object

:nodoc:



53
54
55
# File 'lib/tatango_sms/mt.rb', line 53

def url=(url) # :nodoc:
  @@gateway_url = url
end

Instance Method Details

#send(phone_number, message) ⇒ Object

send a message to phone_number

returns a Net::HTTP response



66
67
68
69
70
71
72
73
74
75
# File 'lib/tatango_sms/mt.rb', line 66

def send(phone_number, message)
  Net::HTTP.post_form(
    URI.parse(@@gateway_url), {
      'key' => @gateway_key,
      'recipient' => phone_number,
      'message' => message,
      'hash' => Digest::MD5.hexdigest(@gateway_password + message)
    }
  )
end