mais_orcid_client 0.2.0 → 0.3.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
2
  SHA256:
3
- metadata.gz: 78b55c51d036f61b67cae0d7fd72ec1bc231e787301d1f4b4b1298dc45ef9a60
4
- data.tar.gz: 2826a1359658edc044a94abd4163827e810b6f9b64063d17837fc0441aab350d
3
+ metadata.gz: 5f67823f01c96aa641315a8d64c463bc469c18d746ad5fd05a449a66f3c63925
4
+ data.tar.gz: 2f1435dabf75dd8c0956771f4519f978f0b745511310d3bfdc978bb0bf4bafb0
5
5
  SHA512:
6
- metadata.gz: 1f31a13fb73f0643476343081e33dc50b3fb22847f32abb0f95599252efa13293c3f1a94d684dbfec11d3e0799b4370f166db2d4e436f9eb5ce05def99986cbb
7
- data.tar.gz: e930d20928af633900545f1cfd8aca7df794c1340b753042704dbbe6a037f95b109aeaadb23f948418f459f720f8d4e094c56dbe4a238faaa44f1cbc12ff6136
6
+ metadata.gz: '083990f9b00f45ee537c8f07ea34450160a6b161167345a9e058cacb08fcb68b3c4c710877ae03aefe6f02729d48345536ecba981e9784697646ad6a89857636'
7
+ data.tar.gz: 93b51cbc03f7f5e2f8ea8e664cda30c07f817dbe592f0610ff69bfef1c0cbc50218122bb81d1e5a5bd631f5e99c12d4c82bca15add09c8d2a68fcf4f83238c78
data/.rubocop/custom.yml CHANGED
@@ -52,3 +52,33 @@ RSpec/Rails/InferredSpecType: # new in 2.14
52
52
  RSpec/MultipleExpectations:
53
53
  Enabled: false
54
54
 
55
+ Capybara/MatchStyle: # new in 2.17
56
+ Enabled: true
57
+ FactoryBot/AssociationStyle: # new in 2.23
58
+ Enabled: true
59
+ FactoryBot/FactoryAssociationWithStrategy: # new in 2.23
60
+ Enabled: true
61
+ FactoryBot/FactoryNameStyle: # new in 2.16
62
+ Enabled: true
63
+ FactoryBot/RedundantFactoryOption: # new in 2.23
64
+ Enabled: true
65
+ RSpec/BeEmpty: # new in 2.20
66
+ Enabled: true
67
+ RSpec/ContainExactly: # new in 2.19
68
+ Enabled: true
69
+ RSpec/DuplicatedMetadata: # new in 2.16
70
+ Enabled: true
71
+ RSpec/IndexedLet: # new in 2.20
72
+ Enabled: true
73
+ RSpec/MatchArray: # new in 2.19
74
+ Enabled: true
75
+ RSpec/PendingWithoutReason: # new in 2.16
76
+ Enabled: true
77
+ RSpec/RedundantAround: # new in 2.19
78
+ Enabled: true
79
+ RSpec/SkipBlockInsideExample: # new in 2.19
80
+ Enabled: true
81
+ RSpec/Rails/MinitestAssertions: # new in 2.17
82
+ Enabled: true
83
+ RSpec/Rails/TravelAround: # new in 2.19
84
+ Enabled: true
data/.rubocop.yml CHANGED
@@ -4,6 +4,8 @@ inherit_mode:
4
4
 
5
5
  require:
6
6
  - standard
7
+ - standard-custom
8
+ - standard-performance
7
9
  - rubocop-performance
8
10
  - rubocop-rspec
