Sha256: 123082ceff56d707321198362ce19e8c332bbfff5a7e75fe6c9d44c87eabc2e3
Contents?: true
Size: 1017 Bytes
Versions: 5
Compression:
Stored size: 1017 Bytes
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_pretty if success? each(&:print_pretty) else puts "Request failed." end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems