Class: Youlend::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/youlend/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



12
13
14
# File 'lib/youlend/response.rb', line 12

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#http_responseObject (readonly)

Returns the value of attribute http_response.



9
10
11
# File 'lib/youlend/response.rb', line 9

def http_response
  @http_response
end

Instance Method Details

#dataObject



34
35
36
# File 'lib/youlend/response.rb', line 34

def data
  @http_response.body
end

#errorsObject



28
29
30
31
32
# File 'lib/youlend/response.rb', line 28

def errors
  return [] unless unauthorized? || token_expired?

  @http_response.body
end

#token_expired?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/youlend/response.rb', line 20

def token_expired?
  auth_header = @http_response.headers['www-authenticate']

  return false unless auth_header

  auth_header.match?(/.*token is expired.*/)
end

#unauthorized?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/youlend/response.rb', line 16

def unauthorized?
  status == 401
end