procore 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: ab6a771f9ecbd227e500591c59381e08e70b1ad3cea2f82e767b4de2d88664b3
4
- data.tar.gz: 1159fa494f5d38ce2d0a0fbcbdb465bf6203e8989a96acf3bcceab915ea9dbac
2
+ SHA1:
3
+ metadata.gz: 9cd9c39ae342255313380ec2630ef51b60500eae
4
+ data.tar.gz: 5985c77c80a79229743539c37dc049b9a243939a
5
5
  SHA512:
6
- metadata.gz: e1c9f942d9c8223df00bff8c67b366adc85be3224d2a6ef41ee4e345d40cba8cc0ca71fe0361ff094be1ba358d3ad7ead40fc99d36bba8e5edac0dfc19932c57
7
- data.tar.gz: afb9275ad4ec9b1396f3f7bed77317eb39b8e6cacf5d82dc77b38e9a934491e439795fe7df432d27fdc337800b7343327f1cb9d7b70c072ed72244bcd41d6a0a
6
+ metadata.gz: 1db78e84a20c38b6cc6707c027d8649ab0a4e9c2c820c2d3b6bacbde1fc017ad337dd094fa8ad218794cb92c6ded0bf6e902d2d20becf30dc96529ac0afb93c9
7
+ data.tar.gz: 2c0a9ea9b6bb6e05ff31508dfccc06e439239214a6cd1e051c91ba1af808cf62685bab70673af4d8676eeb9121e852df5d4ab21e643ff404837717db56f1fc4b
data/.travis.yml CHANGED
@@ -1,30 +1,25 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3
4
- - 2.4
5
- - 2.5
6
- - 2.6
7
-
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
8
7
  services:
9
- - redis-server
10
- - memcached
11
-
8
+ - redis-server
9
+ - memcached
12
10
  before_install:
13
- - gem update --system
14
- - gem install bundler
15
-
11
+ - gem update --system
12
+ - gem install bundler
16
13
  cache: bundler
17
-
18
14
  script: bundle exec rake
19
-
20
15
  deploy:
21
16
  provider: rubygems
22
17
  api_key:
23
- secure: GYH7nTi2D9ZwbCP+JYS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/FLR75S6Vkm0DBnbqd/yYp6MP9Vbi77gIZpWMXANfdk1aWGVlPNpskYeWyqPjwZX1nYybJQIIpZfX21F2WPrNA9r/cj1KYjb8vKopMEdn9GP9xMeUXXu85K+ZVPqSD/AblrLHyD2x7cES/i4+XcQSaKUOSLxTUqemAiDRBahDCehPOOeLHnu/rUzgQr1gzQL0YcLNgHovmIdstljBys62JC4gy376cNawiSW4ZPMHWg6PewqQ6Ozg4Lkytx06bBwOos55dFgI4k0T4H0/6QiE=
19
+ gem: ruby-sdk
25
20
  on:
26
21
  tags: true
27
22
  repo: procore/ruby-sdk
28
-
23
+ skip_cleanup: 'true'
29
24
  notifications:
30
25
  email: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 1.1.0 (March 11, 2021)
2
+
3
+ * Allow tokens to be revoked and manually refreshed.
4
+
5
+ PR #39 - https://github.com/procore/ruby-sdk/pull/39
6
+
7
+ *Nate Baer*
8
+
1
9
  ## 1.0.0 (January 5, 2021)
2
10
 
