Class: MaisPersonClient

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mais_person_client.rb,
lib/mais_person_client/person.rb,
lib/mais_person_client/version.rb,
lib/mais_person_client/affiliations.rb,
lib/mais_person_client/unexpected_response.rb

Overview

Client for interacting with MAIS's Person API

Defined Under Namespace

Classes: Affiliations, Person, UnexpectedResponse

Constant Summary collapse

ALLOWED_TAGS =

Allowed tag values that can be requested from the API

%w[
  name
  title
  email
  url
  location
  affiliation
  identifier
  privgroup
  profile
  visibility
].freeze
VERSION =
'1.0.0'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



55
56
57
# File 'lib/mais_person_client.rb', line 55

def config
  @config
end

Class Method Details

.configure(api_key:, api_cert:, base_url:, user_agent: 'stanford-library') ⇒ Object

Parameters:

  • api_key (String)

    the api_key provided by MAIS

  • api_cert (String)

    the api_cert provided by MAIS

  • base_url (String)

    the base URL for the API

  • user_agent (String) (defaults to: 'stanford-library')

    the user agent to use for requests (default: 'stanford-library')



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mais_person_client.rb', line 39

def configure(api_key:, api_cert:, base_url:, user_agent: 'stanford-library')
  # rubocop:disable Style/OpenStructUse
  instance.config = OpenStruct.new(
    api_key:,
    api_cert:,
    base_url:,
    user_agent:
  )
  # rubocop:enable Style/OpenStructUse

  self
end

Instance Method Details

#fetch_user(sunetid, tags: nil) ⇒ <Person>?

Fetch a user details Fetch user details. Optionally accepts tags: which may be a String (comma separated) or an Array of tag names. Only tags listed in ALLOWED_TAGS are permitted; otherwise an ArgumentError is raised.

Parameters:

  • sunet (string)

    to fetch

Returns:

  • (<Person>, nil)

    user or nil if not found



63
64
65
66
67
# File 'lib/mais_person_client.rb', line 63

def fetch_user(sunetid, tags: nil)
  params = build_tag_params(tags)

  get_response("/doc/person/#{sunetid}", allow404: true, params: params)
end

#fetch_user_affiliations(sunetid) ⇒ Array<Affiliation>?

Fetch a user's affiliations

Parameters:

  • sunet (string)

    to fetch

Returns:

  • (Array<Affiliation>, nil)

    affiliations or nil if not found



72
73
74
# File 'lib/mais_person_client.rb', line 72

def fetch_user_affiliations(sunetid)
  get_response("/doc/person/#{sunetid}/affiliation", allow404: true)
end