Class: Outbox::Msg91::Client

Inherits:
Clients::Base
  • Object
show all
Defined in:
lib/outbox/msg91/client.rb

Overview

Uses MSG91s php API client to deliver SMS messages.

Outbox::Messages::SMS.default_client(
  :msg91,
  authkey = "xxxxxxxxxxxxxxxxxxx")
sms = Outbox::Messages::SMS.new(
  from:  = "ABCDEFG"  <6 digit code>   
  body: 'Hello World'
)
sms.deliver('+15552224444')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = nil) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
# File 'lib/outbox/msg91/client.rb', line 16

def initialize(settings = nil)
  super

  options = @settings.dup
  p @options

  # 4 indicates transactional sms
  @route_code = 4
  @authkey = options[:authkey]
end

Instance Attribute Details

#auth_keyObject (readonly)

Returns the value of attribute auth_key.



14
15
16
# File 'lib/outbox/msg91/client.rb', line 14

def auth_key
  @auth_key
end

#senderidObject (readonly)

Returns the value of attribute senderid.



14
15
16
# File 'lib/outbox/msg91/client.rb', line 14

def senderid
  @senderid
end

Instance Method Details

#deliver(sms) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/outbox/msg91/client.rb', line 35

def deliver(sms)
  params = {:authkey => @authkey, :mobiles => sms.to, :message => sms.body , :sender => sms.from ,:route => @route_code, :response => "json"}
  url = "http://api.msg91.com"
  uri = full_path(url, '/api/sendhttp.php', params)
  #p uri
  response = Net::HTTP.get(uri)
end

#full_path(url, path, params) ⇒ Object



28
29
30
31
32
# File 'lib/outbox/msg91/client.rb', line 28

def full_path(url, path, params)
  encoded_params = URI.encode_www_form(params)
  params_string = [path, encoded_params].join("?")
  URI.parse(url + params_string)
end