asterisk-ari 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.travis.yml +20 -0
  4. data/Gemfile +13 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +38 -0
  7. data/Rakefile +8 -0
  8. data/asterisk-ari.gemspec +28 -0
  9. data/lib/ari.rb +2 -0
  10. data/lib/ari/client.rb +1441 -0
  11. data/lib/ari/errors.rb +38 -0
  12. data/lib/ari/http_services.rb +87 -0
  13. data/lib/ari/json.rb +23 -0
  14. data/lib/ari/response.rb +18 -0
  15. data/lib/ari/version.rb +3 -0
  16. data/spec/ari/client_spec.rb +158 -0
  17. data/spec/ari/errors_spec.rb +25 -0
  18. data/spec/ari/http_service_spec.rb +18 -0
  19. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_applications_list_returns_data.yml +38 -0
  20. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_asterisk_get_info_returns_data.yml +39 -0
  21. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_bridges_create_returns_data.yml +147 -0
  22. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_bridges_list_returns_data.yml +38 -0
  23. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_channels_list_returns_data.yml +38 -0
  24. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_device_states_list_returns_data.yml +38 -0
  25. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_endpoints_list_by_tech_returns_data.yml +38 -0
  26. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_endpoints_list_returns_data.yml +38 -0
  27. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_endpoints_send_message_returns_data.yml +38 -0
  28. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_global_var_asterisk_set_global_var_and_asterisk_get_global_var_returns_data.yml +73 -0
  29. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_recordings_list_stored_returns_data.yml +38 -0
  30. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_sounds_get_returns_data.yml +38 -0
  31. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_sounds_list_with_params_returns_data.yml +395 -0
  32. data/spec/fixtures/vcr_cassettes/ARI_Client/api_request_sounds_list_without_params_returns_data.yml +395 -0
  33. data/spec/spec_helper.rb +22 -0
  34. data/spec/support/config.yml +4 -0
  35. data/spec/support/config_loader.rb +2 -0
  36. data/spec/support/vcr.rb +14 -0
  37. metadata +164 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad92847490ec4384f44d37c888d2307a69a35e41