9
11
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mais_orcid_client (0.2.0)
4
+ mais_orcid_client (0.3.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  faraday
7
7
  faraday-retry
@@ -38,7 +38,7 @@ GEM
38
38
  json (2.6.3)
39
39
  jwt (2.7.1)
40
40
  language_server-protocol (3.17.0.3)
41
- lint_roller (1.0.0)
41
+ lint_roller (1.1.0)
42
42
  minitest (5.18.1)
43
43
  multi_xml (0.6.0)
44
44
  oauth2 (2.0.9)
@@ -52,7 +52,7 @@ GEM
52
52
  parser (3.2.2.3)
53
53
  ast (~> 2.4.1)
54
54
  racc
55
- public_suffix (5.0.1)
55
+ public_suffix (5.0.3)
56
56
  racc (1.7.1)
57
57
  rack (3.0.8)
58
58
  rainbow (3.1.1)
@@ -68,7 +68,7 @@ GEM
68
68
  rspec-expectations (3.12.3)
69
69
  diff-lcs (>= 1.2.0, < 2.0)
70
70
  rspec-support (~> 3.12.0)
71
- rspec-mocks (3.12.5)
71
+ rspec-mocks (3.12.6)
72
72
  diff-lcs (>= 1.2.0, < 2.0)
73
73
  rspec-support (~> 3.12.0)
74
74
  rspec-support (3.12.1)
@@ -106,16 +106,17 @@ GEM
106
106
  snaky_hash (2.0.1)
107
107
  hashie
108
108
  version_gem (~> 1.1, >= 1.1.1)
109
- standard (1.29.0)
109
+ standard (1.30.1)
110
110
  language_server-protocol (~> 3.17.0.2)
111
111
  lint_roller (~> 1.0)
112
112
  rubocop (~> 1.52.0)
113
113
  standard-custom (~> 1.0.0)
114
114
  standard-performance (~> 1.1.0)
115
- standard-custom (1.0.1)
116
- lint_roller (~> 1.0)
117
- standard-performance (1.1.0)
115
+ standard-custom (1.0.2)
118
116
  lint_roller (~> 1.0)
117
+ rubocop (~> 1.50)
118
+ standard-performance (1.1.2)
119
+ lint_roller (~> 1.1)
119
120
  rubocop-performance (~> 1.18.0)
120
121
  tzinfo (2.0.6)
121
122
  concurrent-ruby (~> 1.0)
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
  # mais_orcid_client
7
7
  API client for accessing MAIS's ORCID endpoints.
8
8
 
9
+ MAIS's ORCID API provides access to ORCID information for Stanford users. (This is different from orcid.org's ORCID API, which is supported by https://github.com/sul-dlss/orcid_client.)
10
+
9
11
  ## Installation
10
12
 
11
13
  Install the gem and add to the application's Gemfile by executing:
@@ -68,8 +70,8 @@ recorded.
68
70
 
69
71
  To record new cassettes:
70
72
  1. Temporarily adjust the configuration (client_id, client_secret for the MaIS UAT URL) at the top of `spec/mais_orcid_client_spec.rb` so it matches the real MaIS UAT environment.
71
- 2. Add your new spec with a new cassette name (or delete a cassette to re-create it).
72
- 3. Run just that new spec.
73
+ 2. Add your new spec with a new cassette name (or delete a previous cassette to re-create it).
74
+ 3. Run just that new spec (important: else previous specs may use cassettes that have redacted credentials, causing your new spec to fail).
73
75
  4. You should get a new cassette with the name you specified in the spec.
74
76
  5. The cassette should have access tokens and secrets sanitized by the config in `spec_helper.rb`, but you can double check, EXCEPT for user access tokens in the user response. These should be sanitized manaully (e.g. "access_token":"8d13b8bb-XXXX-YYYY-b7d6-87aecd5a8975")
75
77
  6. Set your configuration at the top of the spec back to the fake client_id and client_secret values.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class MaisOrcidClient
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -79,26 +79,18 @@ class MaisOrcidClient
79
79
  OrcidUser.new(result[:sunet_id], result[:orcid_id], result[:scope], result[:access_token], result[:last_updated])
80
80
  end
81
81
 
82
- # @param [string] orcidid to fetch
82
+ # @param [string] orcidid to fetch (note any ORCID URI will be stripped, as MaIS endpoint requires bare ORCIDID only)
83
83
  # @return [<OrcidUser>, nil] orcid user or nil if not found
84
84
  def fetch_by_orcidid(orcidid)
85
- # NOTE: This is intended to be a temporary implementation that iterates over all users
86
- # until we find the orcidid of interest and then return it. It can be slow (1-2 minutes)
87
- # if the orcidid queried is at the end of the list (or doesn't exist).
88
- # The idea is that when MaIS implements this functionality in their API, we replace this
89
- # iteration with a simple call to their API.
90
- # see https://github.com/sul-dlss/happy-heron/issues/3164
91
- next_page = first_page
92
- loop do
93
- response = get_response(next_page)
94
- response[:results].each do |result|
95
- if result[:orcid_id] == orcidid
96
- return OrcidUser.new(result[:sunet_id], result[:orcid_id], result[:scope], result[:access_token], result[:last_updated])
97
- end
98
- end
99
- next_page = response.dig(:links, :next)
100
- return nil if last_page?(response[:links])
101
- end
85
+ bare_orcid = orcidid_without_uri(orcidid)
86
+
87
+ return if bare_orcid.empty? # don't even bother sending the search if the incoming orcidid is bogus
88
+
89
+ result = get_response("/users/#{bare_orcid}", allow404: true)
90
+
91
+ return if result.nil?
92
+
93
+ OrcidUser.new(result[:sunet_id], result[:orcid_id], result[:scope], result[:access_token], result[:last_updated])
102
94
  end
103
95
 
104
96
  def first_page(page_size = nil)
@@ -148,4 +140,10 @@ class MaisOrcidClient
148
140
  token = client.client_credentials.get_token
149
141
  "Bearer #{token.token}"
150
142
  end
143
+
144
+ # @param [string] orcidid which can include a full URI, e.g. "https://sandbox.orcid.org/0000-0002-7262-6251"
145
+ # @return [string] orcidid without URI (if valid), e.g. "0000-0002-7262-6251" or empty string if none found or orcidid invalid
146
+ def orcidid_without_uri(orcidid)
147
+ orcidid.match(/\d{4}-\d{4}-\d{4}-\d{3}(\d|X){1}\z/).to_s
148
+ end
151
149
  end
@@ -44,4 +44,5 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency "simplecov"
45
45
  spec.add_development_dependency "webmock"
46
46
  spec.add_development_dependency "vcr"
47
+ spec.add_development_dependency "byebug"
47
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mais_orcid_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-07-12 00:00:00.000000000 Z
12
+ date: 2023-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -185,6 +185,20 @@ dependencies:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
187
  version: '0'
188
+ - !ruby/object:Gem::Dependency
189
+ name: byebug
190
+ requirement: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ type: :development
196
+ prerelease: false
197
+ version_requirements: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
188
202
  description: This provides API interaction with the MAIS's ORCID API
189
203
  email:
190
204
  - pmangiafico@stanford.edu
@@ -227,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
227
241
  - !ruby/object:Gem::Version
228
242
  version: '0'
229
243
  requirements: []
230
- rubygems_version: 3.4.14
244
+ rubygems_version: 3.4.10
231
245
  signing_key:
232
246
  specification_version: 4
233
247
  summary: Interface for interacting with the MAIS's ORCID API.