Class: Pickpoint::Auth::State

Inherits:
Object
  • Object
show all
Defined in:
lib/pickpoint/auth.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, session: nil) ⇒ State

Returns a new instance of State.



37
38
39
40
# File 'lib/pickpoint/auth.rb', line 37

def initialize(api_key: nil, session: nil)
  @api_key = api_key
  @session = session
end

Instance Method Details

#apply!(headers) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/pickpoint/auth.rb', line 46

def apply!(headers)
  headers["Accept"] = "application/json"
  if @api_key
    headers["x-api-key"] = @api_key
    return
  end
  headers["Authorization"] = "Bearer #{@session.token}"
end

#bearer?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/pickpoint/auth.rb', line 42

def bearer?
  !@session.nil?
end

#refresh_after_unauthorizedObject



55
56
57
58
59
# File 'lib/pickpoint/auth.rb', line 55

def refresh_after_unauthorized
  return false if @session.nil?

  @session.refresh_after_unauthorized
end