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
Defaults to Configuration.login_host.
- #refresh ⇒ Object
- #revoke ⇒ Object
Methods included from Requestable
#delete, #get, #patch, #post, #put, #sync
Constructor Details
#initialize(client_id:, client_secret:, store:, options: {}) ⇒ Client
Defaults to Configuration.login_host
33 34 35 36 37 38 39 40 41 |
# File 'lib/procore/client.rb', line 33 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[:login_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
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/procore/client.rb', line 44 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/procore/client.rb', line 67 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 |