mais_orcid_client 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e2c78bcd8751c9a2f6d972c46874a7637165d94f26ae15e360d73c1f522ce41
4
- data.tar.gz: e8f6bef5eff960802afceacf18054bd394e105f67ec3e95a3c63c7b7cd07942a
3
+ metadata.gz: 5f67823f01c96aa641315a8d64c463bc469c18d746ad5fd05a449a66f3c63925
4
+ data.tar.gz: 2f1435dabf75dd8c0956771f4519f978f0b745511310d3bfdc978bb0bf4bafb0
5
5
  SHA512:
6
- metadata.gz: ee77115c58f6ebc00b095e6d3938d5094deefb22be8d8317b2b7659fe46c1e38a56540ae7dc6a682907de4c11f60f97926dc79bff6454f22c2fac297c1230a1c
7
- data.tar.gz: f3b4d14e03c95d3ea9f9f7b40f9340433c7d757743cc89229529aa87063573af087e690ee568647aa63c967f74a6e31e3bd9a615538e82e0d4a9908b5009323c
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.1.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
@@ -1,11 +1,13 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/mais_orcid_client.svg)](https://badge.fury.io/rb/mais_orcid_client)
2
2
  [![CircleCI](https://circleci.com/gh/sul-dlss/mais_orcid_client.svg?style=svg)](https://circleci.com/gh/sul-dlss/mais_orcid_client)
3
- [![Maintainability](https://api.codeclimate.com/v1/badges/5919e7ae4cd162861585/maintainability)](https://codeclimate.com/github/sul-dlss/mais_orcid_client/maintainability)
4
- [![Test Coverage](https://api.codeclimate.com/v1/badges/5919e7ae4cd162861585/test_coverage)](https://codeclimate.com/github/sul-dlss/mais_orcid_client/test_coverage)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/25b4a4111f831121dda5/maintainability)](https://codeclimate.com/github/sul-dlss/mais_orcid_client/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/25b4a4111f831121dda5/test_coverage)](https://codeclimate.com/github/sul-dlss/mais_orcid_client/test_coverage)
5
5
 
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:
@@ -58,3 +60,19 @@ end
58
60
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
61
 
60
62
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## VCR Cassettes
65
+
66
+ VCR gem is used to record the results of the API calls for the tests. If you need to
67
+ record or re-create existing cassettes, you may need to adjust expectations in the tests
68
+ as the results coming back from the API may be different than when the cassettes were
69
+ recorded.
70
+
71
+ To record new cassettes:
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.
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).
75
+ 4. You should get a new cassette with the name you specified in the spec.
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")
77
+ 6. Set your configuration at the top of the spec back to the fake client_id and client_secret values.
78
+ 7. Re-run all the specs - they should pass now without making real calls.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class MaisOrcidClient
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
@@ -57,9 +57,21 @@ class MaisOrcidClient
57
57
  end
58
58
  end
59
59
 
60
+ # Fetch a user details, including scope and token, given either a SUNetID or ORCIDID
61
+ # @param [string] sunetid of user to fetch
62
+ # @param [orcid] orcidid of user to fetch (ignored if sunetid is also provided)
63
+ # @return [<OrcidUser>, nil] orcid user or nil if not found
64
+ def fetch_orcid_user(sunetid: nil, orcidid: nil)
65
+ raise "must provide either a sunetid or orcidid" unless sunetid || orcidid
66
+
67
+ sunetid ? fetch_by_sunetid(sunetid) : fetch_by_orcidid(orcidid)
68
+ end
69
+
70
+ private
71
+
60
72
  # @param [string] sunet to fetch
61
73
  # @return [<OrcidUser>, nil] orcid user or nil if not found
62
- def fetch_orcid_user(sunetid:)
74
+ def fetch_by_sunetid(sunetid)
63
75
  result = get_response("/users/#{sunetid}", allow404: true)
64
76
 
65
77
  return if result.nil?
@@ -67,9 +79,21 @@ class MaisOrcidClient
67
79
  OrcidUser.new(result[:sunet_id], result[:orcid_id], result[:scope], result[:access_token], result[:last_updated])
68
80
  end
69
81
 
70
- private
82
+ # @param [string] orcidid to fetch (note any ORCID URI will be stripped, as MaIS endpoint requires bare ORCIDID only)
83
+ # @return [<OrcidUser>, nil] orcid user or nil if not found
84
+ def fetch_by_orcidid(orcidid)
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
71
88
 
72
- def first_page(page_size)
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])
94
+ end
95
+
96
+ def first_page(page_size = nil)
73
97
  path = "/users?scope=ANY"
74
98
  path += "&page_size=#{page_size}" if page_size
75
99
  path
@@ -116,4 +140,10 @@ class MaisOrcidClient
116
140
  token = client.client_credentials.get_token
117
141
  "Bearer #{token.token}"
118
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
119
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.1.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-07 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.