Class: Stealth::Services::Twilio::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Stealth::Services::Twilio::Client
- Defined in:
- lib/stealth/services/twilio/client.rb
Instance Attribute Summary collapse
-
#reply ⇒ Object
readonly
Returns the value of attribute reply.
-
#twilio_client ⇒ Object
readonly
Returns the value of attribute twilio_client.
Instance Method Summary collapse
-
#initialize(reply:) ⇒ Client
constructor
A new instance of Client.
- #transmit ⇒ Object
Constructor Details
#initialize(reply:) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stealth/services/twilio/client.rb', line 17 def initialize(reply:) @reply = reply account_sid = Stealth.config.twilio.account_sid api_key = Stealth.config.twilio.api_key auth_token = Stealth.config.twilio.auth_token if api_key.present? @twilio_client = ::Twilio::REST::Client.new( api_key, auth_token, account_sid ) else @twilio_client = ::Twilio::REST::Client.new(account_sid, auth_token) end end |
Instance Attribute Details
#reply ⇒ Object (readonly)
Returns the value of attribute reply.
15 16 17 |
# File 'lib/stealth/services/twilio/client.rb', line 15 def reply @reply end |
#twilio_client ⇒ Object (readonly)
Returns the value of attribute twilio_client.
15 16 17 |
# File 'lib/stealth/services/twilio/client.rb', line 15 def twilio_client @twilio_client end |
Instance Method Details
#transmit ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/stealth/services/twilio/client.rb', line 32 def transmit # Don't transmit anything for delays return true if reply.blank? begin response = twilio_client..create(**reply) rescue ::Twilio::REST::RestError => e case e. when /21610/ # Attempt to send to unsubscribed recipient raise Stealth::Errors::UserOptOut when /21211/ # Invalid 'To' Phone Number raise Stealth::Errors::InvalidSessionID when /21612/ # 'To' phone number is not currently reachable via SMS raise Stealth::Errors::InvalidSessionID when /21614/ # 'To' number is not a valid mobile number raise Stealth::Errors::InvalidSessionID when /30003/ # Unreachable destination handset raise Stealth::Errors::InvalidSessionID when /30004/ # Message Blocked raise Stealth::Errors::MessageFiltered when /30005/ # Unknown destination handset raise Stealth::Errors::InvalidSessionID when /30006/ # Landline or unreachable carrier raise Stealth::Errors::InvalidSessionID when /30007/ # Message filtered raise Stealth::Errors::MessageFiltered when /30008/ # Unknown error 🤷♂️ raise Stealth::Errors::UnknownServiceError else raise end end Stealth::Logger.l( topic: "twilio", message: "Transmitting. Response: #{response.status}: #{response.}" ) end |