Sha256: 2c554a197c391cf351184156d7d0deb7d0890a0180f248a34ff485226e347ce1

Contents?: true

Size: 988 Bytes

Versions: 12

Compression:

Stored size: 988 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)
            @response = response
            @klass    = klass
            @key      = key

            if @response.success?
              @result =
                if data.is_a?(Array)
                  data.map do |doc|
                    @klass.new(doc)
                  end
                else
                  @klass.new(data)
                end
            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

12 entries across 12 versions & 1 rubygems

Version Path
ecoportal-api-oozes-0.7.4 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.7.3 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.7.2 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.7.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.7.0 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.6.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.6.0 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.5.9 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.5.8 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.5.7 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.5.6 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-oozes-0.5.5 lib/ecoportal/api/common/content/wrapped_response.rb