Class: Majestic::Api::Response
- Inherits:
-
Object
- Object
- Majestic::Api::Response
- Defined in:
- lib/majestic/api/response.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#error_message ⇒ Object
Returns the value of attribute error_message.
-
#full_error ⇒ Object
Returns the value of attribute full_error.
-
#items ⇒ Object
Returns the value of attribute items.
-
#parsed_items ⇒ Object
Returns the value of attribute parsed_items.
-
#response ⇒ Object
Returns the value of attribute response.
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(response = nil) ⇒ Response
constructor
A new instance of Response.
- #parse_response ⇒ Object
- #stacktrace ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(response = nil) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 |
# File 'lib/majestic/api/response.rb', line 6 def initialize(response = nil) self.response = response self.success = false self.items = [] self.parsed_items = [] parse_response end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def code @code end |
#error_message ⇒ Object
Returns the value of attribute error_message.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def @error_message end |
#full_error ⇒ Object
Returns the value of attribute full_error.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def full_error @full_error end |
#items ⇒ Object
Returns the value of attribute items.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def items @items end |
#parsed_items ⇒ Object
Returns the value of attribute parsed_items.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def parsed_items @parsed_items end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def response @response end |
#success ⇒ Object
Returns the value of attribute success.
4 5 6 |
# File 'lib/majestic/api/response.rb', line 4 def success @success end |
Instance Method Details
#parse_response ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/majestic/api/response.rb', line 15 def parse_response if self.response.is_a?(Faraday::Response) self.response = (self.response && self.response.body) ? self.response.body : nil if self.response self.code = self.response.fetch("Code", "") self.success = self.code.downcase.eql?("ok") self. = self.response.fetch("ErrorMessage", "") self.full_error = self.response.fetch("FullError", "") if success? self.parsed_items = self.response.fetch("DataTables", {}).fetch("Results", {}).fetch("Data", []) end end end end |
#stacktrace ⇒ Object
36 37 38 |
# File 'lib/majestic/api/response.rb', line 36 def stacktrace self.full_error end |
#success? ⇒ Boolean
32 33 34 |
# File 'lib/majestic/api/response.rb', line 32 def success? self.success end |