Sha256: 5edfcf2f78f36c3c776a8b2d293614c48107861381ea045f0d733346121777f2

Contents?: true

Size: 650 Bytes

Versions: 5

Compression:

Stored size: 650 Bytes

Contents

module Ecoportal
  module API
    module Common
      class Response

        attr_reader :status, :body

        def initialize(response)
          @status = response.status
          @body   = [].tap do |body_data|
            response.body.each do |chunk|
              body_data << chunk
            end
          end.join("")
          @body   = JSON.parse(@body.to_s) rescue nil
          response
        end

        def success?
          @status.success?
        end

        def print_pretty
          puts "Status: #{@status.code}"
          puts "Body:"
          puts JSON.pretty_generate(@body)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecoportal-api-0.8.5 lib/ecoportal/api/common/response.rb
ecoportal-api-0.8.4 lib/ecoportal/api/common/response.rb
ecoportal-api-0.8.3 lib/ecoportal/api/common/response.rb
ecoportal-api-0.8.2 lib/ecoportal/api/common/response.rb
ecoportal-api-0.7.5 lib/ecoportal/api/common/response.rb