Class: Exotel::Response
- Inherits:
-
Object
- Object
- Exotel::Response
- Defined in:
- lib/exotel/response.rb
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #set_response_data(response_base) ⇒ Object
- #set_response_error(response_base) ⇒ Object
- #set_variable(key, value) ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/exotel/response.rb', line 5 def initialize(response) #To handle unexpected parsing from httparty response = MultiXml.parse(response) unless response.is_a?(Hash) response_base = response['TwilioResponse'] unless response_base.include?('RestException') set_response_data(response_base) else set_response_error(response_base) end end |
Instance Method Details
#set_response_data(response_base) ⇒ Object
16 17 18 19 20 |
# File 'lib/exotel/response.rb', line 16 def set_response_data(response_base) (response_base['Call'] or response_base['SMSMessage']).each do |key, value| set_variable(key, value) end end |
#set_response_error(response_base) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/exotel/response.rb', line 22 def set_response_error(response_base) response_base['RestException'].each do |key, value| set_variable(key, value) instance_variable_set('@status', 'DND') #Override end end |
#set_variable(key, value) ⇒ Object
29 30 31 32 33 |
# File 'lib/exotel/response.rb', line 29 def set_variable(key, value) attr_name = underscore_format(key) self.class.send(:attr_accessor, attr_name) #Set accessors dynamically instance_variable_set("@#{attr_name}", value) end |