Class: Jbr::OAuth
Overview
Credentials for one Jobber account, and the gateway to all they read or write.
Direct Known Subclasses
Constant Summary collapse
- DISCONNECT_MUTATION =
The mutation that revokes the app on the account.
<<~GRAPHQL mutation Disconnect { appDisconnect { app { name author } userErrors { message } } } GRAPHQL
Constants included from Asking
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
-
#account_id ⇒ String?
The account these credentials reach.
-
#expires_at ⇒ Object
readonly
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
-
#invalid_at ⇒ Object
readonly
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
-
#refresh_token ⇒ Object
readonly
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
Class Method Summary collapse
-
.client_id ⇒ String?
The client ID to interact with the API.
-
.client_secret ⇒ String?
The client secret to interact with the API.
-
.create(code:, redirect_uri:) ⇒ OAuth
Exchange an authorization code for credentials, then learn their account.
-
.post(params = {}) ⇒ Object
Exchange a code or a refresh token for credentials.
Instance Method Summary collapse
-
#account ⇒ Object
The resources these credentials read and write.
- #clients ⇒ Object
-
#delete ⇒ Object
Delete a token.
-
#initialize(credentials = {}) ⇒ OAuth
constructor
A new instance of OAuth.
- #invoices ⇒ Object
- #jobs ⇒ Object
- #quotes ⇒ Object
- #requests ⇒ Object
- #visits ⇒ Object
Methods included from Asking
Constructor Details
#initialize(credentials = {}) ⇒ OAuth
Returns a new instance of OAuth.
17 18 19 20 21 22 23 |
# File 'lib/jbr/oauth.rb', line 17 def initialize(credentials = {}) @access_token = credentials[:access_token] @refresh_token = credentials[:refresh_token] @expires_at = credentials[:expires_at] @account_id = credentials[:account_id] @invalid_at = credentials[:invalid_at] end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
26 27 28 |
# File 'lib/jbr/oauth.rb', line 26 def access_token @access_token end |
#account_id ⇒ String?
Returns the account these credentials reach.
28 29 30 |
# File 'lib/jbr/oauth.rb', line 28 def account_id @account_id end |
#expires_at ⇒ Object (readonly)
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
26 27 28 |
# File 'lib/jbr/oauth.rb', line 26 def expires_at @expires_at end |
#invalid_at ⇒ Object (readonly)
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
26 27 28 |
# File 'lib/jbr/oauth.rb', line 26 def invalid_at @invalid_at end |
#refresh_token ⇒ Object (readonly)
The credentials as Jobber last gave them, plus the moment a refusal to refresh landed.
26 27 28 |
# File 'lib/jbr/oauth.rb', line 26 def refresh_token @refresh_token end |
Class Method Details
.client_id ⇒ String?
Returns The client ID to interact with the API.
55 |
# File 'lib/jbr/oauth.rb', line 55 def self.client_id = ENV['JOBBER_CLIENT_ID'] |
.client_secret ⇒ String?
Returns The client secret to interact with the API.
58 |
# File 'lib/jbr/oauth.rb', line 58 def self.client_secret = ENV['JOBBER_CLIENT_SECRET'] |
.create(code:, redirect_uri:) ⇒ OAuth
Exchange an authorization code for credentials, then learn their account.
49 50 51 52 |
# File 'lib/jbr/oauth.rb', line 49 def self.create(code:, redirect_uri:) credentials = post code: code, redirect_uri: redirect_uri, grant_type: 'authorization_code' new(credentials).tap { |oauth| oauth.account_id = oauth.account.id } end |
Instance Method Details
#account ⇒ Object
The resources these credentials read and write.
31 |
# File 'lib/jbr/oauth.rb', line 31 def account = Account.new oauth: self |
#delete ⇒ Object
Delete a token. If the token is invalid, do nothing.
40 41 42 43 |
# File 'lib/jbr/oauth.rb', line 40 def delete client.query DISCONNECT_MUTATION rescue GraphQL::Unauthorized => e end |