Sha256: a824a6ab5a8fd1fd523e9307f0696ff6c55bcaac3a0caf49f80b7ac0d950d72f
Contents?: true
Size: 1.01 KB
Versions: 10
Compression:
Stored size: 1.01 KB
Contents
module Ecoportal module API module Common class WrappedResponse include Enumerable attr_reader :response, :result def initialize(response, klass) @response = response @klass = klass if @response.success? @result = if @response.body.is_a?(Array) @response.body.map do |doc| @klass.new(doc) end else @klass.new(@response.body) end end end def body response.body.to_s end def each [*@result].each do |doc| yield doc end end def status @response.status.code end def success? @response.success? end def print if success? each(&:print) else puts "Request failed." end end end end end end
Version data entries
10 entries across 10 versions & 1 rubygems