Class: ShiftPlanning::AuthenticationKeeper
- Inherits:
-
Object
- Object
- ShiftPlanning::AuthenticationKeeper
- Defined in:
- lib/shift_planning/authentication_keeper.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(api_key, username, password) ⇒ AuthenticationKeeper
constructor
A new instance of AuthenticationKeeper.
- #logout ⇒ Object
- #run(&block) ⇒ Object
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
#client ⇒ Object (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
#logout ⇒ Object
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) login unless @client.connection.authenticated? block.call @client rescue ShiftPlanning::ApiError => e raise e if e.code != 3 login block.call @client end |