Module: Paychex::Client::Auth
- Included in:
- Paychex::Client
- Defined in:
- lib/paychex/client/auth.rb
Instance Method Summary collapse
-
#authorize(options = {}) ⇒ Object
Authorize a client and get back a access token with expiry.
-
#token_expired? ⇒ Boolean
Indicates expiry of the auth token.
Instance Method Details
#authorize(options = {}) ⇒ Object
Authorize a client and get back a access token with expiry.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/paychex/client/auth.rb', line 5 def ( = {}) response = auth('auth/oauth/v2/token', ) if response.body.is_a?(Hash) && response.body['access_token'] self.access_token = response.body['access_token'] self.token_timeout = Time.new + response.body['expires_in'] response else # raise error when token is missing. raise Paychex::BadRequest, response end end |
#token_expired? ⇒ Boolean
Indicates expiry of the auth token
18 19 20 |
# File 'lib/paychex/client/auth.rb', line 18 def token_expired? token_timeout < Time.new end |