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 says of a grant it will not take, in the prose it answers with. About the token rather than about the app, which is what tells it from the 401 a wrong client id and secret get — and that one is every account at once rather than this one.
/refresh token is not valid/
Class Method Summary collapse
-
.post(params = {}) ⇒ Hash
Trade a grant for credentials.
Class Method Details
.post(params = {}) ⇒ Hash
Trade a grant for credentials.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jbr/token.rb', line 17 def self.post(params = {}) response = Net::HTTP.post_form URI(URL), params raise Refused, response.body if REFUSAL.match? response.body 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 |