Class: MaisOrcidClient
- Inherits:
-
Object
- Object
- MaisOrcidClient
- Includes:
- Singleton
- Defined in:
- lib/mais_orcid_client.rb,
lib/mais_orcid_client/version.rb,
lib/mais_orcid_client/authenticator.rb,
lib/mais_orcid_client/token_wrapper.rb,
lib/mais_orcid_client/unexpected_response.rb
Overview
Client for interacting with MAIS’s ORCID API
Defined Under Namespace
Classes: Authenticator, OrcidUser, TokenWrapper, UnexpectedResponse
Constant Summary collapse
- VERSION =
"0.3.1"
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#fetch_orcid_user(sunetid: nil, orcidid: nil) ⇒ <OrcidUser>?
Fetch a user details, including scope and token, given either a SUNetID or ORCIDID.
-
#fetch_orcid_users(limit: nil, page_size: nil) ⇒ Array<OrcidUser>
Orcid users.
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
44 45 46 |
# File 'lib/mais_orcid_client.rb', line 44 def config @config end |
Class Method Details
.configure(client_id:, client_secret:, base_url:) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mais_orcid_client.rb', line 30 def configure(client_id:, client_secret:, base_url:) instance.config = OpenStruct.new( token: Authenticator.token(client_id, client_secret, base_url), client_id:, client_secret:, base_url: ) self end |
Instance Method Details
#fetch_orcid_user(sunetid: nil, orcidid: nil) ⇒ <OrcidUser>?
Fetch a user details, including scope and token, given either a SUNetID or ORCIDID
68 69 70 71 72 |
# File 'lib/mais_orcid_client.rb', line 68 def fetch_orcid_user(sunetid: nil, orcidid: nil) raise "must provide either a sunetid or orcidid" unless sunetid || orcidid sunetid ? fetch_by_sunetid(sunetid) : fetch_by_orcidid(orcidid) end |
#fetch_orcid_users(limit: nil, page_size: nil) ⇒ Array<OrcidUser>
Returns orcid users.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/mais_orcid_client.rb', line 49 def fetch_orcid_users(limit: nil, page_size: nil) orcid_users = [] next_page = first_page(page_size) loop do response = get_response(next_page) response[:results].each do |result| orcid_users << OrcidUser.new(result[:sunet_id], result[:orcid_id], result[:scope], result[:access_token], result[:last_updated]) return orcid_users if limit && limit == orcid_users.size end # Currently next is always present, even on last page. (This may be changed in future.) next_page = response.dig(:links, :next) return orcid_users if last_page?(response[:links]) end end |