module OnSIP::User::ClassMethods

Constants

DEFAULT_OPTIONS

Public Instance Methods

add(organization, attrs = {}) { |response| ... } click to toggle source

Adds a User to an Organization

reference at developer.onsip.com/admin-api/Users/#user-add

@example Add User attrs = {‘Username’ => ‘docs’,

'Name' => 'Docs',
'Email' => 'docs@example.onsip.com',
'AuthUsername' => 'example',
'Password' => 'mysuperpassword',
'PasswordConfirm' => 'mysuperpassword'}

User.add(organization, attrs)

@return [ User ] The created User.

# File lib/onsip/models/user.rb, line 148
def add(organization, attrs = {})
  params = attrs.merge({'Action' => 'UserAdd',
                        'SessionId' => OnSIP.session.id,
                        'OrganizationId' => organization.id,
                        'Domain' => organization.attributes.Domain,
                        'Output' => 'json'})
  response = OnSIP.connection.get('/api', params, {})
  yield response if block_given?
  process_add_user_response response
end
browse(account_id, options = {}) { |response| ... } click to toggle source
# File lib/onsip/models/user.rb, line 77
def browse(account_id, options = {})
  params = merge_params(DEFAULT_OPTIONS[:browse], options)
  params = params.merge({'Action' => 'UserBrowse',
                         'AccountId' => account_id,
                         'SessionId' => OnSIP.session.id,
                         'Output' => 'json'})

  response = OnSIP.connection.get('/api', params, {})
  yield response if block_given?
  process_browse_user_response response
end
change_role(user_id, role) { |response| ... } click to toggle source
# File lib/onsip/models/user.rb, line 185
def change_role(user_id, role)
  response = OnSIP.connection.get('/api', {'Action' => 'UserEditRoleSubmit', 'UserId' => user_id, 'SessionId' => OnSIP.session.id, 'RoleNames[]' => role, 'Output' => 'json'}, {})
  yield response if block_given?
  process_change_role_user_response response
end
delete!(user_id) { |response| ... } click to toggle source
# File lib/onsip/models/user.rb, line 99
def delete!(user_id)
  params = {'Action' => 'UserDelete', 'SessionId' => OnSIP.session.id, 'UserId' => user_id, 'Output' => 'json'}
  response = OnSIP.connection.get('/api', params, {})
  yield response if block_given?
  process_delete_user_response response
end
edit_status(user_id, attrs = {}) { |response| ... } click to toggle source
# File lib/onsip/models/user.rb, line 116
def edit_status(user_id, attrs = {})
  params = attrs.merge({'Action' => 'UserEditStatus', 'SessionId' => OnSIP.session.id, 'UserId' => user_id, 'Output' => 'json'})
  response = OnSIP.connection.get('/api', params, {})
  yield response if block_given?
  process_edit_user_status_response response
end
generate_random_password(length = 8) click to toggle source
# File lib/onsip/models/user.rb, line 201
def generate_random_password(length = 8)
  SecureRandom.urlsafe_base64[0,8]
end
process_add_user_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 159
def process_add_user_response(response)
  user = nil

  key_path = %w(Response Result UserAdd User)
  a = ResponseParser.parse_response response, key_path
  user = (a.map { |h| new h }).first if a

  user
end
process_browse_user_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 89
def process_browse_user_response(response)
  users = []

  key_path = %w(Response Result UserBrowse Users User)
  a = ResponseParser.parse_response response, key_path
  users = a.map { |h| new h } if a

  users
end
process_change_role_user_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 191
def process_change_role_user_response(response)
  user = nil

  key_path = %w(Response Result UserEditRoleSubmit User)
  a = ResponseParser.parse_response response, key_path
  user = (a.map { |h| new h }).first if a

  user
end
process_delete_user_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 106
def process_delete_user_response(response)
  r = response.env.body['Response']

  if r && r['Context'] && r['Context']['Action'] && r['Context']['Action']
    return true
  else
    raise OnSIPRequestException, 'Problem with user request'
  end
end
process_edit_user_status_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 123
def process_edit_user_status_response(response)
  user = nil
  r = response.env.body['Response']

  key_path = %w(Response Result UserEditStatus User)
  a = ResponseParser.parse_response response, key_path
  user = (a.map { |h| new h }).first if a

  user
end
process_read_user_response(response) click to toggle source
# File lib/onsip/models/user.rb, line 175
def process_read_user_response(response)
  user = nil

  key_path = %w(Response Result UserRead User)
  a = ResponseParser.parse_response response, key_path
  user = (a.map { |h| new h }).first if a

  user
end
read(user_id) { |response| ... } click to toggle source
# File lib/onsip/models/user.rb, line 169
def read(user_id)
  response = OnSIP.connection.get('/api', {'Action' => 'UserRead', 'UserId' => user_id, 'SessionId' => OnSIP.session.id, 'Output' => 'json'}, {})
  yield response if block_given?
  process_read_user_response response
end