Class: Credova::Response
- Inherits:
-
Object
- Object
- Credova::Response
- Defined in:
- lib/credova/response.rb
Instance Attribute Summary collapse
-
#success ⇒ Object
Returns the value of attribute success.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #body ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/credova/response.rb', line 6 def initialize(response) @response = response case @response when Net:: Credova::Error::NotAuthorized.new(@response.body) when Net::HTTPNotFound Credova::Error::NotFound.new(@response.body) when Net::HTTPNoContent Credova::Error::NoContent.new(@response.body) when Net::HTTPOK, Net::HTTPSuccess self.success = true _data = (JSON.parse(@response.body) if @response.body.present?) @data = case when _data.is_a?(Hash) _data.deep_symbolize_keys when _data.is_a?(Array) _data.map(&:deep_symbolize_keys) end else raise Credova::Error::RequestError.new(@response.body) end end |
Instance Attribute Details
#success ⇒ Object
Returns the value of attribute success.
4 5 6 |
# File 'lib/credova/response.rb', line 4 def success @success end |
Instance Method Details
#[](key) ⇒ Object
31 32 33 |
# File 'lib/credova/response.rb', line 31 def [](key) @data[key] end |
#body ⇒ Object
35 36 37 |
# File 'lib/credova/response.rb', line 35 def body @data end |
#fetch(key) ⇒ Object
39 40 41 |
# File 'lib/credova/response.rb', line 39 def fetch(key) @data.fetch(key) end |
#success? ⇒ Boolean
43 44 45 |
# File 'lib/credova/response.rb', line 43 def success? !!success end |