Sha256: fe6fa062d139e387ac9bd61754bfd27cf9c32e303b1c16791b9da817e7fcc685
Contents?: true
Size: 940 Bytes
Versions: 33
Compression:
Stored size: 940 Bytes
Contents
module Unimatrix class Response attr_reader :code attr_reader :body attr_reader :resources def initialize( http_response ) @success = http_response.is_a?( Net::HTTPOK ) @code = http_response.code @resources = [] @body = decode_response_body( http_response ) if ( @body && @body.respond_to?( :keys ) ) Parser.new( @body ) do | parser | @resources = parser.resources @success = !( parser.type_name == 'error' ) end else @success = false @resources << Error.new( message: "#{ @code }: #{ http_response.message }." ) end end def success? @success end protected; def decode_response_body( http_response ) body = http_response.body if body.present? JSON.parse( body ) rescue nil else nil end end end end
Version data entries
33 entries across 33 versions & 1 rubygems