mais_orcid_client 0.4.0 → 1.0.0
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 +40 -30
- 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 +11 -5
- 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: 37780670257a67170aacd956c9b28d77462974a7068229a221985c55993435e0
|
4
|
+
data.tar.gz: bb7b89396a2ac1539d7b39dfe6732e5047312c14ae0a269e8a20b9780e434642
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f64d3d4daa1150758535609ee01669850b03fa581e0a6089dbb40702373ab41a2189e4ddc0cdc2783ef8f5894e3b59bb8718ab5c6b376fac59bc5089325b729a
|
7
|
+
data.tar.gz: 525a539b133093d30b7b3099bfadd7d149b7ee53c64b2cee364e4325e73eb7e82876c85d4d768f2b21ea88c94bec1bb2856e84da0d83ceaa3c563197c96f99af
|
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.0)
|
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,7 +27,7 @@ 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)
|
@@ -36,7 +37,7 @@ GEM
|
|
36
37
|
crack (1.0.0)
|
37
38
|
bigdecimal
|
38
39
|
rexml
|
39
|
-
diff-lcs (1.
|
40
|
+
diff-lcs (1.6.0)
|
40
41
|
docile (1.4.1)
|
41
42
|
drb (2.2.1)
|
42
43
|
faraday (2.12.2)
|
@@ -51,12 +52,13 @@ GEM
|
|
51
52
|
hashie (5.0.0)
|
52
53
|
i18n (1.14.7)
|
53
54
|
concurrent-ruby (~> 1.0)
|
54
|
-
json (2.
|
55
|
+
json (2.10.2)
|
55
56
|
jwt (2.10.1)
|
56
57
|
base64
|
57
58
|
language_server-protocol (3.17.0.4)
|
59
|
+
lint_roller (1.1.0)
|
58
60
|
logger (1.6.6)
|
59
|
-
minitest (5.25.
|
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,18 @@ GEM
|
|
68
70
|
rack (>= 1.2, < 4)
|
69
71
|
snaky_hash (~> 2.0)
|
70
72
|
version_gem (~> 1.1)
|
73
|
+
ostruct (0.6.1)
|
71
74
|
parallel (1.26.3)
|
72
|
-
parser (3.3.7.
|
75
|
+
parser (3.3.7.2)
|
73
76
|
ast (~> 2.4.1)
|
74
77
|
racc
|
75
78
|
public_suffix (6.0.1)
|
76
79
|
racc (1.8.1)
|
77
|
-
rack (3.1.
|
80
|
+
rack (3.1.12)
|
78
81
|
rainbow (3.1.1)
|
79
82
|
rake (13.2.1)
|
80
83
|
regexp_parser (2.10.0)
|
81
|
-
rexml (3.4.
|
84
|
+
rexml (3.4.1)
|
82
85
|
rspec (3.13.0)
|
83
86
|
rspec-core (~> 3.13.0)
|
84
87
|
rspec-expectations (~> 3.13.0)
|
@@ -92,9 +95,10 @@ GEM
|
|
92
95
|
diff-lcs (>= 1.2.0, < 2.0)
|
93
96
|
rspec-support (~> 3.13.0)
|
94
97
|
rspec-support (3.13.2)
|
95
|
-
rubocop (1.
|
98
|
+
rubocop (1.74.0)
|
96
99
|
json (~> 2.3)
|
97
|
-
language_server-protocol (
|
100
|
+
language_server-protocol (~> 3.17.0.2)
|
101
|
+
lint_roller (~> 1.1.0)
|
98
102
|
parallel (~> 1.10)
|
99
103
|
parser (>= 3.3.0.2)
|
100
104
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -102,20 +106,25 @@ GEM
|
|
102
106
|
rubocop-ast (>= 1.38.0, < 2.0)
|
103
107
|
ruby-progressbar (~> 1.7)
|
104
108
|
unicode-display_width (>= 2.4.0, < 4.0)
|
105
|
-
rubocop-ast (1.
|
106
|
-
parser (>= 3.3.
|
107
|
-
rubocop-capybara (2.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
rubocop (
|
113
|
-
|
114
|
-
|
115
|
-
rubocop (
|
116
|
-
|
117
|
-
|
118
|
-
|
109
|
+
rubocop-ast (1.41.0)
|
110
|
+
parser (>= 3.3.7.2)
|
111
|
+
rubocop-capybara (2.22.1)
|
112
|
+
lint_roller (~> 1.1)
|
113
|
+
rubocop (~> 1.72, >= 1.72.1)
|
114
|
+
rubocop-factory_bot (2.27.1)
|
115
|
+
lint_roller (~> 1.1)
|
116
|
+
rubocop (~> 1.72, >= 1.72.1)
|
117
|
+
rubocop-performance (1.24.0)
|
118
|
+
lint_roller (~> 1.1)
|
119
|
+
rubocop (>= 1.72.1, < 2.0)
|
120
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
121
|
+
rubocop-rspec (3.5.0)
|
122
|
+
lint_roller (~> 1.1)
|
123
|
+
rubocop (~> 1.72, >= 1.72.1)
|
124
|
+
rubocop-rspec_rails (2.31.0)
|
125
|
+
lint_roller (~> 1.1)
|
126
|
+
rubocop (~> 1.72, >= 1.72.1)
|
127
|
+
rubocop-rspec (~> 3.5)
|
119
128
|
ruby-progressbar (1.13.0)
|
120
129
|
securerandom (0.4.1)
|
121
130
|
simplecov (0.22.0)
|
@@ -132,17 +141,18 @@ GEM
|
|
132
141
|
unicode-display_width (3.1.4)
|
133
142
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
134
143
|
unicode-emoji (4.0.4)
|
135
|
-
uri (1.0.
|
144
|
+
uri (1.0.3)
|
136
145
|
vcr (6.3.1)
|
137
146
|
base64
|
138
|
-
version_gem (1.1.
|
139
|
-
webmock (3.25.
|
147
|
+
version_gem (1.1.6)
|
148
|
+
webmock (3.25.1)
|
140
149
|
addressable (>= 2.8.0)
|
141
150
|
crack (>= 0.3.2)
|
142
151
|
hashdiff (>= 0.4.0, < 2.0.0)
|
143
|
-
zeitwerk (2.7.
|
152
|
+
zeitwerk (2.7.2)
|
144
153
|
|
145
154
|
PLATFORMS
|
155
|
+
arm64-darwin-23
|
146
156
|
x86_64-darwin-19
|
147
157
|
x86_64-darwin-20
|
148
158
|
x86_64-darwin-21
|
@@ -165,4 +175,4 @@ DEPENDENCIES
|
|
165
175
|
webmock
|
166
176
|
|
167
177
|
BUNDLED WITH
|
168
|
-
2.
|
178
|
+
2.6.6
|
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.
|
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
|
|
@@ -117,7 +121,7 @@ class MaisOrcidClient
|
|
117
121
|
# rubocop:disable Metrics/MethodLength
|
118
122
|
def get_response(path, allow404: false)
|
119
123
|
TokenWrapper.refresh(config) do
|
120
|
-
response = conn.get("/
|
124
|
+
response = conn.get("/orcid/v1#{path}")
|
121
125
|
|
122
126
|
return if allow404 && response.status == 404
|
123
127
|
|
@@ -133,6 +137,7 @@ class MaisOrcidClient
|
|
133
137
|
end
|
134
138
|
end
|
135
139
|
|
140
|
+
# rubocop:disable Metrics/AbcSize
|
136
141
|
def conn
|
137
142
|
conn = Faraday.new(url: config.base_url) do |faraday|
|
138
143
|
faraday.request :retry, max: 3,
|
@@ -142,10 +147,11 @@ class MaisOrcidClient
|
|
142
147
|
end
|
143
148
|
conn.options.timeout = 500
|
144
149
|
conn.options.open_timeout = 10
|
145
|
-
conn.headers[:user_agent] =
|
150
|
+
conn.headers[:user_agent] = config.user_agent
|
146
151
|
conn.headers[:authorization] = "Bearer #{config.token}"
|
147
152
|
conn
|
148
153
|
end
|
154
|
+
# rubocop:enable Metrics/AbcSize
|
149
155
|
# rubocop:enable Metrics/MethodLength
|
150
156
|
|
151
157
|
# @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.0
|
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-03-28 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
|