Class: Jbr::Token
- Inherits:
-
Object
- Object
- Jbr::Token
- Defined in:
- lib/jbr/token.rb
Overview
The endpoint that trades an authorization code or a refresh token for credentials.
Constant Summary collapse
- URL =
Where a grant is exchanged.
'https://api.getjobber.com/api/oauth/token'- REFUSAL =
What Jobber calls a grant that is no good, in the OAuth 2 word for it.
'invalid_grant'
Class Method Summary collapse
-
.post(params = {}) ⇒ Hash
Trade a grant for credentials.
Class Method Details
.post(params = {}) ⇒ Hash
Trade a grant for credentials.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jbr/token.rb', line 15 def self.post(params = {}) response = Net::HTTP.post_form URI(URL), params raise Refused, response.body if refused? response raise Error, response.body unless response.is_a? Net::HTTPSuccess output = JSON.parse response.body { access_token: output['access_token'], refresh_token: output['refresh_token'], expires_at: (Time.now + output.fetch('expires_in', 3600).to_i), } end |