Sha256: dbd08bcdcc95b968b4f467ab7dd46e3c60cd6be8b6c5104527504311727fa577

Contents?: true

Size: 1005 Bytes

Versions: 7

Compression:

Stored size: 1005 Bytes

Contents

module Ecoportal
  module API
    module Common
      module Content
        class WrappedResponse < Common::WrappedResponse
          include Enumerable

          attr_reader :response, :result

          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

          def data
            return @data if instance_variable_defined?(:@data)

            @data = (response.body || {})["data"]
            @data = @data[@key] if @key && @data
            @data
          end

          def body
            data.to_s
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.6 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.5 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.4 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.3 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.2 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.0 lib/ecoportal/api/common/content/wrapped_response.rb