API client for accessing MAIS's ORCID endpoints.
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.)
Install the gem and add to the application's Gemfile by executing:
$ bundle add mais_orcid_client
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install mais_orcid_client
For one-off requests:
require "mais_orcid_client"
# NOTE: The settings below live in the consumer, not in the gem.
# The user_agent string can be changed by consumers as requested by MaIS for tracking
client = MaisOrcidClient.configure(
client_id: Settings.mais_orcid.client_id,
client_secret: Settings.mais_orcid.client_secret,
base_url: Settings.mais_orcid.base_url,
token_url: Settings.mais_orcid.token_url,
user_agent: 'some-user-agent-string-to-send-in-requests' # defaults to 'stanford-library-sul-pub'
)
client.fetch_orcid_user(sunetid: 'nataliex') # get a single user by sunet
client.fetch_orcid_user(orcid: '0000-1111-2222-3333-4444') # get a single user by orcidid
client.fetch_orcid_users # return all users
You can also invoke methods directly on the client class, which is useful in a Rails application environment where you might initialize the client in an initializer and then invoke client methods in many other contexts where you want to be sure configuration has already occurred, e.g.:
# config/initializers/mais_orcid_client.rb
MaisOrcidClient.configure(
client_id: Settings.mais_orcid.client_id,
client_secret: Settings.mais_orcid.client_secret,
base_url: Settings.mais_orcid.base_url,
token_url: Settings.mais_orcid.token_url
)
# app/services/my_mais_orcid_service.rb
# ...
def create_user_directory
MaisOrcidClient.fetch_orcid_user(sunetid: 'nataliex')
end
# ...
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.
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.
VCR gem is used to record the results of the API calls for the tests. If you need to record or re-create existing cassettes, you may need to adjust expectations in the tests as the results coming back from the API may be different than when the cassettes were recorded.
To record new cassettes:
- 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. - Add your new spec with a new cassette name (or delete a previous cassette to re-create it).
- Run just that new spec (important: else previous specs may use cassettes that have redacted credentials, causing your new spec to fail).
- You should get a new cassette with the name you specified in the spec.
- The cassette should have access tokens and secrets sanitized by the config in
spec_helper.rb
, but you can double check. - Set your configuration at the top of the spec back to the fake client_id and client_secret values.
- 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.
- Re-run all the specs - they should pass now without making real calls.