Class: RelayApiClient::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/relay_api_client/base.rb

Class Method Summary collapse

Class Method Details

.clientObject



4
5
6
# File 'lib/relay_api_client/base.rb', line 4

def self.client
  @client ||= Savon.client(wsdl: RelayApiClient.wsdl, ssl_verify_mode: :none)
end

.create_account(username, password, first_name, last_name) ⇒ String

Returns the guid of the new account

Parameters:

  • username (String)
  • password (String)
  • first_name (String)
  • last_name (String)

Returns:

  • (String)

    Returns the guid of the new account



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/relay_api_client/base.rb', line 13

def self.(username, password, first_name, last_name)
  password = password.gsub('&', '&amp;').gsub('<', '&lt;').gsub('>','&gt;').gsub("'", "&apos;").gsub("\"", "&quot;")
  begin
    response = client.call(:signup, message: {username: username, password: password, passwordConfirm: password, firstName: first_name, lastName: last_name})

    h = response.to_hash

    if response.success?
      puts h.inspect
      return h[:signup_response][:user][:id]
    else
      case h[:fault][:faultstring]
      when "password does not meet with policy requirements."
        raise h[:fault][:faultstring]
      else
        logger.debug response.inspect
      end
    end
  rescue => e
    if e.message.include?("user already exists")
      # check identity linking
      person_entity = GlobalRegistry::Entity.get(
        'entity_type' => 'person',
        'filters[key_username]' => username,
        'filters[owned_by]' => 'the_key'
      )
      guid = person_entity&.dig('entities', 0, 'person', 'authentication', 'key_guid')
      return guid
    else
      raise
    end
  end
end

.set_designation_number(ssoguid, designation) ⇒ Boolean

Returns true if it succeeded, false otherwise.

Parameters:

  • ssoguid (String)
  • designation (String)

Returns:

  • (Boolean)

    true if it succeeded, false otherwise.



50
51
52
53
54
# File 'lib/relay_api_client/base.rb', line 50

def self.set_designation_number(ssoguid, designation)
  response = client.call(:set_designation, message: {ssoguid: ssoguid, designation: designation})

  response.success?
end

.set_role(args) ⇒ Boolean

Returns true if it succeeded, false otherwise.

Parameters:

  • args (Hash)

    arguments to pass on to SOAP call

Returns:

  • (Boolean)

    true if it succeeded, false otherwise.



58
59
60
61
62
63
64
65
# File 'lib/relay_api_client/base.rb', line 58

def self.set_role(args)
  response = client.call(:set_role, message: args)

  response.success?
rescue Savon::SOAPFault => e
  return true if e.message.include?('duplicate')
  false
end