module Ecoportal module API module Common class WrappedResponse include Enumerable attr_reader :response, :result def initialize(response, klass) @response = response @klass = klass return unless @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 def body response.body.to_s end def each(&block) [*result].each(&block) end def status response.status.code end def success? response.success? end def print_pretty return each(&:print_pretty) if success? "Request failed." end end end end end