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-1.1.8 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.7 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.6 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.5 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.4 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.3 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.2 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.1.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-1.0.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.7 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.6 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.5 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.4 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.3 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.2 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.9.1 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.33 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.32 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.31 lib/ecoportal/api/common/content/wrapped_response.rb
ecoportal-api-v2-0.8.30 lib/ecoportal/api/common/content/wrapped_response.rb