Class: SiriusApi::UmapiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/sirius_api/umapi_client.rb

Constant Summary collapse

SITE =
Config.umapi_people_uri

Instance Method Summary collapse

Instance Method Details

#user_has_roles?(username, roles, operator: :all) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sirius_api/umapi_client.rb', line 13

def user_has_roles?(username, roles, operator: :all)
  fail ArgumentError, "Parameter 'username' must not be blank." if username.blank?
  fail ArgumentError, "Parameter 'roles' must not be empty." if roles.nil? || roles.empty?

  unless operator.to_s.in? %(all any none)
    fail ArgumentError, "Operator must be 'all', 'any', or 'none'."
  end

  user_uri = "#{SITE}/#{username}/roles?#{operator}=#{roles.to_a.join(',')}"
  resp = send_request(:head, user_uri)

  case resp.status
  when 200 then true
  when 404 then false
  else raise "Invalid response for #{user_uri} with status #{resp.status}."
  end
end