Sha256: f75baff0d2b0bb00502e92821da03aa38c7f4dfc53b2b150b74f65cf38cc1b8b

Contents?: true

Size: 681 Bytes

Versions: 8

Compression:

Stored size: 681 Bytes

Contents

module Paychex
  class Client
    module Auth
      # Authorize a client and get back a access token with expiry.
      def authorize(options = {})
        response = auth('auth/oauth/v2/token', options)
        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

      # Indicates expiry of the auth token
      def token_expired?
        token_timeout < Time.new
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
paychex-0.3.3 lib/paychex/client/auth.rb
paychex-0.3.2 lib/paychex/client/auth.rb
paychex-0.3.1 lib/paychex/client/auth.rb
paychex-0.3.0 lib/paychex/client/auth.rb
paychex-0.2.2 lib/paychex/client/auth.rb
paychex-0.2.1 lib/paychex/client/auth.rb
paychex-0.2.0 lib/paychex/client/auth.rb
paychex-0.1.1 lib/paychex/client/auth.rb