4
+ data.tar.gz: a29576ab93496121fd8e700bba71e229202b768f
5
+ SHA512:
6
+ metadata.gz: 3fe7f24a8f77fd08c9d84ec75467c15d2cb3a610a035731a32f1ac41095682c726b40a3eeecba13719ed3dc1166bad60961b07568ec9871c7757867ba2c74ce8
7
+ data.tar.gz: 13c0b172d5aa2ad55a7b33399f00b4251f8244bb3d6e7dae2da12ccb0f247b7374c0d7f94f53ebe09434514f55a89711b80638fd7afeb2094eebf88188e372b4
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,20 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - rbx-2.1.1
6
+ - ruby-head
7
+ - 1.8.7
8
+ - 2.0.0
9
+ - 2.1.0
10
+ - jruby-18mode
11
+ - jruby-19mode
12
+ - jruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ - rvm: jruby-18mode
17
+ - rvm: jruby-19mode
18
+ - rvm: jruby-head
19
+ - rvm: 1.8.7
20
+ - rvm: rbx-2.1.1
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "yard"
5
+ end
6
+
7
+ group :development, :test do
8
+ gem "pry"
9
+ gem "pry-doc"
10
+ gem "simplecov"
11
+ end
12
+
13
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) Tatsuo Kaniwa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # ARI
2
+
3
+ ARI is a Ruby client library for the [Asterisk REST Interface (ARI)](https://wiki.asterisk.org/wiki/pages/viewpage.action?pageId=29395573)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'asterisk-ari', :require => 'ari'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install asterisk-ari
18
+
19
+ Usage
20
+ ---
21
+ ```ruby
22
+ require 'ari'
23
+ # setup
24
+ client = ARI::Client.new({ :host => "localhost", :port => 8088, :username => "username", :password => "password" })
25
+ # specify prefix
26
+ # client = ARI::Client.new({ :host => "localhost", :port => 8088, :username => "username", :password => "password", :prefix => "asterisk" })
27
+
28
+ result = client.bridges_create({type: "mixing", bridgeId: "bridge_id", name: "bridge_name"})
29
+ # => {"id"=>"bridge_id", "creator"=>"Stasis", "technology"=>"simple_bridge", "bridge_type"=>"mixing", "bridge_class"=>"stasis", "name"=>"bridge_name", "channels"=>[]}
30
+
31
+ result = client.bridges_get result["id"]
32
+ # => {"id"=>"bridge_id", "creator"=>"Stasis", "technology"=>"simple_bridge", "bridge_type"=>"mixing", "bridge_class"=>"stasis", "name"=>"bridge_name", "channels"=>[]}
33
+ ```
34
+
35
+ ## TODO
36
+
37
+ * add support for WebSocket APIs [(Events REST API)](https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API)
38
+ * add test
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :spec
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new do |t|
7
+ t.rspec_opts = ["--color", "--format doc"]
8
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ari/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "asterisk-ari"
8
+ spec.version = ARI::VERSION
9
+ spec.authors = ["Tatsuo Kaniwa"]
10
+ spec.email = ["tatsuo@kaniwa.biz"]
11
+ spec.summary = %q{ Ruby client library for the Asterisk REST Interface (ARI) }
12
+ spec.description = %q{ Ruby client library for the Asterisk REST Interface (ARI) }
13
+ spec.homepage = "https://github.com/t-k/asterisk-ari-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = `git ls-files -- {spec}/*`.split("\n")
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "multi_json"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock"
28
+ end
@@ -0,0 +1,2 @@
1
+ require "ari/version"
2
+ require "ari/client"
@@ -0,0 +1,1441 @@
1
+ require "ari/errors"
2
+ require "ari/http_services"
3
+
4
+ module ARI
5
+ # @!attribute [r] host
6
+ # @return [String] Host name
7
+ # @!attribute [r] port
8
+ # @return [Integer] Port number
9
+ # @!attribute [r] prefix
10
+ # @return [String] Prefix allows you to specify a prefix for all requests to the server.
11
+ # @!attribute [r] username
12
+ # @return [String] username for basic auth
13
+ # @!attribute [r] password
14
+ # @return [String] password for basic auth
15
+ class Client
16
+
17
+ # @param [Hash] options
18
+ # @option options [String] :host ("localhost") Host name
19
+ # @option options [Integer] :port (8088) Port number
20
+ # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
21
+ # @option options [String] :username username for basic auth
22
+ # @option options [String] :password password for basic auth
23
+ def initialize(options = {})
24
+ @host = options[:host] || "localhost"
25
+ @port = options[:port] || 8088
26
+ @prefix = options[:prefix] if options[:prefix]
27
+ @username = options[:username] if options[:username]
28
+ @password = options[:password] if options[:password]
29
+ end
30
+ attr_reader :host, :port, :prefix, :username, :password
31
+
32
+ %w(get post put delete).each do |verb|
33
+ define_method(verb) do |path, params = {}|
34
+ api_call(path, params, verb)
35
+ end
36
+ end
37
+
38
+ # Asterisk REST API
39
+
40
+ # GET
41
+ # /asterisk/info
42
+ # AsteriskInfo
43
+ # Gets Asterisk system information.
44
+ #
45
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
46
+ #
47
+ # @param [String] only Filter information returned. Allows comma separated values.
48
+ def asterisk_get_info
49
+ get "asterisk/info"
50
+ end
51
+
52
+ # GET
53
+ # /asterisk/variable
54
+ # Variable
55
+ # Get the value of a global variable.
56
+ #
57
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
58
+ #
59
+ # @param [Hash] params
60
+ # @option params [String] variable *required The variable to get
61
+ #
62
+ # Error Responses
63
+ #
64
+ # return 400 - Missing variable parameter.
65
+ def asterisk_get_global_var(params = {})
66
+ get "asterisk/variable", params
67
+ end
68
+
69
+ # POST
70
+ # /asterisk/variable
71
+ # void
72
+ # Set the value of a global variable.
73
+ #
74
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
75
+ #
76
+ # @param [Hash] params
77
+ # @option params [String] :variable *required The variable to set
78
+ # @option params [String] :value The value to set the variable to
79
+ #
80
+ # Error Responses
81
+ # 400 - Missing variable parameter.
82
+ def asterisk_set_global_var(params = {})
83
+ post "asterisk/variable", params
84
+ end
85
+
86
+
87
+ # Bridges REST API
88
+ #
89
+
90
+ # GET
91
+ # /bridges
92
+ # List[Bridge]
93
+ # List all active bridges in Asterisk.
94
+ #
95
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
96
+ def bridges_list
97
+ get "bridges"
98
+ end
99
+
100
+ # POST
101
+ # /bridges
102
+ # Bridge
103
+ # Create a new bridge.
104
+ #
105
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
106
+ #
107
+ # @param [Hash] params
108
+ # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
109
+ # @option params [String] :bridgeId Unique ID to give to the bridge being created.
110
+ # @option params [String] :name Name to give to the bridge being created.
111
+ def bridges_create(params = {})
112
+ post "bridges", params
113
+ end
114
+
115
+ # POST
116
+ # /bridges/:bridgeId
117
+ # Bridge
118
+ # Create a new bridge or updates an existing one.
119
+ #
120
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
121
+ #
122
+ # @param [String] bridge_id Unique ID to give to the bridge being created.
123
+ # @param [Hash] params
124
+ # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
125
+ # @option params [String] :name Set the name of the bridge.
126
+ def bridges_create_or_update_with_id(bridge_id, params = {})
127
+ post "bridges/#{bridge_id}", params
128
+ end
129
+
130
+ # GET
131
+ # /bridges/:bridgeId
132
+ # Bridge
133
+ # Get bridge details.
134
+ #
135
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
136
+ #
137
+ # @param [String] bridge_id Bridge's id
138
+ #
139
+ # Error Responses
140
+ #
141
+ # 404 - Bridge not found
142
+ def bridges_get(bridge_id)
143
+ get "bridges/#{bridge_id}"
144
+ end
145
+
146
+ # DELETE
147
+ # /bridges/:bridgeId
148
+ # void
149
+ # Shut down a bridge.
150
+ #
151
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
152
+ #
153
+ # @param [String] bridge_id Bridge's id
154
+ #
155
+ # Error Responses
156
+ #
157
+ # 404 - Bridge not found
158
+ def bridges_destroy(bridge_id)
159
+ delete "bridges/#{bridge_id}"
160
+ end
161
+
162
+ # POST
163
+ # /bridges/:bridgeId/addChannel
164
+ # void
165
+ # Add a channel to a bridge.
166
+ #
167
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
168
+ #
169
+ # @param [String] bridge_id Bridge's id
170
+ # @param [Hash] params
171
+ # @option params [String] :channel *required Ids of channels to add to bridge
172
+ # Allows comma separated values.
173
+ # @option params [String] :role Channel's role in the bridge
174
+ #
175
+ # Error Responses
176
+ #
177
+ # 400 - Channel not found
178
+ # 404 - Bridge not found
179
+ # 409 - Bridge not in Stasis application; Channel currently recording
180
+ # 422 - Channel not in Stasis application
181
+ def bridges_add_channel(bridge_id, params = {})
182
+ post "bridges/#{bridge_id}/addChannel", params
183
+ end
184
+
185
+ # POST
186
+ # /bridges/:bridgeId/removeChannel
187
+ # void
188
+ # Remove a channel from a bridge.
189
+ #
190
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
191
+ #
192
+ # @param [String] bridge_id Bridge's id
193
+ # @param [Hash] params
194
+ # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
195
+ #
196
+ # Error Responses
197
+ #
198
+ # 400 - Channel not found
199
+ # 404 - Bridge not found
200
+ # 409 - Bridge not in Stasis application
201
+ # 422 - Channel not in this bridge
202
+ def bridges_remove_channel(bridge_id, params = {})
203
+ post "bridges/#{bridge_id}/removeChannel", params
204
+ end
205
+
206
+ # POST
207
+ # /bridges/:bridgeId/moh
208
+ # void
209
+ # Play music on hold to a bridge or change the MOH class that is playing.
210
+ #
211
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
212
+ #
213
+ # @param [String] bridge_id Bridge's id
214
+ # @param [Hash] params
215
+ # @option params [String] :mohClass Channel's id
216
+ #
217
+ # Error Responses
218
+ #
219
+ # 404 - Bridge not found
220
+ # 409 - Bridge not in Stasis application
221
+ def bridges_start_moh(bridge_id, params = {})
222
+ post "bridges/#{bridge_id}/moh", params
223
+ end
224
+
225
+ # DELETE
226
+ # /bridges/:bridgeId/moh
227
+ # void
228
+ # Stop playing music on hold to a bridge.
229
+ #
230
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
231
+ #
232
+ # @param [String] bridge_id Bridge's id
233
+ #
234
+ # Error Responses
235
+ # 404 - Bridge not found
236
+ # 409 - Bridge not in Stasis application
237
+ def bridges_stop_moh(bridge_id)
238
+ delete "bridges/#{bridge_id}/moh"
239
+ end
240
+
241
+ # POST
242
+ # /bridges/:bridgeId/play
243
+ # Playback
244
+ # Start playback of media on a bridge.
245
+ #
246
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
247
+ #
248
+ # @param [String] bridge_id Bridge's id
249
+ # @param [Hash] params
250
+ # @option params [String] :media *required Media's URI to play.
251
+ # @option params [String] :lang For sounds, selects language for sound.
252
+ # @option params [Integer] :offsetms Number of media to skip before playing.
253
+ # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
254
+ # @option params [String] :playbackId Playback Id.
255
+ #
256
+ # Error Responses
257
+ #
258
+ # 404 - Bridge not found
259
+ # 409 - Bridge not in a Stasis application
260
+ def bridges_play(bridge_id, params = {})
261
+ post "bridges/#{bridge_id}/play", params
262
+ end
263
+
264
+ # POST
265
+ # /bridges/:bridgeId/play/:playbackId
266
+ # Playback
267
+ # Start playback of media on a bridge.
268
+ #
269
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
270
+ #
271
+ # @param [String] bridge_id Bridge's id
272
+ # @param [String] playback_id Playback ID.
273
+ # @param [Hash] params
274
+ # @option params [String] :media *required Media's URI to play.
275
+ # @option params [String] :lang For sounds, selects language for sound.
276
+ # @option params [Integer] :offsetms Number of media to skip before playing.
277
+ # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
278
+ #
279
+ # Error Responses
280
+ #
281
+ # 404 - Bridge not found
282
+ # 409 - Bridge not in a Stasis application
283
+ def bridges_play_with_id(bridge_id, playback_id, params = {})
284
+ post "bridges/#{bridge_id}/play/#{playback_id}", params
285
+ end
286
+
287
+ # POST
288
+ # /bridges/:bridgeId/record
289
+ # LiveRecording
290
+ # Start a recording.
291
+ #
292
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
293
+ #
294
+ # @param [String] bridge_id Bridge's id
295
+ # @param [Hash] params
296
+ # @option params [String] :name *required Recording's filename
297
+ # @option params [String] :format *required Format to encode audio in
298
+ # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
299
+ # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
300
+ # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
301
+ # @option params [Boolean] :beep Play beep when recording begins
302
+ # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
303
+ #
304
+ # Error Responses
305
+ #
306
+ # 400 - Invalid parameters
307
+ # 404 - Bridge not found
308
+ # 409 - Bridge is not in a Stasis application; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail
309
+ # 422 - The format specified is unknown on this system
310
+ def bridges_record(bridge_id, params = {})
311
+ post "bridges/#{bridge_id}/record", params
312
+ end
313
+
314
+ # Channels REST API
315
+ # GET
316
+ # /channels
317
+ # List[Channel]
318
+ # List all active channels in Asterisk.
319
+ #
320
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
321
+ #
322
+ def channels_list
323
+ get "channels"
324
+ end
325
+
326
+ # POST
327
+ # /channels
328
+ # Channel
329
+ # Create a new channel (originate).
330
+ #
331
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
332
+ #
333
+ # @param [Hash] params
334
+ # @option params [String] :endpoint *required Endpoint to call.
335
+ # @option params [String] :extension The extension to dial after the endpoint answers
336
+ # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
337
+ # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
338
+ # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
339
+ # @option params [String] :appArgs The application arguments to pass to the Stasis application.
340
+ # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
341
+ # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
342
+ # @option params [String] :channelId The unique id to assign the channel on creation.
343
+ # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
344
+ #
345
+ # Body parameter
346
+ #
347
+ # variables: containers - The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
348
+ #
349
+ # Error Responses
350
+ #
351
+ # 400 - Invalid parameters for originating a channel.
352
+ def channels_originate(params = {})
353
+ post "channels", params
354
+ end
355
+
356
+ # GET
357
+ # /channels/:channelId
358
+ # Channel
359
+ # Channel details.
360
+ #
361
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
362
+ #
363
+ # @param [String] channel_id Channel's id
364
+ #
365
+ # Error Responses
366
+ #
367
+ # 404 - Channel not found
368
+ def channels_get(channel_id)
369
+ get "channels/#{channel_id}"
370
+ end
371
+
372
+ # POST
373
+ # /channels/:channelId
374
+ # Channel
375
+ # Create a new channel (originate with id).
376
+ #
377
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
378
+ #
379
+ # @param [String] channel_id The unique id to assign the channel on creation.
380
+ # @param [Hash] params
381
+ # @option params [String] :endpoint *required Endpoint to call.
382
+ # @option params [String] :extension The extension to dial after the endpoint answers
383
+ # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
384
+ # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
385
+ # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
386
+ # @option params [String] :appArgs The application arguments to pass to the Stasis application.
387
+ # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
388
+ # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
389
+ # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
390
+ #
391
+ # Body parameter
392
+ #
393
+ # variables: containers - The "variables" key in the body object holds variable key/value pairs to set on the channel on creation. Other keys in the body object are interpreted as query parameters. Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
394
+ #
395
+ # Error Responses
396
+ #
397
+ # 400 - Invalid parameters for originating a channel.
398
+ def channels_originate_with_id(channel_id, params = {})
399
+ post "channels/#{channel_id}", params
400
+ end
401
+
402
+ # DELETE
403
+ # /channels/:channelId
404
+ # void
405
+ # Delete (i.e. hangup) a channel.
406
+ #
407
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
408
+ #
409
+ # @param [String] channel_id Channel's id
410
+ # @param [Hash] params
411
+ # @option params [String] :reason Reason for hanging up the channel
412
+ #
413
+ # Error Responses
414
+ #
415
+ # 400 - Invalid reason for hangup provided
416
+ # 404 - Channel not found
417
+ def channels_hangup(channel_id, params = {})
418
+ delete "channels/#{channel_id}", params
419
+ end
420
+
421
+ # POST
422
+ # /channels/:channelId/continue
423
+ # void
424
+ # Exit application; continue execution in the dialplan.
425
+ #
426
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
427
+ #
428
+ # @param [String] channel_id Channel's id
429
+ # @param [Hash] params
430
+ # @option params [String] :context The context to continue to.
431
+ # @option params [String] :extension The extension to continue to.
432
+ # @option params [Integer] :priority The priority to continue to.
433
+ #
434
+ # Error Responses
435
+ #
436
+ # 404 - Channel not found
437
+ # 409 - Channel not in a Stasis application
438
+ def channels_continue_in_dialplan(channel_id, params = {})
439
+ post "channels/#{channel_id}/continue", params
440
+ end
441
+
442
+ # POST
443
+ # /channels/:channelId/answer
444
+ # void
445
+ # Answer a channel.
446
+ #
447
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
448
+ #
449
+ # @param [String] channel_id Channel's id
450
+ #
451
+ # Error Responses
452
+ #
453
+ # 404 - Channel not found
454
+ # 409 - Channel not in a Stasis application
455
+ def channels_answer(channel_id)
456
+ post "channels/#{channel_id}/answer"
457
+ end
458
+
459
+ # POST
460
+ # /channels/:channelId/ring
461
+ # void
462
+ # Indicate ringing to a channel.
463
+ #
464
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
465
+ #
466
+ # @param [String] channel_id Channel's id
467
+ #
468
+ # Error Responses
469
+ #
470
+ # 404 - Channel not found
471
+ # 409 - Channel not in a Stasis application
472
+ def channels_ring(channel_id)
473
+ post "channels/#{channel_id}/ring"
474
+ end
475
+
476
+ # DELETE
477
+ # /channels/:channelId/ring
478
+ # void
479
+ # Stop ringing indication on a channel if locally generated.
480
+ #
481
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
482
+ #
483
+ # @param [String] channel_id Channel's id
484
+ #
485
+ # Error Responses
486
+ #
487
+ # 404 - Channel not found
488
+ # 409 - Channel not in a Stasis application
489
+ def channels_ring_stop(channel_id)
490
+ delete "channels/#{channel_id}/ring"
491
+ end
492
+
493
+ # POST
494
+ # /channels/:channelId/dtmf
495
+ # void
496
+ # Send provided DTMF to a given channel.
497
+ #
498
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
499
+ #
500
+ # @param [String] channel_id Channel's id
501
+ # @param [Hash] params
502
+ # @option params [String] :dtmf DTMF To send.
503
+ # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
504
+ # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
505
+ # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
506
+ # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
507
+ #
508
+ # Error Responses
509
+ #
510
+ # 400 - DTMF is required
511
+ # 404 - Channel not found
512
+ # 409 - Channel not in a Stasis application
513
+ def channels_send_dtmf(channel_id, params = {})
514
+ post "channels/#{channel_id}/dtmf", params
515
+ end
516
+
517
+ # POST
518
+ # /channels/:channelId/mute
519
+ # void
520
+ # Mute a channel.
521
+ #
522
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
523
+ #
524
+ # @param [String] channel_id Channel's id
525
+ # @param [Hash] params
526
+ # @option params [String] :direction ("both") Direction in which to mute audio
527
+ #
528
+ # Error Responses
529
+ #
530
+ # 404 - Channel not found
531
+ # 409 - Channel not in a Stasis application
532
+ def channels_mute(channel_id, params = {})
533
+ post "channels/#{channel_id}/mute", params
534
+ end
535
+
536
+ # DELETE
537
+ # /channels/:channelId/mute
538
+ # void
539
+ # Unmute a channel.
540
+ #
541
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
542
+ #
543
+ # @param [String] channel_id Channel's id
544
+ # @param [Hash] params
545
+ # @option params [String] :direction ("both") Direction in which to unmute audio
546
+ #
547
+ # Error Responses
548
+ #
549
+ # 404 - Channel not found
550
+ # 409 - Channel not in a Stasis application
551
+ def channels_unmute(channel_id, params = {})
552
+ delete "channels/#{channel_id}/mute", params
553
+ end
554
+
555
+ # POST
556
+ # /channels/:channelId/hold
557
+ # void
558
+ # Hold a channel.
559
+ #
560
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
561
+ #
562
+ # @param [String] channel_id Channel's id
563
+ #
564
+ # Error Responses
565
+ #
566
+ # 404 - Channel not found
567
+ # 409 - Channel not in a Stasis application
568
+ def channels_hold(channel_id)
569
+ post "channels/#{channel_id}/hold"
570
+ end
571
+
572
+ # DELETE
573
+ # /channels/:channelId/hold
574
+ # void
575
+ # Remove a channel from hold.
576
+ #
577
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
578
+ #
579
+ # @param [String] channel_id Channel's id
580
+ #
581
+ # Error Responses
582
+ #
583
+ # 404 - Channel not found
584
+ # 409 - Channel not in a Stasis application
585
+ def channels_unhold(channel_id)
586
+ delete "channels/#{channel_id}/hold"
587
+ end
588
+
589
+ # POST
590
+ # /channels/:channelId/moh
591
+ # void
592
+ # Play music on hold to a channel.
593
+ #
594
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
595
+ #
596
+ # @param [String] channel_id Channel's id
597
+ # @param [Hash] params
598
+ # @option params [String] :mohClass Music on hold class to use
599
+ #
600
+ # Error Responses
601
+ #
602
+ # 404 - Channel not found
603
+ # 409 - Channel not in a Stasis application
604
+ def channels_start_moh(channel_id, params = {})
605
+ post "channels/#{channel_id}/moh", params
606
+ end
607
+
608
+ # DELETE
609
+ # /channels/:channelId/moh
610
+ # void
611
+ # Stop playing music on hold to a channel.
612
+ # POST
613
+ #
614
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
615
+ #
616
+ # @param [String] channel_id Channel's id
617
+ #
618
+ # Error Responses
619
+ #
620
+ # 404 - Channel not found
621
+ # 409 - Channel not in a Stasis application
622
+ def channels_stop_moh(channel_id)
623
+ delete "channels/#{channel_id}/moh"
624
+ end
625
+
626
+ # /channels/:channelId/silence
627
+ # void
628
+ # Play silence to a channel.
629
+ #
630
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
631
+ #
632
+ # @param [String] channel_id Channel's id
633
+ #
634
+ # Error Responses
635
+ #
636
+ # 404 - Channel not found
637
+ # 409 - Channel not in a Stasis application
638
+ def channels_start_silence(channel_id)
639
+ post "channels/#{channel_id}/silence"
640
+ end
641
+
642
+ # DELETE
643
+ # /channels/:channelId/silence
644
+ # void
645
+ # Stop playing silence to a channel.
646
+ #
647
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
648
+ #
649
+ # @param [String] channel_id Channel's id
650
+ #
651
+ # Error Responses
652
+ #
653
+ # 404 - Channel not found
654
+ # 409 - Channel not in a Stasis application
655
+ def channels_stop_silence(channel_id)
656
+ delete "channels/#{channel_id}/silence"
657
+ end
658
+
659
+ # POST
660
+ # /channels/:channelId/play
661
+ # Playback
662
+ # Start playback of media.
663
+ #
664
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
665
+ #
666
+ # @param [String] channel_id Channel's id
667
+ # @param [Hash] params
668
+ # @option params [String] :media *required Media's URI to play.
669
+ # @option params [String] :lang For sounds, selects language for sound.
670
+ # @option params [Integer] :offsetms Number of media to skip before playing.
671
+ # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
672
+ # @option params [String] :playbackId Playback ID.
673
+ #
674
+ # Error Responses
675
+ #
676
+ # 404 - Channel not found
677
+ # 409 - Channel not in a Stasis application
678
+ def channels_play(channel_id, params = {})
679
+ post "channels/#{channel_id}/play", params
680
+ end
681
+
682
+ # POST
683
+ # /channels/:channelId/play/:playbackId
684
+ # Playback
685
+ # Start playback of media and specify the playbackId.
686
+ #
687
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
688
+ #
689
+ # @param [String] channel_id channel_id
690
+ # @param [String] playback_id playback_id
691
+ # @param [Hash] params
692
+ # @option params [String] :media *required Media's URI to play.
693
+ # @option params [String] :lang For sounds, selects language for sound.
694
+ # @option params [Integer] :offsetms Number of media to skip before playing.
695
+ # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
696
+ #
697
+ # Error Responses
698
+ #
699
+ # 404 - Channel not found
700
+ # 409 - Channel not in a Stasis application
701
+ def channels_play_with_id(channel_id, playback_id, params = {})
702
+ post "channels/#{channel_id}/play/#{playback_id}", params
703
+ end
704
+
705
+ # POST
706
+ # /channels/:channelId/record
707
+ # LiveRecording
708
+ # Start a recording.
709
+ #
710
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
711
+ #
712
+ # @param [String] channel_id Channel's id
713
+ # @param [Hash] params
714
+ # @option params [String] :name *required Recording's filename
715
+ # @option params [String] :format *required Format to encode audio in
716
+ # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
717
+ # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
718
+ # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
719
+ # @option params [Boolen] :beep Play beep when recording begins
720
+ # @option params [String] :terminateOn ("none") DTMF input to terminate recording
721
+ #
722
+ # Error Responses
723
+ #
724
+ # 400 - Invalid parameters
725
+ # 404 - Channel not found
726
+ # 409 - Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail
727
+ # 422 - The format specified is unknown on this system
728
+ def channels_record(channel_id, params = {})
729
+ post "channels/#{channel_id}/record", params
730
+ end
731
+
732
+ # GET
733
+ # /channels/:channelId/variable
734
+ # Variable
735
+ # Get the value of a channel variable or function.
736
+ #
737
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
738
+ #
739
+ # @param [String] channel_id channel_id
740
+ # @param [Hash] params
741
+ # @option params [String] :variable *required The channel variable or function to get
742
+ #
743
+ # Error Responses
744
+ #
745
+ # 400 - Missing variable parameter.
746
+ # 404 - Channel not found
747
+ # 409 - Channel not in a Stasis application
748
+ def channels_get_channel_var(channel_id, params = {})
749
+ get "channels/#{channel_id}/variable", params
750
+ end
751
+
752
+ # POST
753
+ # /channels/:channelId/variable
754
+ # void
755
+ # Set the value of a channel variable or function.
756
+ #
757
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
758
+ #
759
+ # @param [String] channel_id Channel's id
760
+ # @param [Hash] params
761
+ # @option params [String] :variable *required The channel variable or function to set
762
+ # @option params [String] :value The value to set the variable to
763
+ #
764
+ # Error Responses
765
+ #
766
+ # 400 - Missing variable parameter.
767
+ # 404 - Channel not found
768
+ # 409 - Channel not in a Stasis application
769
+ def channels_set_channel_var(channel_id, params = {})
770
+ post "channels/#{channel_id}/variable", params
771
+ end
772
+
773
+ # POST
774
+ # /channels/:channelId/snoop
775
+ # Channel
776
+ # Start snooping.
777
+ #
778
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
779
+ #
780
+ # @param [String] channel_id Channel's id
781
+ # @param [Hash] params
782
+ # @option params [String] :spy ("none") Direction of audio to spy on
783
+ # @option params [String] :whisper ("none") Direction of audio to whisper into
784
+ # @option params [String] :app *required Application the snooping channel is placed into
785
+ # @option params [String] :appArgs The application arguments to pass to the Stasis application
786
+ # @option params [String] :snoopId Unique ID to assign to snooping channel
787
+ #
788
+ # Error Responses
789
+ #
790
+ # 400 - Invalid parameters
791
+ # 404 - Channel not found
792
+ def channels_snoop_channel(channel_id, params = {})
793
+ post "channels/#{channel_id}/snoop", params
794
+ end
795
+
796
+ # POST
797
+ # /channels/:channelId/snoop/:snoopId
798
+ # Channel
799
+ # Start snooping.
800
+ #
801
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
802
+ #
803
+ # @param [String] channel_id Channel's id
804
+ # @param [String] snoop_id Unique ID to assign to snooping channel
805
+ # @param [Hash] params
806
+ # @option param [String] :spy ("none") Direction of audio to spy on
807
+ # @option param [String] :whisper ("none") Direction of audio to whisper into
808
+ # @option param [String] :app *required Application the snooping channel is placed into
809
+ # @option param [String] :appArgs The application arguments to pass to the Stasis application
810
+ #
811
+ # Error Responses
812
+ #
813
+ # 400 - Invalid parameters
814
+ # 404 - Channel not found
815
+ def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
816
+ post "channels/#{channel_id}/snoop/#{snoop_id}", params
817
+ end
818
+
819
+ # Endpoints REST API
820
+
821
+ # GET
822
+ # /endpoints
823
+ # List[Endpoint]
824
+ # List all endpoints.
825
+ #
826
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
827
+ def endpoints_list
828
+ get "endpoints"
829
+ end
830
+
831
+ # PUT
832
+ # /endpoints/sendMessage
833
+ # void
834
+ # Send a message to some technology URI or endpoint.
835
+ #
836
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
837
+ #
838
+ # @param [Hash] params
839
+ # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
840
+ # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
841
+ # @option param [String] body The body of the message
842
+ #
843
+ # Body parameter
844
+ #
845
+ # variables: containers -
846
+ #
847
+ # Error Responses
848
+ #
849
+ # 404 - Endpoint not found
850
+ def endpoints_send_message(params = {})
851
+ put "endpoints/sendMessage", params
852
+ end
853
+
854
+ # GET
855
+ # /endpoints/:tech
856
+ # List[Endpoint]
857
+ # List available endoints for a given endpoint technology.
858
+ #
859
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
860
+ #
861
+ # @param [String] tech Technology of the endpoints (sip,iax2,...)
862
+ #
863
+ # Error Responses
864
+ #
865
+ # 404 - Endpoints not found
866
+ def endpoints_list_by_tech(tech)
867
+ get "endpoints/#{tech}"
868
+ end
869
+
870
+ # GET
871
+ # /endpoints/:tech/:resource
872
+ # Endpoint
873
+ # Details for an endpoint.
874
+ #
875
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
876
+ #
877
+ # @param [String] tech Technology of the endpoint
878
+ # @param [String] resource ID of the endpoint
879
+ #
880
+ # Error Responses
881
+ #
882
+ # 400 - Invalid parameters for sending a message.
883
+ # 404 - Endpoints not found
884
+ def endpoints_get(tech, resource)
885
+ get "endpoints/#{tech}/#{resource}"
886
+ end
887
+
888
+ # PUT
889
+ # /endpoints/:tech/:resource/sendMessage
890
+ # void
891
+ # Send a message to some endpoint in a technology.
892
+ #
893
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
894
+ #
895
+ # @param [String] tech Technology of the endpoint
896
+ # @param [String] resource ID of the endpoint
897
+ # @param [Hash] params
898
+ # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
899
+ # @option params [String] :body The body of the message
900
+ #
901
+ # Body parameter
902
+ #
903
+ # variables: containers -
904
+ #
905
+ # Error Responses
906
+ #
907
+ # 400 - Invalid parameters for sending a message.
908
+ # 404 - Endpoint not found
909
+ def endpoints_send_message_to_endpoint(tech, resource, params = {})
910
+ put "endpoints/#{tech}/#{resource}/sendMessage", params
911
+ end
912
+
913
+ # TODO
914
+ # # Events REST API
915
+
916
+ # # GET
917
+ # # /events
918
+ # # Message
919
+ # # WebSocket connection for events.
920
+ # #
921
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
922
+ # def events_event_websocket
923
+ # get "events"
924
+ # end
925
+
926
+ # # POST
927
+ # # /events/user/{eventName}
928
+ # # void
929
+ # # Generate a user event.
930
+ # #
931
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
932
+ # #
933
+ # # @param [String] event_name event_name
934
+ # def events_user_event(event_name)
935
+ # post "events/user/#{event_name}"
936
+ # end
937
+
938
+ # Recordings REST API
939
+
940
+ # GET
941
+ # /recordings/stored
942
+ # List[StoredRecording]
943
+ # List recordings that are complete.
944
+ #
945
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
946
+ def recordings_list_stored
947
+ get "recordings/stored"
948
+ end
949
+
950
+ # GET
951
+ #
952
+ # /recordings/stored/:recordingName
953
+ #
954
+ # StoredRecording
955
+ # Get a stored recording's details.
956
+ #
957
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
958
+ #
959
+ # @param [String] recording_name The name of the recording
960
+ #
961
+ # Error Responses
962
+ #
963
+ # 404 - Recording not found
964
+ def recordings_get_stored(recording_name)
965
+ get "recordings/stored/#{recording_name}"
966
+ end
967
+
968
+ # DELETE
969
+ # /recordings/stored/:recordingName
970
+ # void
971
+ # Delete a stored recording.
972
+ #
973
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
974
+ #
975
+ # @param [String] recording_name The name of the recording
976
+ #
977
+ # Error Responses
978
+ #
979
+ # 404 - Recording not found
980
+ def recordings_delete_stored(recording_name)
981
+ delete "recordings/stored/#{recording_name}"
982
+ end
983
+
984
+ # POST
985
+ # /recordings/stored/:recordingName/copy
986
+ # StoredRecording
987
+ # Copy a stored recording.
988
+ #
989
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
990
+ #
991
+ # @param [String] recording_name The name of the recording to copy
992
+ # @param [Hash] params
993
+ # @option params [String] :destinationRecordingName *required The destination name of the recording
994
+ #
995
+ # Error Responses
996
+ #
997
+ # 404 - Recording not found
998
+ # 409 - A recording with the same name already exists on the system
999
+ def recordings_copy_stored(recording_name, params = {})
1000
+ post "recordings/stored/#{recording_name}/copy", params
1001
+ end
1002
+
1003
+ # GET
1004
+ # /recordings/live/:recordingName
1005
+ # LiveRecording
1006
+ # List live recordings.
1007
+ #
1008
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
1009
+ #
1010
+ # @param [String] recording_name The name of the recording
1011
+ #
1012
+ # Error Responses
1013
+ #
1014
+ # 404 - Recording not found
1015
+ def recordings_get_live(recording_name)
1016
+ get "recordings/live/#{recording_name}"
1017
+ end
1018
+
1019
+ # DELETE
1020
+ # /recordings/live/:recordingName
1021
+ # void
1022
+ # Stop a live recording and discard it.
1023
+ #
1024
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
1025
+ #
1026
+ # @param [String] recording_name The name of the recording
1027
+ #
1028
+ # Error Responses
1029
+ #
1030
+ # 404 - Recording not found
1031
+ def recordings_cancel(recording_name)
1032
+ delete "recordings/live/#{recording_name}"
1033
+ end
1034
+
1035
+ # POST
1036
+ # /recordings/live/:recordingName/stop
1037
+ # void
1038
+ # Stop a live recording and store it.
1039
+ #
1040
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
1041
+ #
1042
+ # @param [String] recording_name The name of the recording
1043
+ #
1044
+ # Error Responses
1045
+ #
1046
+ # 404 - Recording not found
1047
+ def recordings_stop(recording_name)
1048
+ post "recordings/live/#{recording_name}/stop"
1049
+ end
1050
+
1051
+ # POST
1052
+ # /recordings/live/:recordingName/pause
1053
+ # void
1054
+ # Pause a live recording.
1055
+ #
1056
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
1057
+ #
1058
+ # @param [String] recording_name The name of the recording
1059
+ #
1060
+ # Error Responses
1061
+ #
1062
+ # 404 - Recording not found
1063
+ # 409 - Recording not in session
1064
+ def recordings_pause(recording_name)
1065
+ post "recordings/live/#{recording_name}/pause"
1066
+ end
1067
+
1068
+ # DELETE
1069
+ # /recordings/live/:recordingName/pause
1070
+ # void
1071
+ # Unpause a live recording.
1072
+ #
1073
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
1074
+ #
1075
+ # @param [String] recording_name The name of the recording
1076
+ #
1077
+ # Error Responses
1078
+ #
1079
+ # 404 - Recording not found
1080
+ # 409 - Recording not in session
1081
+ def recordings_unpause(recording_name)
1082
+ delete "recordings/live/#{recording_name}/pause"
1083
+ end
1084
+
1085
+ # POST
1086
+ # /recordings/live/:recordingName/mute
1087
+ # void
1088
+ # Mute a live recording.
1089
+ #
1090
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
1091
+ #
1092
+ # @param [String] recording_name The name of the recording
1093
+ #
1094
+ # Error Responses
1095
+ #
1096
+ # 404 - Recording not found
1097
+ # 409 - Recording not in session
1098
+ def recordings_mute(recording_name)
1099
+ post "recordings/live/#{recording_name}/mute"
1100
+ end
1101
+
1102
+ # DELETE
1103
+ # /recordings/live/:recordingName/mute
1104
+ # void
1105
+ # Unmute a live recording.
1106
+ #
1107
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
1108
+ #
1109
+ # @param [String] recording_name The name of the recording
1110
+ #
1111
+ # Error Responses
1112
+ #
1113
+ # 404 - Recording not found
1114
+ # 409 - Recording not in session
1115
+ def recordings_unmute(recording_name)
1116
+ delete "recordings/live/#{recording_name}/mute"
1117
+ end
1118
+
1119
+ # Sounds REST API
1120
+
1121
+ # GET
1122
+ # /sounds
1123
+ # List[Sound]
1124
+ # List all sounds.
1125
+ #
1126
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
1127
+ #
1128
+ # @param [Hash] params
1129
+ # @option param [String] lang Lookup sound for a specific language.
1130
+ # @option param [String] format Lookup sound in a specific format.
1131
+ def sounds_list(params = {})
1132
+ get "sounds", params
1133
+ end
1134
+
1135
+ # GET
1136
+ # /sounds/:soundId
1137
+ # Sound
1138
+ # Get a sound's details.
1139
+ #
1140
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
1141
+ #
1142
+ # @param [String] sound_id Sound's id
1143
+ def sounds_get(sound_id)
1144
+ get "sounds/#{sound_id}"
1145
+ end
1146
+
1147
+ # Applications REST API
1148
+
1149
+ # GET
1150
+ # /applications
1151
+ # List[Application]
1152
+ # List all applications.
1153
+ #
1154
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
1155
+ def applications_list
1156
+ get "applications"
1157
+ end
1158
+
1159
+ # GET
1160
+ # /applications/:applicationName
1161
+ # Application
1162
+ # Get details of an application.
1163
+ #
1164
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
1165
+ #
1166
+ # @param [String] application_name Application's name
1167
+ #
1168
+ # Error Responses
1169
+ #
1170
+ # 404 - Application does not exist.
1171
+ def applications_get(application_name)
1172
+ get "applications/#{application_name}"
1173
+ end
1174
+
1175
+ # POST
1176
+ # /applications/:applicationName/subscription
1177
+ # Application
1178
+ # Subscribe an application to a event source.
1179
+ #
1180
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
1181
+ #
1182
+ # @param [String] application_name Application's name
1183
+ # @param [Hash] params
1184
+ # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
1185
+ #
1186
+ # Error Responses
1187
+ #
1188
+ # 400 - Missing parameter.
1189
+ # 404 - Application does not exist.
1190
+ # 422 - Event source does not exist.
1191
+ def applications_subscribe(application_name, params = {})
1192
+ post "applications/#{application_name}/subscription", params
1193
+ end
1194
+
1195
+ # DELETE
1196
+ # /applications/:applicationName/subscription
1197
+ # Application
1198
+ # Unsubscribe an application from an event source.
1199
+ #
1200
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
1201
+ #
1202
+ # @param [String] application_name Application's name
1203
+ # @param [Hash] params
1204
+ # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
1205
+ #
1206
+ # Error Responses
1207
+ #
1208
+ # 400 - Missing parameter.
1209
+ # 404 - Application does not exist.
1210
+ # 409 - Application not subscribed to event source.
1211
+ # 422 - Event source does not exist.
1212
+ def applications_unsubscribe(application_name, params = {})
1213
+ delete "applications/#{application_name}/subscription", params
1214
+ end
1215
+
1216
+ # Playbacks REST API
1217
+
1218
+ # GET
1219
+ # /playbacks/:playbackId
1220
+ # Playback
1221
+ # Get a playback's details.
1222
+ #
1223
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
1224
+ #
1225
+ # @param [String] playback_id Playback's id
1226
+ #
1227
+ # Error Responses
1228
+ #
1229
+ # 404 - The playback cannot be found
1230
+ def playbacks_get(playback_id)
1231
+ get "playbacks/#{playback_id}"
1232
+ end
1233
+
1234
+ # DELETE
1235
+ # /playbacks/:playbackId
1236
+ # void
1237
+ # Stop a playback.
1238
+ #
1239
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
1240
+ #
1241
+ # @param [String] playback_id Playback's id
1242
+ #
1243
+ # Error Responses
1244
+ #
1245
+ # 404 - The playback cannot be found
1246
+ def playbacks_stop(playback_id)
1247
+ delete "playbacks/#{playback_id}"
1248
+ end
1249
+
1250
+ # POST
1251
+ # /playbacks/:playbackId/control
1252
+ # void
1253
+ # Control a playback.
1254
+ #
1255
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
1256
+ #
1257
+ # @param [String] playback_id Playback's id
1258
+ # @param [Hash] params
1259
+ # @option params [String] :operation *required Operation to perform on the playback.
1260
+ #
1261
+ # Error Responses
1262
+ #
1263
+ # 400 - The provided operation parameter was invalid
1264
+ # 404 - The playback cannot be found
1265
+ # 409 - The operation cannot be performed in the playback's current state
1266
+ def playbacks_control(playback_id, params = {})
1267
+ post "playbacks/#{playback_id}/control", params
1268
+ end
1269
+
1270
+ # Devicestates REST API
1271
+
1272
+ # GET
1273
+ # /deviceStates
1274
+ # List[DeviceState]
1275
+ # List all ARI controlled device states.
1276
+ #
1277
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
1278
+ def device_states_list
1279
+ get "deviceStates"
1280
+ end
1281
+
1282
+ # GET
1283
+ # /deviceStates/:deviceName
1284
+ # DeviceState
1285
+ # Retrieve the current state of a device.
1286
+ #
1287
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
1288
+ #
1289
+ # @param [String] device_name Name of the device
1290
+ def device_states_get(device_name)
1291
+ get "deviceStates/#{device_name}"
1292
+ end
1293
+
1294
+ # PUT
1295
+ # /deviceStates/:deviceName
1296
+ # void
1297
+ # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
1298
+ #
1299
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
1300
+ #
1301
+ # @param [String] device_name Name of the device
1302
+ # @param [Hash] params
1303
+ # @option params [String] :deviceState *required Device state value
1304
+ #
1305
+ # Error Responses
1306
+ #
1307
+ # 404 - Device name is missing
1308
+ # 409 - Uncontrolled device specified
1309
+ def device_states_update(device_name, params = {})
1310
+ put "deviceStates/#{device_name}", params
1311
+ end
1312
+
1313
+ # DELETE
1314
+ # /deviceStates/:deviceName
1315
+ # void
1316
+ # Destroy a device-state controlled by ARI.
1317
+ #
1318
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
1319
+ #
1320
+ # @param [String] device_name Name of the device
1321
+ #
1322
+ # Error Responses
1323
+ #
1324
+ # 404 - Device name is missing
1325
+ # 409 - Uncontrolled device specified
1326
+ def device_states_delete(device_name)
1327
+ delete "deviceStates/#{device_name}"
1328
+ end
1329
+
1330
+ # Mailboxes REST API
1331
+
1332
+ # GET
1333
+ # /mailboxes
1334
+ # List[Mailbox]
1335
+ # List all mailboxes.
1336
+ #
1337
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
1338
+ def mailboxes_list
1339
+ get "mailboxes"
1340
+ end
1341
+
1342
+ # GET
1343
+ # /mailboxes/:mailboxName
1344
+ # Mailbox
1345
+ # Retrieve the current state of a mailbox.
1346
+ #
1347
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
1348
+ #
1349
+ # @param [String] mailbox_name Name of the mailbox
1350
+ #
1351
+ # Error Responses
1352
+ #
1353
+ # 404 - Mailbox not found
1354
+ def mailboxes_get(mailbox_name)
1355
+ get "mailboxes/#{mailbox_name}"
1356
+ end
1357
+
1358
+ # PUT
1359
+ # /mailboxes/:mailboxName
1360
+ # void
1361
+ # Change the state of a mailbox. (Note - implicitly creates the mailbox).
1362
+ #
1363
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
1364
+ #
1365
+ # @param [String] mailbox_name Name of the mailbox
1366
+ # @param [Hash] params
1367
+ # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
1368
+ # @option params [Integer] :newMessages *required Count of new messages in the mailbox
1369
+ #
1370
+ # Error Responses
1371
+ #
1372
+ # 404 - Mailbox not found
1373
+ def mailboxes_update(mailbox_name, params = {})
1374
+ put "mailboxes/#{mailbox_name}", params
1375
+ end
1376
+
1377
+ # DELETE
1378
+ # /mailboxes/:mailboxName
1379
+ # void
1380
+ # Destroy a mailbox.
1381
+ #
1382
+ # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
1383
+ #
1384
+ # @param [String] mailbox_name Name of the mailbox
1385
+ #
1386
+ # Error Responses
1387
+ #
1388
+ # 404 - Mailbox not found
1389
+ def mailboxes_delete(mailbox_name)
1390
+ delete "mailboxes/#{mailbox_name}"
1391
+ end
1392
+
1393
+ private
1394
+
1395
+ def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
1396
+ # Setup args for make_request
1397
+ path = "/ari/#{path}" unless path =~ /^\//
1398
+ path = "/#{@prefix}#{path}" if @prefix
1399
+
1400
+ options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
1401
+ # Make request via the provided service
1402
+ result = ARI.make_request path, args, verb, options
1403
+
1404
+ if result.status >= 500
1405
+ error_detail = {
1406
+ :http_status => result.status.to_i,
1407
+ :body => result.body
1408
+ }
1409
+ raise ARI::ServerError.new(result.body, error_detail)
1410
+ elsif result.status >= 400
1411
+ error_detail = {
1412
+ :http_status => result.status.to_i,
1413
+ :body => result.body,
1414
+ :data => ARI::JSON.load(result.body)
1415
+ }
1416
+ raise ARI::APIError.new(result.body, error_detail)
1417
+ end
1418
+
1419
+ # Parse the body
1420
+ body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
1421
+ ARI::JSON.load result.body.to_s
1422
+ else
1423
+ result.body.to_s
1424
+ end
1425
+ # Return result
1426
+ if options[:http_component]
1427
+ result.send options[:http_component]
1428
+ else
1429
+ body
1430
+ end
1431
+ end
1432
+
1433
+ end
1434
+
1435
+ def self.http_service=(service)
1436
+ self.send :include, service
1437
+ end
1438
+
1439
+ ARI.http_service = NetHTTPService
1440
+
1441
+ end