Class: Procore::Client
- Inherits:
-
Object
- Object
- Procore::Client
- Includes:
- Requestable
- Defined in:
- lib/procore/client.rb
Overview
Main class end users interact with. An instance of a client can call out the Procore API using methods matching standard HTTP verbs #get, #post, #put, #patch, #delete.
Constant Summary
Constants included from Requestable
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
-
#initialize(client_id:, client_secret:, store:, options: {}) ⇒ Client
constructor
A new instance of Client.
- #refresh ⇒ Object
- #revoke ⇒ Object
Methods included from Requestable
#delete, #get, #patch, #post, #put, #sync
Constructor Details
#initialize(client_id:, client_secret:, store:, options: {}) ⇒ Client
Returns a new instance of Client.
31 32 33 34 35 36 37 38 39 |
# File 'lib/procore/client.rb', line 31 def initialize(client_id:, client_secret:, store:, options: {}) @options = Procore::Defaults::.merge() @credentials = Procore::Auth::AccessTokenCredentials.new( client_id: client_id, client_secret: client_secret, host: @options[:host], ) @store = store end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/procore/client.rb', line 20 def @options end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
20 21 22 |
# File 'lib/procore/client.rb', line 20 def store @store end |
Instance Method Details
#refresh ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/procore/client.rb', line 42 def refresh token = fetch_token begin new_token = @credentials.refresh( token: token.access_token, refresh: token.refresh_token, ) Util.log_info("Token Refresh Successful", store: store) store.save(new_token) rescue RuntimeError Util.log_error("Token Refresh Failed", store: store) raise Procore::OAuthError.new( "Unable to refresh the access token. Perhaps the Procore API is " \ "down or your access token store is misconfigured. Either " \ "way, you should clear the store and prompt the user to sign in " \ "again.", ) end end |
#revoke ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/procore/client.rb', line 65 def revoke token = fetch_token begin @credentials.revoke(token: token) Util.log_info("Token Revocation Successful", store: store) rescue RuntimeError Util.log_error("Token Revocation Failed", store: store) raise Procore::OAuthError.new( "Unable to revoke the access token. Perhaps the Procore API is " \ "down or your access token store is misconfigured. Either " \ "way, you should clear the store and prompt the user to sign in " \ "again.", ) end end |