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