Class: Symgate::Auth::Client

Inherits:
Client
  • Object
show all
Defined in:
lib/symgate/auth/client.rb

Overview

client for the Symgate authentication system

Instance Attribute Summary

Attributes inherited from Client

#account, #endpoint, #key, #password, #savon_client, #savon_opts, #token, #user, #wsdl

Instance Method Summary collapse

Methods inherited from Client

#initialize, savon_array

Constructor Details

This class inherits a constructor from Symgate::Client

Instance Method Details

#add_group_language(group, language) ⇒ Object

Adds a language to the specified group

This enables users within the group to use the Symboliser in that language.

Attributes

  • group - The ID of the group to add the language to (String)

  • language - The cml language to enable (String)

Returns

Returns 'OK' if successful or 'Exists' if the language is already assigned to the account (String)

Supported authentication types

  • account/key



278
279
280
281
282
# File 'lib/symgate/auth/client.rb', line 278

def add_group_language(group, language)
  savon_request(:add_group_language) do |soap|
    soap.message(groupid: group, language: language)
  end.body[:add_group_language_response]
end

#authenticate(user_to_impersonate = nil) ⇒ Object

Authenticates a user and returns a token

This optionally provides a token which allows you to 'impersonate' a user (i.e. use the API as if you were logged on as that user)

Raises a Symgate::Error on error (e.g. authentication fails)

Attributes

  • user_to_impersonate (optional) - The ID (String) of the user to impersonate

Returns

A token, used for further calls to the client (String)

  • account/key (requires user_to_impersonate)

  • user (cannot use user_to_impersonate)



253
254
255
256
257
258
259
# File 'lib/symgate/auth/client.rb', line 253

def authenticate(user_to_impersonate = nil)
  r = savon_request(:authenticate) do |soap|
    soap.message(userid: user_to_impersonate) if user_to_impersonate
  end.body[:authenticate_response]

  r ? r[:authtoken] : nil
end

#create_group(group_id) ⇒ Object

Creates a new group.

Raises a Symgate::Error on failure

Attributes

  • group_id - The ID of the new group to create (String)

Supported authentication types

  • account/key



35
36
37
38
39
# File 'lib/symgate/auth/client.rb', line 35

def create_group(group_id)
  savon_request(:create_group, returns_error_string: true) do |soap|
    soap.message(groupid: group_id)
  end
end

#create_user(user, password) ⇒ Object

Creates a new user

Raises a Symgate::Error on failure (e.g. the user is invalid, or the group specified in the User object does not exist)

Attributes

  • user - A Symgate::Auth::User describing the new user

  • password - The password for the new user (String)

Supported authentication types

  • account/key

  • user (with is_group_admin)



119
120
121
122
123
124
# File 'lib/symgate/auth/client.rb', line 119

def create_user(user, password)
  savon_request(:create_user, returns_error_string: true) do |soap|
    soap.message(password: password)
    user.to_soap(soap[:message])
  end
end

#destroy_group(group_id) ⇒ Object

Destroys an existing group

IMPORTANT: This will permanently delete the group, along with all associated users, wordlists and metadata. Can't be undone.

Raises a Symgate::Error on failure

Attributes

  • group_id - The ID of the new group to create (String)

Supported authentication types

  • account/key



55
56
57
58
59
# File 'lib/symgate/auth/client.rb', line 55

def destroy_group(group_id)
  savon_request(:destroy_group, returns_error_string: true) do |soap|
    soap.message(groupid: group_id)
  end
end

#destroy_user(user_id) ⇒ Object

Destroys a user

IMPORTANT: This will irreversibly destroy all wordlists and metadata belonging to the user

Attributes

  • user_id - The ID of the user for whom the password is to be changed

Supported authentication types

  • account/key

  • user (with is_group_admin)



230
231
232
233
234
# File 'lib/symgate/auth/client.rb', line 230

def destroy_user(user_id)
  savon_request(:destroy_user, returns_error_string: true) do |soap|
    soap.message(userid: user_id)
  end
end

#enumerate_group_languages(group_id) ⇒ Object

Lists the allowed languages for the specified group

Attributes

  • group_id - The ID of the group (String)

Returns

Returns an array of cml languages as strings

Supported authentication types

  • account/key



320
321
322
323
324
325
326
327
# File 'lib/symgate/auth/client.rb', line 320

def enumerate_group_languages(group_id)
  resp = savon_request(:enumerate_group_languages) { |soap| soap.message(groupid: group_id) }

  Symgate::Client.savon_array(
    resp.body[:enumerate_group_languages_response],
    :language
  )
end

#enumerate_groupsObject

Returns a list of groups for the current symgate account

Returns

An array of group ids, as strings

Supported authentication types

  • account/key



17
18
19
20
21
22
# File 'lib/symgate/auth/client.rb', line 17

def enumerate_groups
  Symgate::Client.savon_array(
    savon_request(:enumerate_groups).body[:enumerate_groups_response],
    :groupid
  )
end

#enumerate_languagesObject

Lists the allowed languages for the currently authenticated user

Returns

Returns an array of cml languages as strings

Supported authentication types

  • user



358
359
360
361
362
363
364
365
# File 'lib/symgate/auth/client.rb', line 358

def enumerate_languages
  resp = savon_request(:enumerate_languages)

  Symgate::Client.savon_array(
    resp.body[:enumerate_languages_response],
    :language
  )
end

#enumerate_users(group_id) ⇒ Object

Returns a list of users for the specified group)

