Class: ShiftPlanning::AuthenticationKeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/shift_planning/authentication_keeper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, username, password) ⇒ AuthenticationKeeper

Returns a new instance of AuthenticationKeeper.



4
5
6
7
8
# File 'lib/shift_planning/authentication_keeper.rb', line 4

def initialize(api_key, username, password)
  @client = ShiftPlanning::Client.new(api_key)
  @username = username
  @password = password
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



2
3
4
# File 'lib/shift_planning/authentication_keeper.rb', line 2

def client
  @client
end

Instance Method Details

#logoutObject



19
20
21
# File 'lib/shift_planning/authentication_keeper.rb', line 19

def logout
  @client.staff.get_logout if @client.connection.authenticated?
end

#run(&block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/shift_planning/authentication_keeper.rb', line 10

def run(&block)
   unless @client.connection.authenticated?
  block.call @client
rescue ShiftPlanning::ApiError => e
  raise e if e.code != 3
  
  block.call @client
end