Class: Smess::Twilio
- Includes:
- Logging
- Defined in:
- lib/smess/outputs/twilio.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#api_secret ⇒ Object
Returns the value of attribute api_secret.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#callback_url ⇒ Object
Returns the value of attribute callback_url.
-
#from ⇒ Object
Returns the value of attribute from.
-
#messaging_service_sid ⇒ Object
Returns the value of attribute messaging_service_sid.
-
#sid ⇒ Object
Returns the value of attribute sid.
-
#verify_service_sid ⇒ Object
Returns the value of attribute verify_service_sid.
Attributes inherited from Output
Instance Method Summary collapse
- #check(code) ⇒ Object
- #deliver ⇒ Object
-
#initialize(config) ⇒ Twilio
constructor
A new instance of Twilio.
- #send_feedback(message_sid) ⇒ Object
- #validate_config ⇒ Object
- #verify(using: 'sms') ⇒ Object
Methods included from Logging
Constructor Details
#initialize(config) ⇒ Twilio
Returns a new instance of Twilio.
7 8 9 10 |
# File 'lib/smess/outputs/twilio.rb', line 7 def initialize(config) super @results = [] end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def api_key @api_key end |
#api_secret ⇒ Object
Returns the value of attribute api_secret.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def api_secret @api_secret end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def auth_token @auth_token end |
#callback_url ⇒ Object
Returns the value of attribute callback_url.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def callback_url @callback_url end |
#from ⇒ Object
Returns the value of attribute from.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def from @from end |
#messaging_service_sid ⇒ Object
Returns the value of attribute messaging_service_sid.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def messaging_service_sid @messaging_service_sid end |
#sid ⇒ Object
Returns the value of attribute sid.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def sid @sid end |
#verify_service_sid ⇒ Object
Returns the value of attribute verify_service_sid.
12 13 14 |
# File 'lib/smess/outputs/twilio.rb', line 12 def verify_service_sid @verify_service_sid end |
Instance Method Details
#check(code) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/smess/outputs/twilio.rb', line 58 def check(code) response = client.verify.v2 .services(verify_service_sid) .verification_checks .create(to: to, code: code) { 'sid' => response.sid, 'service_sid' => response.service_sid, 'account_sid' => response.account_sid, 'to' => response.to, 'channel' => response.channel, 'status' => response.status, 'valid' => response.valid, 'amount' => response.amount, 'payee' => response.payee, 'date_created' => response.date_created, 'date_updated' => response.date_updated, 'sna_attempts_error_codes' => response.sna_attempts_error_codes, } end |
#deliver ⇒ Object
30 31 32 |
# File 'lib/smess/outputs/twilio.rb', line 30 def deliver send_one_sms sms. end |
#send_feedback(message_sid) ⇒ Object
26 27 28 |
# File 'lib/smess/outputs/twilio.rb', line 26 def send_feedback() client.().feedback.create(outcome: "confirmed") end |
#validate_config ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/smess/outputs/twilio.rb', line 14 def validate_config @sid = config.fetch(:sid) @auth_token = config.fetch(:auth_token, nil) @api_key = config.fetch(:api_key, nil) @api_secret = config.fetch(:api_secret, nil) raise "missing API credentials" unless auth_token.present? || (api_key.present? && api_secret.present?) @from = config.fetch(:from, nil) @messaging_service_sid = config.fetch(:messaging_service_sid, nil) @callback_url = config.fetch(:callback_url) @verify_service_sid = config.fetch(:verify_service_sid, nil) end |
#verify(using: 'sms') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/smess/outputs/twilio.rb', line 34 def verify(using: 'sms') response = client.verify.v2 .services(verify_service_sid) .verifications .create(to: to, channel: using) { 'sid' => response.sid, 'service_sid' => response.service_sid, 'account_sid' => response.account_sid, 'to' => response.to, 'channel' => response.channel, 'status' => response.status, 'valid' => response.valid, 'lookup' => response.lookup, 'amount' => response.amount, 'payee' => response.payee, 'send_code_attempts' => response.send_code_attempts, 'date_created' => response.date_created, 'date_updated' => response.date_updated, 'sna' => response.sna, 'url' => response.url } end |