Class: Ecoportal::API::Common::Content::WrappedResponse
- Inherits:
-
WrappedResponse
- Object
- WrappedResponse
- Ecoportal::API::Common::Content::WrappedResponse
- Includes:
- Enumerable
- Defined in:
- lib/ecoportal/api/common/content/wrapped_response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #body ⇒ Object
- #data ⇒ Object
-
#initialize(response, klass, key: nil) ⇒ WrappedResponse
constructor
rubocop:disable Lint/MissingSuper.
Constructor Details
#initialize(response, klass, key: nil) ⇒ WrappedResponse
rubocop:disable Lint/MissingSuper
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ecoportal/api/common/content/wrapped_response.rb', line 10 def initialize(response, klass, key: nil) # rubocop:disable Lint/MissingSuper @response = response @klass = klass @key = key return unless @response.success? @result = if data.is_a?(Array) data.map do |doc| @klass.new(doc) end else @klass.new(data) end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/ecoportal/api/common/content/wrapped_response.rb', line 8 def response @response end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
8 9 10 |
# File 'lib/ecoportal/api/common/content/wrapped_response.rb', line 8 def result @result end |
Instance Method Details
#body ⇒ Object
35 36 37 |
# File 'lib/ecoportal/api/common/content/wrapped_response.rb', line 35 def body data.to_s end |
#data ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ecoportal/api/common/content/wrapped_response.rb', line 27 def data return @data if instance_variable_defined?(:@data) @data = (response.body || {})["data"] @data = @data[@key] if @key && @data @data end |