Class: Xip::Services::Twilio::Client
- Inherits:
-
BaseClient
- Object
- BaseClient
- Xip::Services::Twilio::Client
- Defined in:
- lib/xip/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.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/xip/services/twilio/client.rb', line 16 def initialize(reply:) @reply = reply account_sid = Xip.config.twilio.account_sid api_key = Xip.config.twilio.api_key auth_token = Xip.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.
14 15 16 |
# File 'lib/xip/services/twilio/client.rb', line 14 def reply @reply end |
#twilio_client ⇒ Object (readonly)
Returns the value of attribute twilio_client.
14 15 16 |
# File 'lib/xip/services/twilio/client.rb', line 14 def twilio_client @twilio_client end |
Instance Method Details
#transmit ⇒ Object
31 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 |
# File 'lib/xip/services/twilio/client.rb', line 31 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 Xip::Errors::UserOptOut when /21612/ # 'To' phone number is not currently reachable via SMS raise Xip::Errors::UserOptOut when /21614/ # 'To' number is not a valid mobile number raise Xip::Errors::UserOptOut when /30004/ # Message blocked raise Xip::Errors::UserOptOut when /21211/ # Invalid 'To' Phone Number raise Xip::Errors::InvalidSessionID when /30003/ # Unreachable destination handset raise Xip::Errors::InvalidSessionID when /30005/ # Unknown destination handset raise Xip::Errors::InvalidSessionID else raise end end Xip::Logger.l( topic: "twilio", message: "Transmitting. Response: #{response.status}: #{response.error_message}" ) end |