Module: OnSIP::User::ClassMethods

Included in:
OnSIP::User
Defined in:
lib/onsip/models/user.rb

Instance Method Summary collapse

Instance Method Details

#add(organization, attrs = {}) {|response| ... } ⇒ User

Adds a User to an Organization

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

attrs = => ‘docs’,

'Name' => 'Docs',
'Email' => '[email protected]',
'AuthUsername' => 'example',
'Password' => 'mysuperpassword',
'PasswordConfirm' => 'mysuperpassword'

User.add(organization, attrs)

Examples:

Add User


Yields:

  • (response)

Returns:

  • (User)

    The created User.



103
104
105
106
107
108
109
110
111
112
# File 'lib/onsip/models/user.rb', line 103

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) ⇒ Object



38
39
40
41
42
# File 'lib/onsip/models/user.rb', line 38

def browse()
  params = {'Action' => 'UserBrowse', 'AccountId' => , 'SessionId' => OnSIP.session.id, 'Output' => 'json'}
  response = OnSIP.connection.get('/api', params, {})
  process_browse_user_response response
end

#delete!(user_id) {|response| ... } ⇒ Object

Yields:

  • (response)


54
55
56
57
58
59
# File 'lib/onsip/models/user.rb', line 54

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| ... } ⇒ Object

Yields:

  • (response)


71
72
73
74
75
76
# File 'lib/onsip/models/user.rb', line 71

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

#process_add_user_response(response) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/onsip/models/user.rb', line 114

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) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/onsip/models/user.rb', line 44

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_delete_user_response(response) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/onsip/models/user.rb', line 61

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) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/onsip/models/user.rb', line 78

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) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/onsip/models/user.rb', line 130

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| ... } ⇒ Object

Yields:

  • (response)


124
125
126
127
128
# File 'lib/onsip/models/user.rb', line 124

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