Class: ActionTexter::NexmoClient
- Defined in:
- lib/action_texter/nexmo.rb
Overview
Implementation of client for Nexmo: nexmo.com
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #deliver(message) ⇒ Object
-
#initialize(key, secret) ⇒ NexmoClient
constructor
Create a new Nexmo client with key and secret.
- #to_s ⇒ Object
Methods inherited from Client
Constructor Details
#initialize(key, secret) ⇒ NexmoClient
Create a new Nexmo client with key and secret.
63 64 65 66 67 |
# File 'lib/action_texter/nexmo.rb', line 63 def initialize(key, secret) super() self.key = key self.secret = secret end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
57 58 59 |
# File 'lib/action_texter/nexmo.rb', line 57 def key @key end |
#secret ⇒ Object
Returns the value of attribute secret.
57 58 59 |
# File 'lib/action_texter/nexmo.rb', line 57 def secret @secret end |
Instance Method Details
#deliver(message) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/action_texter/nexmo.rb', line 69 def deliver() client = Net::HTTP.new("rest.nexmo.com", 443) client.use_ssl = true # Nexmo doesn't like phone numbers starting with a + # Pattern only matches phones that are pristine phone numbers starting with a +, and leaves everything else alone pattern = /^\+(\d+)$/ from = (.from =~ pattern ? .from.gsub(pattern, '\1') : .from ) to = (.to =~ pattern ? .to.gsub(pattern, '\1') : .to ) response = client.post( "/sms/json", URI.encode_www_form("username" => @key, "password" => @secret, "from" => from, "to" => to, "text" => .text, "client-ref" => .reference), {"Content-Type" => "application/x-www-form-urlencoded"}) return ActionTexter::NexmoResponse.new(response.body) end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/action_texter/nexmo.rb', line 93 def to_s "#<#{self.class.name}:#{key}>" end |