Class: EY::GateKeeper::Client::ServerResponse

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/ey_gatekeeper/client/server_response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ServerResponse

Returns a new instance of ServerResponse.



6
7
8
9
# File 'lib/ey_gatekeeper/client/server_response.rb', line 6

def initialize(response)
  status, headers, body = response
  super(body, status, headers)
end

Instance Method Details

#indicates_any_auth_error?(*messages) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/ey_gatekeeper/client/server_response.rb', line 19

def indicates_any_auth_error?(*messages)
  if auth_error_header = headers['X-Gatekeeper-Authentication-Error']
    messages.map { |message| EY::GateKeeper::Responses.string(message) }.include?(auth_error_header)
  else
    false
  end
end

#is_gatekeeper_unauthorized?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ey_gatekeeper/client/server_response.rb', line 15

def is_gatekeeper_unauthorized?
  (unauthorized? && headers['X-Gatekeeper-Authentication-Error']) ? true : false
end

#needs_gatekeeper_token_refresh?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ey_gatekeeper/client/server_response.rb', line 27

def needs_gatekeeper_token_refresh?
  is_gatekeeper_unauthorized? && indicates_any_auth_error?(:expired_token, :expired_impersonation_token)
end

#to_rackObject



31
32
33
# File 'lib/ey_gatekeeper/client/server_response.rb', line 31

def to_rack
  [status, headers, body]
end

#unauthorized?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/ey_gatekeeper/client/server_response.rb', line 11

def unauthorized?
  status == 401
end