class PennState::SearchService::Client
Attributes
base_url[R]
Public Class Methods
new(base_url: '/search-service/resources')
click to toggle source
@param [String] base_url
# File lib/penn_state/search_service/client.rb, line 13 def initialize(base_url: '/search-service/resources') @base_url = base_url end
Public Instance Methods
search(**args)
click to toggle source
@param [Hash] args of options to pass to the endpoint @option args [String] :text to search for
# File lib/penn_state/search_service/client.rb, line 19 def search(**args) process_response connection.get("#{base_url}/people", args) end
userid(userid)
click to toggle source
@param [Hash] args of options to pass to the endpoint @option args [String] :userid of the person
# File lib/penn_state/search_service/client.rb, line 25 def userid(userid) process_userid_response connection.get("#{base_url}/people/userid/#{userid}") end
Private Instance Methods
connection()
click to toggle source
# File lib/penn_state/search_service/client.rb, line 50 def connection @connection ||= Faraday.new(url: endpoint) do |conn| conn.adapter :net_http end end
endpoint()
click to toggle source
# File lib/penn_state/search_service/client.rb, line 56 def endpoint @endpoint ||= ENV.fetch('IDENTITY_ENDPOINT', 'https://identity.apps.psu.edu') end
process_response(response)
click to toggle source
@return Array<PennState::SearchService::Person>
# File lib/penn_state/search_service/client.rb, line 32 def process_response(response) raise Error.new(response.body) unless response.success? JSON.parse(response.body).map { |result| Person.new(result) } rescue JSON::ParserError [] end
process_userid_response(response)
click to toggle source
@return [PennState::SearchService::Person, nil]
# File lib/penn_state/search_service/client.rb, line 41 def process_userid_response(response) return if response.status == 404 raise Error.new(response.body) unless response.success? Person.new(JSON.parse(response.body)) rescue JSON::ParserError end