3
11
  * Adds support for API versioning
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  #### Table of Contents
6
6
  - [Installation](#installation)
7
- - [1.0.0 Release](#1.0.0-release)
7
+ - [1.0.0 Release](#100-release)
8
8
  - [Making Requests](#making-requests)
9
9
  - [Usage](#usage)
10
10
  - [Error Handling](#error-handling)
@@ -141,6 +141,18 @@ client = Procore::Client.new(
141
141
  client.get("me")
142
142
  ```
143
143
 
144
+ Expired tokens will automatically be refreshed, but can also be refreshed manually:
145
+
146
+ ```ruby
147
+ client.refresh
148
+ ```
149
+
150
+ Tokens may also be manually revoked, forcing the client to refresh its token on the next request:
151
+
152
+ ```ruby
153
+ client.revoke
154
+ ```
155
+
144
156
  ## Error Handling
145
157
 
146
158
  The Procore Gem raises errors whenever a request returns a non `2xx` response.
@@ -32,6 +32,17 @@ module Procore
32
32
  end
33
33
  end
34
34
 
35
+ def revoke(token:)
36
+ request = {
37
+ client_id: @client_id,
38
+ client_secret: @client_secret,
39
+ token: token.access_token,
40
+ }
41
+ client.request(:post, "/oauth/revoke", body: request)
42
+ rescue RestClient::ExceptionWithResponse
43
+ raise OAuthError.new(e.description, response: e.response)
44
+ end
45
+
35
46
  private
36
47
 
37
48
  def client
@@ -38,19 +38,56 @@ module Procore
38
38
  @store = store
39
39
  end
40
40
 
41
+ # @raise [OAuthError] if a token cannot be refreshed.
42
+ def refresh
43
+ token = fetch_token
44
+
45
+ begin
46
+ new_token = @credentials.refresh(
47
+ token: token.access_token,
48
+ refresh: token.refresh_token,
49
+ )
50
+
51
+ Util.log_info("Token Refresh Successful", store: store)
52
+ store.save(new_token)
53
+ rescue RuntimeError
54
+ Util.log_error("Token Refresh Failed", store: store)
55
+ raise Procore::OAuthError.new(
56
+ "Unable to refresh the access token. Perhaps the Procore API is " \
57
+ "down or your access token store is misconfigured. Either " \
58
+ "way, you should clear the store and prompt the user to sign in " \
59
+ "again.",
60
+ )
61
+ end
62
+ end
63
+
64
+ # @raise [OAuthError] if a token cannot be revoked.
65
+ def revoke
66
+ token = fetch_token
67
+
68
+ begin
69
+ @credentials.revoke(token: token)
70
+ Util.log_info("Token Revocation Successful", store: store)
71
+ rescue RuntimeError
72
+ Util.log_error("Token Revocation Failed", store: store)
73
+ raise Procore::OAuthError.new(
74
+ "Unable to revoke the access token. Perhaps the Procore API is " \
75
+ "down or your access token store is misconfigured. Either " \
76
+ "way, you should clear the store and prompt the user to sign in " \
77
+ "again.",
78
+ )
79
+ end
80
+ end
81
+
41
82
  private
42
83
 
43
84
  def base_api_path
44
85
  "#{options[:host]}"
45
86
  end
46
87
 
47
- # @raise [OAuthError] if the store does not have a token stored in it prior
48
- # to making a request.
49
- # @raise [OAuthError] if a token cannot be refreshed.
50
- # @raise [OAuthError] if incorrect credentials have been supplied.
51
- def access_token
88
+ # @raise [OAuthError] if the store does not have a token stored.
89
+ def fetch_token
52
90
  token = store.fetch
53
-
54
91
  if token.nil? || token.invalid?
55
92
  raise Procore::MissingTokenError.new(
56
93
  "Unable to retreive an access token from the store. Double check " \
@@ -58,28 +95,15 @@ module Procore
58
95
  "before attempting to make API requests",
59
96
  )
60
97
  end
98
+ token
99
+ end
61
100
 
101
+ def access_token
102
+ token = fetch_token
62
103
  if token.expired?
63
104
  Util.log_info("Token Expired", store: store)
64
- begin
65
- token = @credentials.refresh(
66
- token: token.access_token,
67
- refresh: token.refresh_token,
68
- )
69
-
70
- Util.log_info("Token Refresh Successful", store: store)
71
- store.save(token)
72
- rescue RuntimeError
73
- Util.log_error("Token Refresh Failed", store: store)
74
- raise Procore::OAuthError.new(
75
- "Unable to refresh the access token. Perhaps the Procore API is " \
76
- "down or the your access token store is misconfigured. Either " \
77
- "way, you should clear the store and prompt the user to sign in " \
78
- "again.",
79
- )
80
- end
105
+ refresh
81
106
  end
82
-
83
107
  token.access_token
84
108
  end
85
109
  end
@@ -374,7 +374,7 @@ module Procore
374
374
  elsif /\Av\d+\.\d+\z/.match?(version)
375
375
  File.join(base_api_path, "rest", version, path)
376
376
  else
377
- raise ArgumentError.new "'#{version}' is an invalid Procore API version"
377
+ raise Procore::InvalidRequestError.new "#{version} is an invalid Procore API version"
378
378
  end
379
379
  end
380
380
  end
@@ -1,3 +1,3 @@
1
1
  module Procore
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: procore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Procore Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-05 00:00:00.000000000 Z
11
+ date: 2021-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -303,7 +303,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
303
303
  - !ruby/object:Gem::Version
304
304
  version: '0'
305
305
  requirements: []
306
- rubygems_version: 3.1.4
306
+ rubyforge_project:
307
+ rubygems_version: 2.6.14
307
308
  signing_key:
308
309
  specification_version: 4
309
310
  summary: Procore Ruby Gem