Class: Kazoo::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/kazoo-client/error.rb,
lib/kazoo-client/media.rb,
lib/kazoo-client/menus.rb,
lib/kazoo-client/users.rb,
lib/kazoo-client/common.rb,
lib/kazoo-client/limits.rb,
lib/kazoo-client/queues.rb,
lib/kazoo-client/devices.rb,
lib/kazoo-client/servers.rb,
lib/kazoo-client/version.rb,
lib/kazoo-client/vmboxes.rb,
lib/kazoo-client/accounts.rb,
lib/kazoo-client/callflows.rb,
lib/kazoo-client/resources.rb,
lib/kazoo-client/conferences.rb,
lib/kazoo-client/directories.rb,
lib/kazoo-client/phone_numbers.rb,
lib/kazoo-client/temporal_rules.rb
Defined Under Namespace
Classes: AuthError, DeleteError, Error, GetError, PostError, PutError, VersionError
Constant Summary
collapse
- VERSION =
'0.1.0'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_callflow(data) ⇒ Object
-
#add_conference(data) ⇒ Object
-
#add_deployment(data) ⇒ Object
-
#add_device(data) ⇒ Object
-
#add_directory(data) ⇒ Object
-
#add_media(data) ⇒ Object
-
#add_menu(data) ⇒ Object
-
#add_queue(data) ⇒ Object
-
#add_resource(data) ⇒ Object
-
#add_temporal_rule(data) ⇒ Object
-
#add_user(data) ⇒ Object
-
#add_vmbox(data) ⇒ Object
-
#authenticate ⇒ Object
-
#authenticated? ⇒ Boolean
-
#delete_callflow(id) ⇒ Object
-
#delete_conference(id) ⇒ Object
-
#delete_device(id) ⇒ Object
-
#delete_directory(id) ⇒ Object
-
#delete_media(id) ⇒ Object
-
#delete_menu(id) ⇒ Object
-
#delete_phone_number(id) ⇒ Object
-
#delete_queue(id) ⇒ Object
-
#delete_request(url) ⇒ Object
-
#delete_resource(id) ⇒ Object
-
#delete_temporal_rule(id) ⇒ Object
-
#delete_user(id) ⇒ Object
-
#delete_vmbox(id) ⇒ Object
-
#get_account(id) ⇒ Object
-
#get_account_children(id) ⇒ Object
-
#get_account_descendants(id) ⇒ Object
-
#get_account_siblings(id) ⇒ Object
-
#get_callflow(id) ⇒ Object
-
#get_callflows ⇒ Object
-
#get_conference(id) ⇒ Object
-
#get_conferences ⇒ Object
-
#get_deployment(id) ⇒ Object
-
#get_device(id) ⇒ Object
-
#get_devices ⇒ Object
-
#get_devices_status ⇒ Object
-
#get_directories ⇒ Object
-
#get_directory(id) ⇒ Object
-
#get_hotdesk ⇒ Object
-
#get_languages ⇒ Object
-
#get_languages_missing ⇒ Object
-
#get_limits ⇒ Object
-
#get_logs(id) ⇒ Object
-
#get_media(id) ⇒ Object
-
#get_medias ⇒ Object
-
#get_menu(id) ⇒ Object
-
#get_menus ⇒ Object
-
#get_phone_numbers ⇒ Object
-
#get_queue(id) ⇒ Object
-
#get_queues ⇒ Object
-
#get_request(url) ⇒ Object
-
#get_resource(id) ⇒ Object
-
#get_resources ⇒ Object
-
#get_servers ⇒ Object
-
#get_temporal_rule(id) ⇒ Object
-
#get_temporal_rules ⇒ Object
-
#get_user(id) ⇒ Object
-
#get_users ⇒ Object
-
#get_vmbox(id) ⇒ Object
-
#get_vmboxes ⇒ Object
-
#initialize(base_url, version, username, password, realm) ⇒ Client
constructor
A new instance of Client.
-
#post_request(url, data) ⇒ Object
-
#put_request(url, data) ⇒ Object
-
#sync_device(id) ⇒ Object
-
#update_account(id, data) ⇒ Object
-
#update_callflow(id, data) ⇒ Object
-
#update_conference(id, data) ⇒ Object
-
#update_device(id, data) ⇒ Object
-
#update_directory(id, data) ⇒ Object
-
#update_media(id, data) ⇒ Object
-
#update_menu(id, data) ⇒ Object
-
#update_phone_number(id, data) ⇒ Object
-
#update_queue(id, data) ⇒ Object
-
#update_resource(id, data) ⇒ Object
-
#update_temporal_rule(id, data) ⇒ Object
-
#update_user(id, data) ⇒ Object
-
#update_vmbox(id, data) ⇒ Object
Constructor Details
#initialize(base_url, version, username, password, realm) ⇒ Client
Returns a new instance of Client.
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/kazoo-client/common.rb', line 5
def initialize(base_url, version, username, password, realm)
@base_url = base_url
@username = username
@password = password
@realm = realm
@version = version
unless authenticated?
authenticate
end
end
|
Instance Attribute Details
#account_id ⇒ Object
Returns the value of attribute account_id.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def account_id
@account_id
end
|
#auth_token ⇒ Object
Returns the value of attribute auth_token.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def auth_token
@auth_token
end
|
#base_url ⇒ Object
Returns the value of attribute base_url.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def base_url
@base_url
end
|
#realm ⇒ Object
Returns the value of attribute realm.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def realm
@realm
end
|
#username ⇒ Object
Returns the value of attribute username.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def username
@username
end
|
#version ⇒ Object
Returns the value of attribute version.
3
4
5
|
# File 'lib/kazoo-client/common.rb', line 3
def version
@version
end
|
Instance Method Details
#add_callflow(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/callflows.rb', line 11
def add_callflow(data)
put_request('callflows', data)
end
|
#add_conference(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/conferences.rb', line 11
def add_conference(data)
put_request('conferences', data)
end
|
#add_deployment(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/servers.rb', line 11
def add_deployment(data)
put_request("servers/#{id}/deployment", data)
end
|
#add_device(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/devices.rb', line 11
def add_device(data)
put_request('devices', data)
end
|
#add_directory(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/directories.rb', line 11
def add_directory(data)
put_request('directories', data)
end
|
11
12
13
|
# File 'lib/kazoo-client/media.rb', line 11
def add_media(data)
put_request('media', data)
end
|
11
12
13
|
# File 'lib/kazoo-client/menus.rb', line 11
def (data)
put_request('menus', data)
end
|
#add_queue(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/queues.rb', line 11
def add_queue(data)
put_request('queues', data)
end
|
#add_resource(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/resources.rb', line 11
def add_resource(data)
put_request('resources', data)
end
|
#add_temporal_rule(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/temporal_rules.rb', line 11
def add_temporal_rule(data)
put_request('temporal_rules', data)
end
|
#add_user(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/users.rb', line 11
def add_user(data)
put_request('users', data)
end
|
#add_vmbox(data) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/vmboxes.rb', line 11
def add_vmbox(data)
put_request('vmboxes', data)
end
|
#authenticate ⇒ Object
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
46
|
# File 'lib/kazoo-client/common.rb', line 21
def authenticate
credentials = Digest::MD5.hexdigest "#{@username}:#{@password}"
auth_hash = {
data: {
credentials: credentials,
account_name: @realm
},
verb: 'PUT'
}
response = HTTP.(content_type: 'application/json', accept: 'application/json')
.put("#{@base_url}/#{@version}/user_auth", json: auth_hash)
result = JSON.parse(response.body)
case response.code
when (200..299)
@account_id = result['data']['account_id']
@auth_token = result['auth_token']
= {
content_type: 'application/json',
accept: 'application/json',
X_Auth_Token: @auth_token
}
return result['data']
else
raise AuthError, "Authentication error: #{response.status}"
end
end
|
#authenticated? ⇒ Boolean
17
18
19
|
# File 'lib/kazoo-client/common.rb', line 17
def authenticated?
!@auth_token.nil?
end
|
#delete_callflow(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/callflows.rb', line 19
def delete_callflow(id)
delete_request("callflows/#{id}")
end
|
#delete_conference(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/conferences.rb', line 19
def delete_conference(id)
delete_request("conferences/#{id}")
end
|
#delete_device(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/devices.rb', line 19
def delete_device(id)
delete_request("devices/#{id}")
end
|
#delete_directory(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/directories.rb', line 19
def delete_directory(id)
delete_request("directories/#{id}")
end
|
19
20
21
|
# File 'lib/kazoo-client/media.rb', line 19
def delete_media(id)
delete_request("media/#{id}")
end
|
19
20
21
|
# File 'lib/kazoo-client/menus.rb', line 19
def (id)
delete_request("menus/#{id}")
end
|
#delete_phone_number(id) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/phone_numbers.rb', line 11
def delete_phone_number(id)
delete_request("phone_numbers/#{id}")
end
|
#delete_queue(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/queues.rb', line 19
def delete_queue(id)
delete_request("queues/#{id}")
end
|
#delete_request(url) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/kazoo-client/common.rb', line 84
def delete_request(url)
response = HTTP.()
.delete("#{@base_url}/#{@version}/accounts/#{@account_id}/#{url}")
result = JSON.parse(response.body)
case response.code
when (200..299)
return result['data']
else
raise DeleteError, "Delete error: #{response.status} #{result['data']}"
end
end
|
#delete_resource(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/resources.rb', line 19
def delete_resource(id)
delete_request("resources/#{id}")
end
|
#delete_temporal_rule(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/temporal_rules.rb', line 19
def delete_temporal_rule(id)
delete_request("temporal_rules/#{id}")
end
|
#delete_user(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/users.rb', line 19
def delete_user(id)
delete_request("users/#{id}")
end
|
#delete_vmbox(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/vmboxes.rb', line 19
def delete_vmbox(id)
delete_request("vmboxes/#{id}")
end
|
#get_account(id) ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/accounts.rb', line 3
def get_account(id)
get_request("accounts/#{id}")
end
|
#get_account_children(id) ⇒ Object
11
12
13
|
# File 'lib/kazoo-client/accounts.rb', line 11
def get_account_children(id)
get_request("accounts/#{id}/children")
end
|
#get_account_descendants(id) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/accounts.rb', line 15
def get_account_descendants(id)
get_request("accounts/#{id}/descendants")
end
|
#get_account_siblings(id) ⇒ Object
19
20
21
|
# File 'lib/kazoo-client/accounts.rb', line 19
def get_account_siblings(id)
get_request("accounts/#{id}/siblings")
end
|
#get_callflow(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/callflows.rb', line 7
def get_callflow(id)
get_request("callflows/#{id}")
end
|
#get_callflows ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/callflows.rb', line 3
def get_callflows
get_request('callflows')
end
|
#get_conference(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/conferences.rb', line 7
def get_conference(id)
get_request("conferences/#{id}")
end
|
#get_conferences ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/conferences.rb', line 3
def get_conferences
get_request('conferences')
end
|
#get_deployment(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/servers.rb', line 7
def get_deployment(id)
get_request("servers/#{id}/deployment")
end
|
#get_device(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/devices.rb', line 7
def get_device(id)
get_request("devices/#{id}")
end
|
#get_devices ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/devices.rb', line 3
def get_devices
get_request('devices')
end
|
#get_devices_status ⇒ Object
23
24
25
|
# File 'lib/kazoo-client/devices.rb', line 23
def get_devices_status
get_request('devices/status')
end
|
#get_directories ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/directories.rb', line 3
def get_directories
get_request('directories')
end
|
#get_directory(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/directories.rb', line 7
def get_directory(id)
get_request("directories/#{id}")
end
|
#get_hotdesk ⇒ Object
23
24
25
|
# File 'lib/kazoo-client/users.rb', line 23
def get_hotdesk
get_request('users/hotdesk')
end
|
#get_languages ⇒ Object
23
24
25
|
# File 'lib/kazoo-client/media.rb', line 23
def get_languages
get_request('media/languages')
end
|
#get_languages_missing ⇒ Object
27
28
29
|
# File 'lib/kazoo-client/media.rb', line 27
def get_languages_missing
get_request('media/languages/missing')
end
|
#get_limits ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/limits.rb', line 3
def get_limits
get_request('limits')
end
|
#get_logs(id) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/servers.rb', line 15
def get_logs(id)
get_request("servers/#{id}/log")
end
|
7
8
9
|
# File 'lib/kazoo-client/media.rb', line 7
def get_media(id)
get_request("media/#{id}")
end
|
3
4
5
|
# File 'lib/kazoo-client/media.rb', line 3
def get_medias
get_request('media')
end
|
7
8
9
|
# File 'lib/kazoo-client/menus.rb', line 7
def (id)
get_request("menus/#{id}")
end
|
3
4
5
|
# File 'lib/kazoo-client/menus.rb', line 3
def
get_request('menus')
end
|
#get_phone_numbers ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/phone_numbers.rb', line 3
def get_phone_numbers
get_request('phone_numbers')
end
|
#get_queue(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/queues.rb', line 7
def get_queue(id)
get_request("queues/#{id}")
end
|
#get_queues ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/queues.rb', line 3
def get_queues
get_request('queues')
end
|
#get_request(url) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/kazoo-client/common.rb', line 48
def get_request(url)
response = HTTP.()
.get("#{@base_url}/#{@version}/accounts/#{@account_id}/#{url}")
result = JSON.parse(response.body)
case response.code
when (200..299)
return result['data']
else
raise GetError, "Get error: #{response.status} #{result['data']}"
end
end
|
#get_resource(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/resources.rb', line 7
def get_resource(id)
get_request("resources/#{id}")
end
|
#get_resources ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/resources.rb', line 3
def get_resources
get_request('resources')
end
|
#get_servers ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/servers.rb', line 3
def get_servers
get_request('servers')
end
|
#get_temporal_rule(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/temporal_rules.rb', line 7
def get_temporal_rule(id)
get_request("temporal_rules/#{id}")
end
|
#get_temporal_rules ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/temporal_rules.rb', line 3
def get_temporal_rules
get_request('temporal_rules')
end
|
#get_user(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/users.rb', line 7
def get_user(id)
get_request("users/#{id}")
end
|
#get_users ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/users.rb', line 3
def get_users
get_request('users')
end
|
#get_vmbox(id) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/vmboxes.rb', line 7
def get_vmbox(id)
get_request("vmboxes/#{id}")
end
|
#get_vmboxes ⇒ Object
3
4
5
|
# File 'lib/kazoo-client/vmboxes.rb', line 3
def get_vmboxes
get_request('vmboxes')
end
|
#post_request(url, data) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/kazoo-client/common.rb', line 72
def post_request(url, data)
response = HTTP.()
.post("#{@base_url}/#{@version}/accounts/#{@account_id}/#{url}", json: data)
result = JSON.parse(response.body)
case response.code
when (200..299)
return result['data']
else
raise PostError, "Post error: #{response.status} #{result['data']}"
end
end
|
#put_request(url, data) ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/kazoo-client/common.rb', line 60
def put_request(url, data)
response = HTTP.()
.put("#{@base_url}/#{@version}/accounts/#{@account_id}/#{url}", json: data)
result = JSON.parse(response.body)
case response.code
when (200..299)
return result['data']
else
raise PutError, "Put error: #{response.status} #{result['data']}"
end
end
|
#sync_device(id) ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/kazoo-client/devices.rb', line 27
def sync_device(id)
data = { data: {}, verb: 'POST' }
if @version == 'v2'
post_request("devices/#{id}/sync", data)
else
raise VersionError, 'sync_device is not implemented for v1 api'
end
end
|
#update_account(id, data) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/accounts.rb', line 7
def update_account(id, data)
post_request("accounts/#{id}", data)
end
|
#update_callflow(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/callflows.rb', line 15
def update_callflow(id, data)
post_request("callflows/#{id}", data)
end
|
#update_conference(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/conferences.rb', line 15
def update_conference(id, data)
post_request("conferences/#{id}", data)
end
|
#update_device(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/devices.rb', line 15
def update_device(id, data)
post_request("devices/#{id}", data)
end
|
#update_directory(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/directories.rb', line 15
def update_directory(id, data)
post_request("directories/#{id}", data)
end
|
15
16
17
|
# File 'lib/kazoo-client/media.rb', line 15
def update_media(id, data)
post_request("media/#{id}", data)
end
|
15
16
17
|
# File 'lib/kazoo-client/menus.rb', line 15
def (id, data)
post_request("menus/#{id}", data)
end
|
#update_phone_number(id, data) ⇒ Object
7
8
9
|
# File 'lib/kazoo-client/phone_numbers.rb', line 7
def update_phone_number(id, data)
post_request("phone_numbers/#{id}", data)
end
|
#update_queue(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/queues.rb', line 15
def update_queue(id, data)
post_request("queues/#{id}", data)
end
|
#update_resource(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/resources.rb', line 15
def update_resource(id, data)
post_request("resources/#{id}", data)
end
|
#update_temporal_rule(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/temporal_rules.rb', line 15
def update_temporal_rule(id, data)
post_request("temporal_rules/#{id}", data)
end
|
#update_user(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/users.rb', line 15
def update_user(id, data)
post_request("users/#{id}", data)
end
|
#update_vmbox(id, data) ⇒ Object
15
16
17
|
# File 'lib/kazoo-client/vmboxes.rb', line 15
def update_vmbox(id, data)
post_request("vmboxes/#{id}", data)
end
|