mais_orcid_client 0.4.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +49 -37
- data/README.md +11 -4
- data/lib/mais_orcid_client/authenticator.rb +2 -2
- data/lib/mais_orcid_client/token_wrapper.rb +1 -1
- data/lib/mais_orcid_client/version.rb +1 -1
- data/lib/mais_orcid_client.rb +12 -11
- data/mais_orcid_client.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fd365e002189b3f5865c0f890851f47bdb96252dfec8c76036db3debfb55773
|
4
|
+
data.tar.gz: 2c1da5d83bece19afa22b0030ffe846e09de4b2d7c26ee7b8f380474e7c64d04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92a637eaf9bf68af95c7bb7d8da4de0fc38efd95c5f96c84590b342ff0e68b36da8304e3a6378a740a73c2d4cc26184b96570db340db596aa3d90d45ee3edfc1
|
7
|
+
data.tar.gz: 2c0d11e4a6bde90e0464425a0d36562f0c57f02b84217aedb4266581206a71f4804e4c788a2eee585ad46d8920acaaabbea132ca6786e34c913bee98ace88f01
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mais_orcid_client (0.
|
4
|
+
mais_orcid_client (1.0.1)
|
5
5
|
activesupport (>= 4.2)
|
6
6
|
faraday
|
7
7
|
faraday-retry
|
8
8
|
oauth2
|
9
|
+
ostruct
|
9
10
|
zeitwerk
|
10
11
|
|
11
12
|
GEM
|
12
13
|
remote: https://rubygems.org/
|
13
14
|
specs:
|
14
|
-
activesupport (8.0.
|
15
|
+
activesupport (8.0.2)
|
15
16
|
base64
|
16
17
|
benchmark (>= 0.3)
|
17
18
|
bigdecimal
|
@@ -26,37 +27,38 @@ GEM
|
|
26
27
|
uri (>= 0.13.1)
|
27
28
|
addressable (2.8.7)
|
28
29
|
public_suffix (>= 2.0.2, < 7.0)
|
29
|
-
ast (2.4.
|
30
|
+
ast (2.4.3)
|
30
31
|
base64 (0.2.0)
|
31
32
|
benchmark (0.4.0)
|
32
33
|
bigdecimal (3.1.9)
|
33
|
-
byebug (
|
34
|
+
byebug (12.0.0)
|
34
35
|
concurrent-ruby (1.3.5)
|
35
|
-
connection_pool (2.5.
|
36
|
+
connection_pool (2.5.2)
|
36
37
|
crack (1.0.0)
|
37
38
|
bigdecimal
|
38
39
|
rexml
|
39
|
-
diff-lcs (1.
|
40
|
+
diff-lcs (1.6.1)
|
40
41
|
docile (1.4.1)
|
41
42
|
drb (2.2.1)
|
42
|
-
faraday (2.
|
43
|
+
faraday (2.13.1)
|
43
44
|
faraday-net_http (>= 2.0, < 3.5)
|
44
45
|
json
|
45
46
|
logger
|
46
47
|
faraday-net_http (3.4.0)
|
47
48
|
net-http (>= 0.5.0)
|
48
|
-
faraday-retry (2.
|
49
|
+
faraday-retry (2.3.1)
|
49
50
|
faraday (~> 2.0)
|
50
51
|
hashdiff (1.1.2)
|
51
52
|
hashie (5.0.0)
|
52
53
|
i18n (1.14.7)
|
53
54
|
concurrent-ruby (~> 1.0)
|
54
|
-
json (2.
|
55
|
+
json (2.11.3)
|
55
56
|
jwt (2.10.1)
|
56
57
|
base64
|
57
58
|
language_server-protocol (3.17.0.4)
|
58
|
-
|
59
|
-
|
59
|
+
lint_roller (1.1.0)
|
60
|
+
logger (1.7.0)
|
61
|
+
minitest (5.25.5)
|
60
62
|
multi_xml (0.7.1)
|
61
63
|
bigdecimal (~> 3.1)
|
62
64
|
net-http (0.6.0)
|
@@ -68,17 +70,19 @@ GEM
|
|
68
70
|
rack (>= 1.2, < 4)
|
69
71
|
snaky_hash (~> 2.0)
|
70
72
|
version_gem (~> 1.1)
|
71
|
-
|
72
|
-
|
73
|
+
ostruct (0.6.1)
|
74
|
+
parallel (1.27.0)
|
75
|
+
parser (3.3.8.0)
|
73
76
|
ast (~> 2.4.1)
|
74
77
|
racc
|
78
|
+
prism (1.4.0)
|
75
79
|
public_suffix (6.0.1)
|
76
80
|
racc (1.8.1)
|
77
|
-
rack (3.1.
|
81
|
+
rack (3.1.13)
|
78
82
|
rainbow (3.1.1)
|
79
83
|
rake (13.2.1)
|
80
84
|
regexp_parser (2.10.0)
|
81
|
-
rexml (3.4.
|
85
|
+
rexml (3.4.1)
|
82
86
|
rspec (3.13.0)
|
83
87
|
rspec-core (~> 3.13.0)
|
84
88
|
rspec-expectations (~> 3.13.0)
|
@@ -92,30 +96,37 @@ GEM
|
|
92
96
|
diff-lcs (>= 1.2.0, < 2.0)
|
93
97
|
rspec-support (~> 3.13.0)
|
94
98
|
rspec-support (3.13.2)
|
95
|
-
rubocop (1.
|
99
|
+
rubocop (1.75.3)
|
96
100
|
json (~> 2.3)
|
97
|
-
language_server-protocol (
|
101
|
+
language_server-protocol (~> 3.17.0.2)
|
102
|
+
lint_roller (~> 1.1.0)
|
98
103
|
parallel (~> 1.10)
|
99
104
|
parser (>= 3.3.0.2)
|
100
105
|
rainbow (>= 2.2.2, < 4.0)
|
101
106
|
regexp_parser (>= 2.9.3, < 3.0)
|
102
|
-
rubocop-ast (>= 1.
|
107
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
103
108
|
ruby-progressbar (~> 1.7)
|
104
109
|
unicode-display_width (>= 2.4.0, < 4.0)
|
105
|
-
rubocop-ast (1.
|
106
|
-
parser (>= 3.3.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
rubocop (~> 1.
|
111
|
-
rubocop-
|
112
|
-
|
113
|
-
rubocop
|
114
|
-
rubocop-
|
115
|
-
|
116
|
-
|
117
|
-
rubocop (
|
118
|
-
|
110
|
+
rubocop-ast (1.44.1)
|
111
|
+
parser (>= 3.3.7.2)
|
112
|
+
prism (~> 1.4)
|
113
|
+
rubocop-capybara (2.22.1)
|
114
|
+
lint_roller (~> 1.1)
|
115
|
+
rubocop (~> 1.72, >= 1.72.1)
|
116
|
+
rubocop-factory_bot (2.27.1)
|
117
|
+
lint_roller (~> 1.1)
|
118
|
+
rubocop (~> 1.72, >= 1.72.1)
|
119
|
+
rubocop-performance (1.25.0)
|
120
|
+
lint_roller (~> 1.1)
|
121
|
+
rubocop (>= 1.75.0, < 2.0)
|
122
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
123
|
+
rubocop-rspec (3.6.0)
|
124
|
+
lint_roller (~> 1.1)
|
125
|
+
rubocop (~> 1.72, >= 1.72.1)
|
126
|
+
rubocop-rspec_rails (2.31.0)
|
127
|
+
lint_roller (~> 1.1)
|
128
|
+
rubocop (~> 1.72, >= 1.72.1)
|
129
|
+
rubocop-rspec (~> 3.5)
|
119
130
|
ruby-progressbar (1.13.0)
|
120
131
|
securerandom (0.4.1)
|
121
132
|
simplecov (0.22.0)
|
@@ -132,17 +143,18 @@ GEM
|
|
132
143
|
unicode-display_width (3.1.4)
|
133
144
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
134
145
|
unicode-emoji (4.0.4)
|
135
|
-
uri (1.0.
|
146
|
+
uri (1.0.3)
|
136
147
|
vcr (6.3.1)
|
137
148
|
base64
|
138
|
-
version_gem (1.1.
|
139
|
-
webmock (3.25.
|
149
|
+
version_gem (1.1.7)
|
150
|
+
webmock (3.25.1)
|
140
151
|
addressable (>= 2.8.0)
|
141
152
|
crack (>= 0.3.2)
|
142
153
|
hashdiff (>= 0.4.0, < 2.0.0)
|
143
|
-
zeitwerk (2.7.
|
154
|
+
zeitwerk (2.7.2)
|
144
155
|
|
145
156
|
PLATFORMS
|
157
|
+
arm64-darwin-23
|
146
158
|
x86_64-darwin-19
|
147
159
|
x86_64-darwin-20
|
148
160
|
x86_64-darwin-21
|
@@ -165,4 +177,4 @@ DEPENDENCIES
|
|
165
177
|
webmock
|
166
178
|
|
167
179
|
BUNDLED WITH
|
168
|
-
2.
|
180
|
+
2.6.8
|
data/README.md
CHANGED
@@ -25,12 +25,17 @@ For one-off requests:
|
|
25
25
|
require "mais_orcid_client"
|
26
26
|
|
27
27
|
# NOTE: The settings below live in the consumer, not in the gem.
|
28
|
+
# The user_agent string can be changed by consumers as requested by MaIS for tracking
|
28
29
|
client = MaisOrcidClient.configure(
|
29
30
|
client_id: Settings.mais_orcid.client_id,
|
30
31
|
client_secret: Settings.mais_orcid.client_secret,
|
31
|
-
base_url: Settings.mais_orcid.base_url
|
32
|
+
base_url: Settings.mais_orcid.base_url,
|
33
|
+
token_url: Settings.mais_orcid.token_url,
|
34
|
+
user_agent: 'some-user-agent-string-to-send-in-requests' # defaults to 'stanford-library-sul-pub'
|
32
35
|
)
|
33
|
-
client.fetch_orcid_user(sunetid: 'nataliex')
|
36
|
+
client.fetch_orcid_user(sunetid: 'nataliex') # get a single user by sunet
|
37
|
+
client.fetch_orcid_user(orcid: '0000-1111-2222-3333-4444') # get a single user by orcidid
|
38
|
+
client.fetch_orcid_users # return all users
|
34
39
|
```
|
35
40
|
|
36
41
|
You can also invoke methods directly on the client class, which is useful in a
|
@@ -43,7 +48,8 @@ to be sure configuration has already occurred, e.g.:
|
|
43
48
|
MaisOrcidClient.configure(
|
44
49
|
client_id: Settings.mais_orcid.client_id,
|
45
50
|
client_secret: Settings.mais_orcid.client_secret,
|
46
|
-
base_url: Settings.mais_orcid.base_url
|
51
|
+
base_url: Settings.mais_orcid.base_url,
|
52
|
+
token_url: Settings.mais_orcid.token_url
|
47
53
|
)
|
48
54
|
|
49
55
|
# app/services/my_mais_orcid_service.rb
|
@@ -72,6 +78,7 @@ To record new cassettes:
|
|
72
78
|
2. Add your new spec with a new cassette name (or delete a previous cassette to re-create it).
|
73
79
|
3. Run just that new spec (important: else previous specs may use cassettes that have redacted credentials, causing your new spec to fail).
|
74
80
|
4. You should get a new cassette with the name you specified in the spec.
|
75
|
-
5. The cassette should have access tokens and secrets sanitized by the config in `spec_helper.rb`, but you can double check
|
81
|
+
5. The cassette should have access tokens and secrets sanitized by the config in `spec_helper.rb`, but you can double check. The one exception is the access_token for each ORCID user, these need to be set to "private_access_token" in the cassette manually, as VCR filter_sensitive_data can only replace the first instance.
|
76
82
|
6. Set your configuration at the top of the spec back to the fake client_id and client_secret values.
|
83
|
+
7. The spec that checks for a raised exception when fetching all users may need to be handcrafted in the cassette to look it raised a 500. It's hard to get the actual URL to produce a 500 on this call.
|
77
84
|
7. Re-run all the specs - they should pass now without making real calls.
|
@@ -18,8 +18,8 @@ class MaisOrcidClient
|
|
18
18
|
# @return [String]
|
19
19
|
def token
|
20
20
|
client = OAuth2::Client.new(client_id, client_secret, site: base_url,
|
21
|
-
token_url: '/
|
22
|
-
authorize_url: '/
|
21
|
+
token_url: '/oauth2/token',
|
22
|
+
authorize_url: '/oauth2/authorize',
|
23
23
|
auth_scheme: :request_body)
|
24
24
|
client.client_credentials.get_token.token
|
25
25
|
end
|
@@ -6,7 +6,7 @@ class MaisOrcidClient
|
|
6
6
|
def self.refresh(config)
|
7
7
|
yield
|
8
8
|
rescue UnexpectedResponse::UnauthorizedError
|
9
|
-
config.token = Authenticator.token(config.client_id, config.client_secret, config.
|
9
|
+
config.token = Authenticator.token(config.client_id, config.client_secret, config.token_url)
|
10
10
|
yield
|
11
11
|
end
|
12
12
|
end
|
data/lib/mais_orcid_client.rb
CHANGED
@@ -6,6 +6,7 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
6
6
|
require 'faraday'
|
7
7
|
require 'faraday/retry'
|
8
8
|
require 'oauth2'
|
9
|
+
require 'ostruct'
|
9
10
|
require 'singleton'
|
10
11
|
require 'zeitwerk'
|
11
12
|
|
@@ -27,13 +28,16 @@ class MaisOrcidClient
|
|
27
28
|
# @param client_id [String] the client identifier registered with MAIS
|
28
29
|
# @param client_secret [String] the client secret to authenticate with MAIS
|
29
30
|
# @param base_url [String] the base URL for the API
|
30
|
-
|
31
|
+
# @param token_url [String] the base token URL for authentication (getting token)
|
32
|
+
# @param user_agent [String] the user agent to use for requests (default: 'stanford-library-sul-pub')
|
33
|
+
def configure(client_id:, client_secret:, base_url:, token_url:, user_agent: 'stanford-library-sul-pub')
|
31
34
|
# rubocop:disable Style/OpenStructUse
|
32
35
|
instance.config = OpenStruct.new(
|
33
|
-
token: Authenticator.token(client_id, client_secret,
|
36
|
+
token: Authenticator.token(client_id, client_secret, token_url),
|
34
37
|
client_id:,
|
35
38
|
client_secret:,
|
36
|
-
base_url
|
39
|
+
base_url:,
|
40
|
+
user_agent:
|
37
41
|
)
|
38
42
|
# rubocop:enable Style/OpenStructUse
|
39
43
|
|
@@ -60,9 +64,8 @@ class MaisOrcidClient
|
|
60
64
|
result[:last_updated])
|
61
65
|
return orcid_users if limit && limit == orcid_users.size
|
62
66
|
end
|
63
|
-
# Currently next is always present, even on last page. (This may be changed in future.)
|
64
67
|
next_page = response.dig(:links, :next)
|
65
|
-
return orcid_users if
|
68
|
+
return orcid_users if next_page.nil? || next_page.empty?
|
66
69
|
end
|
67
70
|
end
|
68
71
|
# rubocop:enable Metrics/MethodLength
|
@@ -110,14 +113,10 @@ class MaisOrcidClient
|
|
110
113
|
path
|
111
114
|
end
|
112
115
|
|
113
|
-
def last_page?(links)
|
114
|
-
links[:self] == links[:last]
|
115
|
-
end
|
116
|
-
|
117
116
|
# rubocop:disable Metrics/MethodLength
|
118
117
|
def get_response(path, allow404: false)
|
119
118
|
TokenWrapper.refresh(config) do
|
120
|
-
response = conn.get("/
|
119
|
+
response = conn.get("/orcid/v1#{path}")
|
121
120
|
|
122
121
|
return if allow404 && response.status == 404
|
123
122
|
|
@@ -133,6 +132,7 @@ class MaisOrcidClient
|
|
133
132
|
end
|
134
133
|
end
|
135
134
|
|
135
|
+
# rubocop:disable Metrics/AbcSize
|
136
136
|
def conn
|
137
137
|
conn = Faraday.new(url: config.base_url) do |faraday|
|
138
138
|
faraday.request :retry, max: 3,
|
@@ -142,10 +142,11 @@ class MaisOrcidClient
|
|
142
142
|
end
|
143
143
|
conn.options.timeout = 500
|
144
144
|
conn.options.open_timeout = 10
|
145
|
-
conn.headers[:user_agent] =
|
145
|
+
conn.headers[:user_agent] = config.user_agent
|
146
146
|
conn.headers[:authorization] = "Bearer #{config.token}"
|
147
147
|
conn
|
148
148
|
end
|
149
|
+
# rubocop:enable Metrics/AbcSize
|
149
150
|
# rubocop:enable Metrics/MethodLength
|
150
151
|
|
151
152
|
# @param [string] orcidid which can include a full URI, e.g. "https://sandbox.orcid.org/0000-0002-7262-6251"
|
data/mais_orcid_client.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mais_orcid_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Mangiafico
|
8
8
|
- Justin Littman
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ostruct
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: zeitwerk
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|