Sha256: b662a3b9f10ac60b01f5247a59558facd7660f54f00a237fcec56737a81ac147

Contents?: true

Size: 1021 Bytes

Versions: 9

Compression:

Stored size: 1021 Bytes

Contents

module Ecoportal
  module API
    module Common
      module Content
        class WrappedResponse < Ecoportal::API::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

9 entries across 9 versions & 1 rubygems

Version Path
ecoportal-api-v2-2.0.16 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.15 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.14 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.12 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.11 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.10 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.9 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.8 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-2.0.7 lib/ecoportal/api/common/content/wrapped_response.rb