Sha256: 42a6120f4a970ec3dc60ce50ff573fe8f8420d5c20c66dd59996636e04b7d122

Contents?: true

Size: 989 Bytes

Versions: 47

Compression:

Stored size: 989 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

47 entries across 47 versions & 2 rubygems

Version Path
ecoportal-api-v2-0.8.29 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.28 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.27 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.26 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.25 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.24 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.23 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.22 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.21 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.20 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.19 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.18 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.17 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.16 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.15 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.14 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.13 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.12 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.11 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.10 lib/ecoportal/api/common/content/wrapped_response.rb