mais_orcid_client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +18 -2
- data/lib/mais_orcid_client/version.rb +1 -1
- data/lib/mais_orcid_client.rb +35 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 78b55c51d036f61b67cae0d7fd72ec1bc231e787301d1f4b4b1298dc45ef9a60
|
4
|
+
data.tar.gz: 2826a1359658edc044a94abd4163827e810b6f9b64063d17837fc0441aab350d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f31a13fb73f0643476343081e33dc50b3fb22847f32abb0f95599252efa13293c3f1a94d684dbfec11d3e0799b4370f166db2d4e436f9eb5ce05def99986cbb
|
7
|
+
data.tar.gz: e930d20928af633900545f1cfd8aca7df794c1340b753042704dbbe6a037f95b109aeaadb23f948418f459f720f8d4e094c56dbe4a238faaa44f1cbc12ff6136
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
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/
|
4
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/
|
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.
|
@@ -58,3 +58,19 @@ end
|
|
58
58
|
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
59
|
|
60
60
|
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).
|
61
|
+
|
62
|
+
## VCR Cassettes
|
63
|
+
|
64
|
+
VCR gem is used to record the results of the API calls for the tests. If you need to
|
65
|
+
record or re-create existing cassettes, you may need to adjust expectations in the tests
|
66
|
+
as the results coming back from the API may be different than when the cassettes were
|
67
|
+
recorded.
|
68
|
+
|
69
|
+
To record new cassettes:
|
70
|
+
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
|
+
4. You should get a new cassette with the name you specified in the spec.
|
74
|
+
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
|
+
6. Set your configuration at the top of the spec back to the fake client_id and client_secret values.
|
76
|
+
7. Re-run all the specs - they should pass now without making real calls.
|
data/lib/mais_orcid_client.rb
CHANGED
@@ -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
|
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,29 @@ 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
|
-
|
82
|
+
# @param [string] orcidid to fetch
|
83
|
+
# @return [<OrcidUser>, nil] orcid user or nil if not found
|
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
|
102
|
+
end
|
71
103
|
|
72
|
-
def first_page(page_size)
|
104
|
+
def first_page(page_size = nil)
|
73
105
|
path = "/users?scope=ANY"
|
74
106
|
path += "&page_size=#{page_size}" if page_size
|
75
107
|
path
|
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.
|
4
|
+
version: 0.2.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
|
+
date: 2023-07-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|