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_pretty if success? each(&:print_pretty) else puts "Request failed." end end end end end end