Class: Outbox::Msg91::Client
- Inherits:
-
Clients::Base
- Object
- Clients::Base
- Outbox::Msg91::Client
- 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
-
#auth_key ⇒ Object
readonly
Returns the value of attribute auth_key.
-
#senderid ⇒ Object
readonly
Returns the value of attribute senderid.
Instance Method Summary collapse
-
#deliver(sms) ⇒ Object
MSG91 API Documented at api.msg91.com/apidoc/textsms/send-sms.php.
- #full_path(url, path, params) ⇒ Object
-
#initialize(settings = nil) ⇒ Client
constructor
A new instance of Client.
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 = @settings.dup p @options # 4 indicates transactional sms @route_code = 4 @authkey = [:authkey] end |
Instance Attribute Details
#auth_key ⇒ Object (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 |
#senderid ⇒ Object (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
MSG91 API Documented at api.msg91.com/apidoc/textsms/send-sms.php
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 |