Attributes

  • group_id - The ID of the group (String)

Returns

An array of Symgate::Auth::User objects

Supported authentication types

  • account/key



95
96
97
98
99
100
101
102
103
# File 'lib/symgate/auth/client.rb', line 95

def enumerate_users(group_id)
  resp = savon_request(:enumerate_users) { |soap| soap.message(groupid: group_id) }

  Symgate::Client.savon_array(
    resp.body[:enumerate_users_response],
    :user,
    Symgate::Auth::User
  )
end

#move_user(old_user_id, new_user_id) ⇒ Object

Moves a user between groups

Moves a user from one group to another. The group part of the user ID should be changed.

Raises a Symgate::Error on failure (e.g. the new_user_id is already taken or the user with old_user_id does not exist)

Attributes

  • old_user_id - The ID of the user to move, in 'group_id/username' format (String)

  • new_user_id - The new ID of the renamed user (String)

Example

auth_client.move_user('group_1/username', 'group_2/username')

Supported authentication types

  • account/key



189
190
191
192
193
# File 'lib/symgate/auth/client.rb', line 189

def move_user(old_user_id, new_user_id)
  savon_request(:move_user, returns_error_string: true) do |soap|
    soap.message(old_user_id: old_user_id, new_user_id: new_user_id)
  end
end

#query_group_language(group_id, language) ⇒ Object

Queries whether a language is assigned to a group

Attributes

  • group - The ID of the group (String)

  • language - The cml language to query (String)

Returns

Returns true if the user has the language assigned, otherwise false (Boolean)

Supported authentication types

  • account/key



343
344
345
346
347
# File 'lib/symgate/auth/client.rb', line 343

def query_group_language(group_id, language)
  savon_request(:query_group_language) do |soap|
    soap.message(groupid: group_id, language: language)
  end.body[:query_group_language_response]
end

#query_language(language) ⇒ Object

Queries whether a language is assigned to the currently authenticated user

Attributes

  • language - The cml language to query (String)

Returns

Returns true if the user has the language assigned, otherwise false (Boolean)

Supported authentication types

  • user



380
381
382
383
# File 'lib/symgate/auth/client.rb', line 380

def query_language(language)
  savon_request(:query_language) { |soap| soap.message(language: language) }
    .body[:query_language_response]
end

#remove_group_language(group, language) ⇒ Object

Removes a language from the specified group

This prevents users within the group to use the Symboliser in that language.

Attributes

  • group - The ID of the group to remove the language from(String)

  • language - The cml language to disable (String)

Returns

Returns 'OK' if successful or 'NotExist' if the language is not assigned to the account (String)

Supported authentication types

  • account/key



301
302
303
304
305
# File 'lib/symgate/auth/client.rb', line 301

def remove_group_language(group, language)
  savon_request(:remove_group_language) do |soap|
    soap.message(groupid: group, language: language)
  end.body[:remove_group_language_response]
end

#rename_group(old_group_id, new_group_id) ⇒ Object

Renames a group

This will require all users to use the new group_id as part of their login username in future.

Raises a Symgate::Error on failure (e.g. the new_group_id is invalid)

Attributes

  • old_group_id - The ID of the group to rename (String)

  • new_group_id - The new ID for the renamed group (String)

Supported authentication types

  • account/key



76
77
78
79
80
# File 'lib/symgate/auth/client.rb', line 76

def rename_group(old_group_id, new_group_id)
  savon_request(:rename_group, returns_error_string: true) do |soap|
    soap.message(old_groupid: old_group_id, new_groupid: new_group_id)
  end
end

#rename_user(old_user_id, new_user_id) ⇒ Object

Renames a user

The user cannot be renamed from one group to another - the group part of the user id should remain the same.

Raises a Symgate::Error on failure (e.g. the new_user_id is already taken or the user with old_user_id does not exist)

Attributes

  • old_user_id - The ID of the user to rename, in 'group_id/username' format (String)

  • new_user_id - The new ID of the renamed user (String)

Supported authentication types

  • account/key

  • user (with is_group_admin)



163
164
165
166
167
# File 'lib/symgate/auth/client.rb', line 163

def rename_user(old_user_id, new_user_id)
  savon_request(:rename_user, returns_error_string: true) do |soap|
    soap.message(old_user_id: old_user_id, new_user_id: new_user_id)
  end
end

#set_user_password(user_id, password) ⇒ Object

Sets the password for a user

Note that when authenticating as a user without the is_group_admin permission you can only change the password for yourself.

Raises a Symgate::Error on failure (e.g. the user identified by user_id does not exist, or you do not have sufficient permissions to update the password.)

Attributes

  • user_id - The ID of the user for whom the password is to be changed

Supported authentication types

  • account/key

  • user



211
212
213
214
215
# File 'lib/symgate/auth/client.rb', line 211

def set_user_password(user_id, password)
  savon_request(:set_user_password, returns_error_string: true) do |soap|
    soap.message(userid: user_id, password: password)
  end
end

#update_user(user) ⇒ Object

Updates a user

Currently this can only be used to set the is_group_admin member of the user object

Attributes

  • user - The updated Symgate::Auth::User object

Supported authentication types

  • account/key

  • user (with is_group_admin)



139
140
141
142
143
144
# File 'lib/symgate/auth/client.rb', line 139

def update_user(user)
  savon_request(:update_user, returns_error_string: true) do |soap|
    soap.message({})
    user.to_soap(soap[:message])
  end
end