Class: Unimatrix::Authorization::Response

Inherits:
Response
  • Object
show all
Defined in:
lib/unimatrix/authorization/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#success?

Constructor Details

#initialize(http_response, path = "") ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unimatrix/authorization/response.rb', line 9

def initialize( http_response, path = "" )
  @request_path   = path
  @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, @request_path ) do | parser |
      @resources = parser.resources
      @success   = !( parser.type_name == 'error' )
    end
  else
    @success  = false
    @resources << Unimatrix::Error.new(
      message: "#{ @code }: #{ http_response.message }."
    )
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/unimatrix/authorization/response.rb', line 6

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/unimatrix/authorization/response.rb', line 5

def code
  @code
end

#resourcesObject (readonly)

Returns the value of attribute resources.



7
8
9
# File 'lib/unimatrix/authorization/response.rb', line 7

def resources
  @resources
end