asterisk-ari-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +85 -0
  6. data/Rakefile +54 -0
  7. data/asterisk-ari-client.gemspec +32 -0
  8. data/examples/list_channels.rb +14 -0
  9. data/examples/websocket.rb +33 -0
  10. data/lib/ari.rb +12 -0
  11. data/lib/ari/client.rb +124 -0
  12. data/lib/ari/generators/api.rb +23 -0
  13. data/lib/ari/generators/attribute.rb +35 -0
  14. data/lib/ari/generators/model.rb +38 -0
  15. data/lib/ari/generators/operation.rb +43 -0
  16. data/lib/ari/generators/parameter.rb +35 -0
  17. data/lib/ari/generators/property.rb +32 -0
  18. data/lib/ari/generators/resource_generator.rb +94 -0
  19. data/lib/ari/generators/templates/model.rb.erb +36 -0
  20. data/lib/ari/generators/templates/resource.rb.erb +97 -0
  21. data/lib/ari/list_resource.rb +23 -0
  22. data/lib/ari/model.rb +26 -0
  23. data/lib/ari/models.rb +47 -0
  24. data/lib/ari/models/.DS_Store +0 -0
  25. data/lib/ari/models/application_replaced.rb +17 -0
  26. data/lib/ari/models/asterisk_info.rb +35 -0
  27. data/lib/ari/models/bridge_attended_transfer.rb +63 -0
  28. data/lib/ari/models/bridge_blind_transfer.rb +35 -0
  29. data/lib/ari/models/bridge_created.rb +23 -0
  30. data/lib/ari/models/bridge_destroyed.rb +23 -0
  31. data/lib/ari/models/bridge_merged.rb +27 -0
  32. data/lib/ari/models/build_info.rb +19 -0
  33. data/lib/ari/models/caller_id.rb +19 -0
  34. data/lib/ari/models/channel_caller_id.rb +23 -0
  35. data/lib/ari/models/channel_created.rb +23 -0
  36. data/lib/ari/models/channel_destroyed.rb +23 -0
  37. data/lib/ari/models/channel_dialplan.rb +23 -0
  38. data/lib/ari/models/channel_dtmf_received.rb +23 -0
  39. data/lib/ari/models/channel_entered_bridge.rb +27 -0
  40. data/lib/ari/models/channel_hangup_request.rb +23 -0
  41. data/lib/ari/models/channel_left_bridge.rb +27 -0
  42. data/lib/ari/models/channel_state_change.rb +23 -0
  43. data/lib/ari/models/channel_talking_finished.rb +23 -0
  44. data/lib/ari/models/channel_talking_started.rb +23 -0
  45. data/lib/ari/models/channel_userevent.rb +35 -0
  46. data/lib/ari/models/channel_varset.rb +23 -0
  47. data/lib/ari/models/config_info.rb +27 -0
  48. data/lib/ari/models/device_state_changed.rb +23 -0
  49. data/lib/ari/models/dial.rb +31 -0
  50. data/lib/ari/models/dialed.rb +17 -0
  51. data/lib/ari/models/dialplan_cep.rb +19 -0
  52. data/lib/ari/models/endpoint_state_change.rb +23 -0
  53. data/lib/ari/models/format_lang_pair.rb +19 -0
  54. data/lib/ari/models/live_recording.rb +19 -0
  55. data/lib/ari/models/message.rb +19 -0
  56. data/lib/ari/models/missing_params.rb +19 -0
  57. data/lib/ari/models/playback_finished.rb +23 -0
  58. data/lib/ari/models/playback_started.rb +23 -0
  59. data/lib/ari/models/recording_failed.rb +23 -0
  60. data/lib/ari/models/recording_finished.rb +23 -0
  61. data/lib/ari/models/recording_started.rb +23 -0
  62. data/lib/ari/models/set_id.rb +19 -0
  63. data/lib/ari/models/stasis_end.rb +23 -0
  64. data/lib/ari/models/stasis_start.rb +27 -0
  65. data/lib/ari/models/status_info.rb +27 -0
  66. data/lib/ari/models/stored_recording.rb +19 -0
  67. data/lib/ari/models/system_info.rb +19 -0
  68. data/lib/ari/models/text_message.rb +23 -0
  69. data/lib/ari/models/text_message_received.rb +27 -0
  70. data/lib/ari/models/text_message_variable.rb +19 -0
  71. data/lib/ari/models/variable.rb +19 -0
  72. data/lib/ari/request_error.rb +8 -0
  73. data/lib/ari/resource.rb +37 -0
  74. data/lib/ari/resources.rb +11 -0
  75. data/lib/ari/resources/application.rb +101 -0
  76. data/lib/ari/resources/asterisk.rb +72 -0
  77. data/lib/ari/resources/bridge.rb +286 -0
  78. data/lib/ari/resources/channel.rb +610 -0
  79. data/lib/ari/resources/device_state.rb +98 -0
  80. data/lib/ari/resources/endpoint.rb +124 -0
  81. data/lib/ari/resources/event.rb +25 -0
  82. data/lib/ari/resources/mailbox.rb +99 -0
  83. data/lib/ari/resources/playback.rb +86 -0
  84. data/lib/ari/resources/recording.rb +241 -0
  85. data/lib/ari/resources/sound.rb +64 -0
  86. data/lib/ari/server_error.rb +8 -0
  87. data/lib/asterisk/ari/client.rb +10 -0
  88. data/lib/asterisk/ari/client/version.rb +7 -0
  89. data/test/fixtures/bridge_create.json +74 -0
  90. data/test/fixtures/bridge_get.json +74 -0
  91. data/test/fixtures/bridges_list.json +76 -0
  92. data/test/fixtures/channel_get.json +83 -0
  93. data/test/fixtures/channel_originate.json +83 -0
  94. data/test/fixtures/channel_originate_with_id.json +83 -0
  95. data/test/fixtures/channels_list.json +105 -0
  96. data/test/lib/asterisk-ari-client/.DS_Store +0 -0
  97. data/test/lib/asterisk-ari-client/bridge_test.rb +46 -0
  98. data/test/lib/asterisk-ari-client/channel_test.rb +59 -0
  99. data/test/test_helper.rb +42 -0
  100. metadata +265 -0
@@ -0,0 +1,72 @@
1
+ #------------------------------------------------------------------------------
2
+ #
3
+ # WARNING !
4
+ #
5
+ # This is a generated file. DO NOT EDIT THIS FILE! Your changes will
6
+ # be lost the next time this file is regenerated.
7
+ #
8
+ # This file was generated using asterisk-ari-client ruby gem.
9
+ #
10
+ #------------------------------------------------------------------------------
11
+
12
+ module Ari
13
+ class Asterisk < Resource
14
+
15
+
16
+ # GET /asterisk/info
17
+ #
18
+ # Asterisk system information (similar to core show settings)
19
+ #
20
+ #
21
+ # Parameters:
22
+ #
23
+ # only - Filter information returned
24
+ #
25
+ def self.get_info(options = {})
26
+ path = '/asterisk/info'
27
+ response = client(options).get(path, options)
28
+ AsteriskInfo.new(response.merge(client: options[:client]))
29
+ end
30
+ class << self; alias_method :getInfo, :get_info; end
31
+
32
+ # GET /asterisk/variable
33
+ #
34
+ # Global variables
35
+ #
36
+ #
37
+ # Parameters:
38
+ #
39
+ # variable (required) - The variable to get
40
+ #
41
+ def self.get_global_var(options = {})
42
+ raise ArgumentError.new("Parameter variable must be passed in options hash.") unless options[:variable]
43
+ path = '/asterisk/variable'
44
+ response = client(options).get(path, options)
45
+ Variable.new(response.merge(client: options[:client]))
46
+ end
47
+ class << self; alias_method :getGlobalVar, :get_global_var; end
48
+
49
+ # POST /asterisk/variable
50
+ #
51
+ # Global variables
52
+ #
53
+ #
54
+ # Parameters:
55
+ #
56
+ # variable (required) - The variable to set
57
+ # value - The value to set the variable to
58
+ #
59
+ def self.set_global_var(options = {})
60
+ raise ArgumentError.new("Parameter variable must be passed in options hash.") unless options[:variable]
61
+ path = '/asterisk/variable'
62
+ response = client(options).post(path, options)
63
+ end
64
+ class << self; alias_method :setGlobalVar, :set_global_var; end
65
+
66
+
67
+ end
68
+ end
69
+
70
+ Ari::Client.send :define_method, 'asterisk' do
71
+ Ari::ListResource.new(self, Ari::Asterisk)
72
+ end
@@ -0,0 +1,286 @@
1
+ #------------------------------------------------------------------------------
2
+ #
3
+ # WARNING !
4
+ #
5
+ # This is a generated file. DO NOT EDIT THIS FILE! Your changes will
6
+ # be lost the next time this file is regenerated.
7
+ #
8
+ # This file was generated using asterisk-ari-client ruby gem.
9
+ #
10
+ #------------------------------------------------------------------------------
11
+
12
+ module Ari
13
+ class Bridge < Resource
14
+
15
+ attr_reader :id, :technology, :bridge_type, :bridge_class, :creator, :name, :channels
16
+
17
+
18
+ # GET /bridges
19
+ #
20
+ # Active bridges
21
+ #
22
+ #
23
+ def self.list(options = {})
24
+ path = '/bridges'
25
+ response = client(options).get(path, options)
26
+ response.map { |hash| Bridge.new(hash.merge(client: options[:client])) }
27
+ end
28
+
29
+ # POST /bridges
30
+ #
31
+ # Active bridges
32
+ #
33
+ #
34
+ # Parameters:
35
+ #
36
+ # type - Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
37
+ # bridgeId - Unique ID to give to the bridge being created.
38
+ # name - Name to give to the bridge being created.
39
+ #
40
+ def self.create(options = {})
41
+ path = '/bridges'
42
+ response = client(options).post(path, options)
43
+ Bridge.new(response.merge(client: options[:client]))
44
+ end
45
+
46
+ # POST /bridges/%{bridgeId}
47
+ #
48
+ # Individual bridge
49
+ #
50
+ #
51
+ # Parameters:
52
+ #
53
+ # type - Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
54
+ # bridgeId (required) - Unique ID to give to the bridge being created.
55
+ # name - Set the name of the bridge.
56
+ #
57
+ def self.create_or_update_with_id(options = {})
58
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
59
+ path = '/bridges/%{bridgeId}' % options
60
+ response = client(options).post(path, options)
61
+ Bridge.new(response.merge(client: options[:client]))
62
+ end
63
+
64
+ def create_or_update_with_id(options = {})
65
+ self.class.create_or_update_with_id(options.merge(bridgeId: self.id, client: @client))
66
+ end
67
+
68
+ # GET /bridges/%{bridgeId}
69
+ #
70
+ # Individual bridge
71
+ #
72
+ #
73
+ # Parameters:
74
+ #
75
+ # bridgeId (required) - Bridge's id
76
+ #
77
+ def self.get(options = {})
78
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
79
+ path = '/bridges/%{bridgeId}' % options
80
+ response = client(options).get(path, options)
81
+ Bridge.new(response.merge(client: options[:client]))
82
+ end
83
+
84
+ def get(options = {})
85
+ self.class.get(options.merge(bridgeId: self.id, client: @client))
86
+ end
87
+
88
+ # DELETE /bridges/%{bridgeId}
89
+ #
90
+ # Individual bridge
91
+ #
92
+ #
93
+ # Parameters:
94
+ #
95
+ # bridgeId (required) - Bridge's id
96
+ #
97
+ def self.destroy(options = {})
98
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
99
+ path = '/bridges/%{bridgeId}' % options
100
+ response = client(options).delete(path, options)
101
+ rescue Ari::RequestError => e
102
+ raise unless e.code == '404'
103
+ end
104
+
105
+ def destroy(options = {})
106
+ self.class.destroy(options.merge(bridgeId: self.id, client: @client))
107
+ end
108
+
109
+ # POST /bridges/%{bridgeId}/addChannel
110
+ #
111
+ # Add a channel to a bridge
112
+ #
113
+ #
114
+ # Parameters:
115
+ #
116
+ # bridgeId (required) - Bridge's id
117
+ # channel (required) - Ids of channels to add to bridge
118
+ # role - Channel's role in the bridge
119
+ #
120
+ def self.add_channel(options = {})
121
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
122
+ raise ArgumentError.new("Parameter channel must be passed in options hash.") unless options[:channel]
123
+ path = '/bridges/%{bridgeId}/addChannel' % options
124
+ response = client(options).post(path, options)
125
+ end
126
+ class << self; alias_method :addChannel, :add_channel; end
127
+
128
+ def add_channel(options = {})
129
+ self.class.add_channel(options.merge(bridgeId: self.id, client: @client))
130
+ end
131
+
132
+ # POST /bridges/%{bridgeId}/removeChannel
133
+ #
134
+ # Remove a channel from a bridge
135
+ #
136
+ #
137
+ # Parameters:
138
+ #
139
+ # bridgeId (required) - Bridge's id
140
+ # channel (required) - Ids of channels to remove from bridge
141
+ #
142
+ def self.remove_channel(options = {})
143
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
144
+ raise ArgumentError.new("Parameter channel must be passed in options hash.") unless options[:channel]
145
+ path = '/bridges/%{bridgeId}/removeChannel' % options
146
+ response = client(options).post(path, options)
147
+ end
148
+ class << self; alias_method :removeChannel, :remove_channel; end
149
+
150
+ def remove_channel(options = {})
151
+ self.class.remove_channel(options.merge(bridgeId: self.id, client: @client))
152
+ end
153
+
154
+ # POST /bridges/%{bridgeId}/moh
155
+ #
156
+ # Play music on hold to a bridge
157
+ #
158
+ #
159
+ # Parameters:
160
+ #
161
+ # bridgeId (required) - Bridge's id
162
+ # mohClass - Channel's id
163
+ #
164
+ def self.start_moh(options = {})
165
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
166
+ path = '/bridges/%{bridgeId}/moh' % options
167
+ response = client(options).post(path, options)
168
+ end
169
+ class << self; alias_method :startMoh, :start_moh; end
170
+
171
+ def start_moh(options = {})
172
+ self.class.start_moh(options.merge(bridgeId: self.id, client: @client))
173
+ end
174
+
175
+ # DELETE /bridges/%{bridgeId}/moh
176
+ #
177
+ # Play music on hold to a bridge
178
+ #
179
+ #
180
+ # Parameters:
181
+ #
182
+ # bridgeId (required) - Bridge's id
183
+ #
184
+ def self.stop_moh(options = {})
185
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
186
+ path = '/bridges/%{bridgeId}/moh' % options
187
+ response = client(options).delete(path, options)
188
+ rescue Ari::RequestError => e
189
+ raise unless e.code == '404'
190
+ end
191
+ class << self; alias_method :stopMoh, :stop_moh; end
192
+
193
+ def stop_moh(options = {})
194
+ self.class.stop_moh(options.merge(bridgeId: self.id, client: @client))
195
+ end
196
+
197
+ # POST /bridges/%{bridgeId}/play
198
+ #
199
+ # Play media to the participants of a bridge
200
+ #
201
+ #
202
+ # Parameters:
203
+ #
204
+ # bridgeId (required) - Bridge's id
205
+ # media (required) - Media's URI to play.
206
+ # lang - For sounds, selects language for sound.
207
+ # offsetms - Number of media to skip before playing.
208
+ # skipms - Number of milliseconds to skip for forward/reverse operations.
209
+ # playbackId - Playback Id.
210
+ #
211
+ def self.play(options = {})
212
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
213
+ raise ArgumentError.new("Parameter media must be passed in options hash.") unless options[:media]
214
+ path = '/bridges/%{bridgeId}/play' % options
215
+ response = client(options).post(path, options)
216
+ Playback.new(response.merge(client: options[:client]))
217
+ end
218
+
219
+ def play(options = {})
220
+ self.class.play(options.merge(bridgeId: self.id, client: @client))
221
+ end
222
+
223
+ # POST /bridges/%{bridgeId}/play/%{playbackId}
224
+ #
225
+ # Play media to a bridge
226
+ #
227
+ #
228
+ # Parameters:
229
+ #
230
+ # bridgeId (required) - Bridge's id
231
+ # playbackId (required) - Playback ID.
232
+ # media (required) - Media's URI to play.
233
+ # lang - For sounds, selects language for sound.
234
+ # offsetms - Number of media to skip before playing.
235
+ # skipms - Number of milliseconds to skip for forward/reverse operations.
236
+ #
237
+ def self.play_with_id(options = {})
238
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
239
+ raise ArgumentError.new("Parameter playbackId must be passed in options hash.") unless options[:playbackId]
240
+ raise ArgumentError.new("Parameter media must be passed in options hash.") unless options[:media]
241
+ path = '/bridges/%{bridgeId}/play/%{playbackId}' % options
242
+ response = client(options).post(path, options)
243
+ Playback.new(response.merge(client: options[:client]))
244
+ end
245
+ class << self; alias_method :playWithId, :play_with_id; end
246
+
247
+ def play_with_id(options = {})
248
+ self.class.play_with_id(options.merge(bridgeId: self.id, client: @client))
249
+ end
250
+
251
+ # POST /bridges/%{bridgeId}/record
252
+ #
253
+ # Record audio on a bridge
254
+ #
255
+ #
256
+ # Parameters:
257
+ #
258
+ # bridgeId (required) - Bridge's id
259
+ # name (required) - Recording's filename
260
+ # format (required) - Format to encode audio in
261
+ # maxDurationSeconds - Maximum duration of the recording, in seconds. 0 for no limit.
262
+ # maxSilenceSeconds - Maximum duration of silence, in seconds. 0 for no limit.
263
+ # ifExists - Action to take if a recording with the same name already exists.
264
+ # beep - Play beep when recording begins
265
+ # terminateOn - DTMF input to terminate recording.
266
+ #
267
+ def self.record(options = {})
268
+ raise ArgumentError.new("Parameter bridgeId must be passed in options hash.") unless options[:bridgeId]
269
+ raise ArgumentError.new("Parameter name must be passed in options hash.") unless options[:name]
270
+ raise ArgumentError.new("Parameter format must be passed in options hash.") unless options[:format]
271
+ path = '/bridges/%{bridgeId}/record' % options
272
+ response = client(options).post(path, options)
273
+ LiveRecording.new(response.merge(client: options[:client]))
274
+ end
275
+
276
+ def record(options = {})
277
+ self.class.record(options.merge(bridgeId: self.id, client: @client))
278
+ end
279
+
280
+
281
+ end
282
+ end
283
+
284
+ Ari::Client.send :define_method, 'bridges' do
285
+ Ari::ListResource.new(self, Ari::Bridge)
286
+ end
@@ -0,0 +1,610 @@
1
+ #------------------------------------------------------------------------------
2
+ #
3
+ # WARNING !
4
+ #
5
+ # This is a generated file. DO NOT EDIT THIS FILE! Your changes will
6
+ # be lost the next time this file is regenerated.
7
+ #
8
+ # This file was generated using asterisk-ari-client ruby gem.
9
+ #
10
+ #------------------------------------------------------------------------------
11
+
12
+ module Ari
13
+ class Channel < Resource
14
+
15
+ attr_reader :id, :name, :state, :caller, :connected, :accountcode, :dialplan, :creationtime
16
+
17
+ def caller=(val)
18
+ @caller ||= CallerID.new(val)
19
+ end
20
+
21
+ def connected=(val)
22
+ @connected ||= CallerID.new(val)
23
+ end
24
+
25
+ def dialplan=(val)
26
+ @dialplan ||= DialplanCEP.new(val)
27
+ end
28
+
29
+ def creationtime=(val)
30
+ @creationtime ||= Time.parse(val)
31
+ end
32
+
33
+
34
+ # GET /channels
35
+ #
36
+ # Active channels
37
+ #
38
+ #
39
+ def self.list(options = {})
40
+ path = '/channels'
41
+ response = client(options).get(path, options)
42
+ response.map { |hash| Channel.new(hash.merge(client: options[:client])) }
43
+ end
44
+
45
+ # POST /channels
46
+ #
47
+ # Active channels
48
+ #
49
+ #
50
+ # Parameters:
51
+ #
52
+ # endpoint (required) - Endpoint to call.
53
+ # extension - The extension to dial after the endpoint answers
54
+ # context - The context to dial after the endpoint answers. If omitted, uses 'default'
55
+ # priority - The priority to dial after the endpoint answers. If omitted, uses 1
56
+ # app - The application that is subscribed to the originated channel, and passed to the Stasis application.
57
+ # appArgs - The application arguments to pass to the Stasis application.
58
+ # callerId - CallerID to use when dialing the endpoint or extension.
59
+ # timeout - Timeout (in seconds) before giving up dialing, or -1 for no timeout.
60
+ # variables - 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" } }
61
+ # channelId - The unique id to assign the channel on creation.
62
+ # otherChannelId - The unique id to assign the second channel when using local channels.
63
+ #
64
+ def self.originate(options = {})
65
+ raise ArgumentError.new("Parameter endpoint must be passed in options hash.") unless options[:endpoint]
66
+ path = '/channels'
67
+ response = client(options).post(path, options)
68
+ Channel.new(response.merge(client: options[:client]))
69
+ end
70
+
71
+ # GET /channels/%{channelId}
72
+ #
73
+ # Active channel
74
+ #
75
+ #
76
+ # Parameters:
77
+ #
78
+ # channelId (required) - Channel's id
79
+ #
80
+ def self.get(options = {})
81
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
82
+ path = '/channels/%{channelId}' % options
83
+ response = client(options).get(path, options)
84
+ Channel.new(response.merge(client: options[:client]))
85
+ end
86
+
87
+ def get(options = {})
88
+ self.class.get(options.merge(channelId: self.id, client: @client))
89
+ end
90
+
91
+ # POST /channels/%{channelId}
92
+ #
93
+ # Active channel
94
+ #
95
+ #
96
+ # Parameters:
97
+ #
98
+ # channelId (required) - The unique id to assign the channel on creation.
99
+ # endpoint (required) - Endpoint to call.
100
+ # extension - The extension to dial after the endpoint answers
101
+ # context - The context to dial after the endpoint answers. If omitted, uses 'default'
102
+ # priority - The priority to dial after the endpoint answers. If omitted, uses 1
103
+ # app - The application that is subscribed to the originated channel, and passed to the Stasis application.
104
+ # appArgs - The application arguments to pass to the Stasis application.
105
+ # callerId - CallerID to use when dialing the endpoint or extension.
106
+ # timeout - Timeout (in seconds) before giving up dialing, or -1 for no timeout.
107
+ # variables - 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" } }
108
+ # otherChannelId - The unique id to assign the second channel when using local channels.
109
+ #
110
+ def self.originate_with_id(options = {})
111
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
112
+ raise ArgumentError.new("Parameter endpoint must be passed in options hash.") unless options[:endpoint]
113
+ path = '/channels/%{channelId}' % options
114
+ response = client(options).post(path, options)
115
+ Channel.new(response.merge(client: options[:client]))
116
+ end
117
+ class << self; alias_method :originateWithId, :originate_with_id; end
118
+
119
+ def originate_with_id(options = {})
120
+ self.class.originate_with_id(options.merge(channelId: self.id, client: @client))
121
+ end
122
+
123
+ # DELETE /channels/%{channelId}
124
+ #
125
+ # Active channel
126
+ #
127
+ #
128
+ # Parameters:
129
+ #
130
+ # channelId (required) - Channel's id
131
+ # reason - Reason for hanging up the channel
132
+ #
133
+ def self.hangup(options = {})
134
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
135
+ path = '/channels/%{channelId}' % options
136
+ response = client(options).delete(path, options)
137
+ rescue Ari::RequestError => e
138
+ raise unless e.code == '404'
139
+ end
140
+
141
+ def hangup(options = {})
142
+ self.class.hangup(options.merge(channelId: self.id, client: @client))
143
+ end
144
+
145
+ # POST /channels/%{channelId}/continue
146
+ #
147
+ # Exit application; continue execution in the dialplan
148
+ #
149
+ #
150
+ # Parameters:
151
+ #
152
+ # channelId (required) - Channel's id
153
+ # context - The context to continue to.
154
+ # extension - The extension to continue to.
155
+ # priority - The priority to continue to.
156
+ #
157
+ def self.continue_in_dialplan(options = {})
158
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
159
+ path = '/channels/%{channelId}/continue' % options
160
+ response = client(options).post(path, options)
161
+ end
162
+ class << self; alias_method :continueInDialplan, :continue_in_dialplan; end
163
+
164
+ def continue_in_dialplan(options = {})
165
+ self.class.continue_in_dialplan(options.merge(channelId: self.id, client: @client))
166
+ end
167
+
168
+ # POST /channels/%{channelId}/answer
169
+ #
170
+ # Answer a channel
171
+ #
172
+ #
173
+ # Parameters:
174
+ #
175
+ # channelId (required) - Channel's id
176
+ #
177
+ def self.answer(options = {})
178
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
179
+ path = '/channels/%{channelId}/answer' % options
180
+ response = client(options).post(path, options)
181
+ end
182
+
183
+ def answer(options = {})
184
+ self.class.answer(options.merge(channelId: self.id, client: @client))
185
+ end
186
+
187
+ # POST /channels/%{channelId}/ring
188
+ #
189
+ # Send a ringing indication to a channel
190
+ #
191
+ #
192
+ # Parameters:
193
+ #
194
+ # channelId (required) - Channel's id
195
+ #
196
+ def self.ring(options = {})
197
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
198
+ path = '/channels/%{channelId}/ring' % options
199
+ response = client(options).post(path, options)
200
+ end
201
+
202
+ def ring(options = {})
203
+ self.class.ring(options.merge(channelId: self.id, client: @client))
204
+ end
205
+
206
+ # DELETE /channels/%{channelId}/ring
207
+ #
208
+ # Send a ringing indication to a channel
209
+ #
210
+ #
211
+ # Parameters:
212
+ #
213
+ # channelId (required) - Channel's id
214
+ #
215
+ def self.ring_stop(options = {})
216
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
217
+ path = '/channels/%{channelId}/ring' % options
218
+ response = client(options).delete(path, options)
219
+ rescue Ari::RequestError => e
220
+ raise unless e.code == '404'
221
+ end
222
+ class << self; alias_method :ringStop, :ring_stop; end
223
+
224
+ def ring_stop(options = {})
225
+ self.class.ring_stop(options.merge(channelId: self.id, client: @client))
226
+ end
227
+
228
+ # POST /channels/%{channelId}/dtmf
229
+ #
230
+ # Send DTMF to a channel
231
+ #
232
+ #
233
+ # Parameters:
234
+ #
235
+ # channelId (required) - Channel's id
236
+ # dtmf - DTMF To send.
237
+ # before - Amount of time to wait before DTMF digits (specified in milliseconds) start.
238
+ # between - Amount of time in between DTMF digits (specified in milliseconds).
239
+ # duration - Length of each DTMF digit (specified in milliseconds).
240
+ # after - Amount of time to wait after DTMF digits (specified in milliseconds) end.
241
+ #
242
+ def self.send_dtmf(options = {})
243
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
244
+ path = '/channels/%{channelId}/dtmf' % options
245
+ response = client(options).post(path, options)
246
+ end
247
+ class << self; alias_method :sendDTMF, :send_dtmf; end
248
+
249
+ def send_dtmf(options = {})
250
+ self.class.send_dtmf(options.merge(channelId: self.id, client: @client))
251
+ end
252
+
253
+ # POST /channels/%{channelId}/mute
254
+ #
255
+ # Mute a channel
256
+ #
257
+ #
258
+ # Parameters:
259
+ #
260
+ # channelId (required) - Channel's id
261
+ # direction - Direction in which to mute audio
262
+ #
263
+ def self.mute(options = {})
264
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
265
+ path = '/channels/%{channelId}/mute' % options
266
+ response = client(options).post(path, options)
267
+ end
268
+
269
+ def mute(options = {})
270
+ self.class.mute(options.merge(channelId: self.id, client: @client))
271
+ end
272
+
273
+ # DELETE /channels/%{channelId}/mute
274
+ #
275
+ # Mute a channel
276
+ #
277
+ #
278
+ # Parameters:
279
+ #
280
+ # channelId (required) - Channel's id
281
+ # direction - Direction in which to unmute audio
282
+ #
283
+ def self.unmute(options = {})
284
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
285
+ path = '/channels/%{channelId}/mute' % options
286
+ response = client(options).delete(path, options)
287
+ rescue Ari::RequestError => e
288
+ raise unless e.code == '404'
289
+ end
290
+
291
+ def unmute(options = {})
292
+ self.class.unmute(options.merge(channelId: self.id, client: @client))
293
+ end
294
+
295
+ # POST /channels/%{channelId}/hold
296
+ #
297
+ # Put a channel on hold
298
+ #
299
+ #
300
+ # Parameters:
301
+ #
302
+ # channelId (required) - Channel's id
303
+ #
304
+ def self.hold(options = {})
305
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
306
+ path = '/channels/%{channelId}/hold' % options
307
+ response = client(options).post(path, options)
308
+ end
309
+
310
+ def hold(options = {})
311
+ self.class.hold(options.merge(channelId: self.id, client: @client))
312
+ end
313
+
314
+ # DELETE /channels/%{channelId}/hold
315
+ #
316
+ # Put a channel on hold
317
+ #
318
+ #
319
+ # Parameters:
320
+ #
321
+ # channelId (required) - Channel's id
322
+ #
323
+ def self.unhold(options = {})
324
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
325
+ path = '/channels/%{channelId}/hold' % options
326
+ response = client(options).delete(path, options)
327
+ rescue Ari::RequestError => e
328
+ raise unless e.code == '404'
329
+ end
330
+
331
+ def unhold(options = {})
332
+ self.class.unhold(options.merge(channelId: self.id, client: @client))
333
+ end
334
+
335
+ # POST /channels/%{channelId}/moh
336
+ #
337
+ # Play music on hold to a channel
338
+ #
339
+ #
340
+ # Parameters:
341
+ #
342
+ # channelId (required) - Channel's id
343
+ # mohClass - Music on hold class to use
344
+ #
345
+ def self.start_moh(options = {})
346
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
347
+ path = '/channels/%{channelId}/moh' % options
348
+ response = client(options).post(path, options)
349
+ end
350
+ class << self; alias_method :startMoh, :start_moh; end
351
+
352
+ def start_moh(options = {})
353
+ self.class.start_moh(options.merge(channelId: self.id, client: @client))
354
+ end
355
+
356
+ # DELETE /channels/%{channelId}/moh
357
+ #
358
+ # Play music on hold to a channel
359
+ #
360
+ #
361
+ # Parameters:
362
+ #
363
+ # channelId (required) - Channel's id
364
+ #
365
+ def self.stop_moh(options = {})
366
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
367
+ path = '/channels/%{channelId}/moh' % options
368
+ response = client(options).delete(path, options)
369
+ rescue Ari::RequestError => e
370
+ raise unless e.code == '404'
371
+ end
372
+ class << self; alias_method :stopMoh, :stop_moh; end
373
+
374
+ def stop_moh(options = {})
375
+ self.class.stop_moh(options.merge(channelId: self.id, client: @client))
376
+ end
377
+
378
+ # POST /channels/%{channelId}/silence
379
+ #
380
+ # Play silence to a channel
381
+ #
382
+ #
383
+ # Parameters:
384
+ #
385
+ # channelId (required) - Channel's id
386
+ #
387
+ def self.start_silence(options = {})
388
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
389
+ path = '/channels/%{channelId}/silence' % options
390
+ response = client(options).post(path, options)
391
+ end
392
+ class << self; alias_method :startSilence, :start_silence; end
393
+
394
+ def start_silence(options = {})
395
+ self.class.start_silence(options.merge(channelId: self.id, client: @client))
396
+ end
397
+
398
+ # DELETE /channels/%{channelId}/silence
399
+ #
400
+ # Play silence to a channel
401
+ #
402
+ #
403
+ # Parameters:
404
+ #
405
+ # channelId (required) - Channel's id
406
+ #
407
+ def self.stop_silence(options = {})
408
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
409
+ path = '/channels/%{channelId}/silence' % options
410
+ response = client(options).delete(path, options)
411
+ rescue Ari::RequestError => e
412
+ raise unless e.code == '404'
413
+ end
414
+ class << self; alias_method :stopSilence, :stop_silence; end
415
+
416
+ def stop_silence(options = {})
417
+ self.class.stop_silence(options.merge(channelId: self.id, client: @client))
418
+ end
419
+
420
+ # POST /channels/%{channelId}/play
421
+ #
422
+ # Play media to a channel
423
+ #
424
+ #
425
+ # Parameters:
426
+ #
427
+ # channelId (required) - Channel's id
428
+ # media (required) - Media's URI to play.
429
+ # lang - For sounds, selects language for sound.
430
+ # offsetms - Number of media to skip before playing.
431
+ # skipms - Number of milliseconds to skip for forward/reverse operations.
432
+ # playbackId - Playback ID.
433
+ #
434
+ def self.play(options = {})
435
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
436
+ raise ArgumentError.new("Parameter media must be passed in options hash.") unless options[:media]
437
+ path = '/channels/%{channelId}/play' % options
438
+ response = client(options).post(path, options)
439
+ Playback.new(response.merge(client: options[:client]))
440
+ end
441
+
442
+ def play(options = {})
443
+ self.class.play(options.merge(channelId: self.id, client: @client))
444
+ end
445
+
446
+ # POST /channels/%{channelId}/play/%{playbackId}
447
+ #
448
+ # Play media to a channel
449
+ #
450
+ #
451
+ # Parameters:
452
+ #
453
+ # channelId (required) - Channel's id
454
+ # playbackId (required) - Playback ID.
455
+ # media (required) - Media's URI to play.
456
+ # lang - For sounds, selects language for sound.
457
+ # offsetms - Number of media to skip before playing.
458
+ # skipms - Number of milliseconds to skip for forward/reverse operations.
459
+ #
460
+ def self.play_with_id(options = {})
461
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
462
+ raise ArgumentError.new("Parameter playbackId must be passed in options hash.") unless options[:playbackId]
463
+ raise ArgumentError.new("Parameter media must be passed in options hash.") unless options[:media]
464
+ path = '/channels/%{channelId}/play/%{playbackId}' % options
465
+ response = client(options).post(path, options)
466
+ Playback.new(response.merge(client: options[:client]))
467
+ end
468
+ class << self; alias_method :playWithId, :play_with_id; end
469
+
470
+ def play_with_id(options = {})
471
+ self.class.play_with_id(options.merge(channelId: self.id, client: @client))
472
+ end
473
+
474
+ # POST /channels/%{channelId}/record
475
+ #
476
+ # Record audio from a channel
477
+ #
478
+ #
479
+ # Parameters:
480
+ #
481
+ # channelId (required) - Channel's id
482
+ # name (required) - Recording's filename
483
+ # format (required) - Format to encode audio in
484
+ # maxDurationSeconds - Maximum duration of the recording, in seconds. 0 for no limit
485
+ # maxSilenceSeconds - Maximum duration of silence, in seconds. 0 for no limit
486
+ # ifExists - Action to take if a recording with the same name already exists.
487
+ # beep - Play beep when recording begins
488
+ # terminateOn - DTMF input to terminate recording
489
+ #
490
+ def self.record(options = {})
491
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
492
+ raise ArgumentError.new("Parameter name must be passed in options hash.") unless options[:name]
493
+ raise ArgumentError.new("Parameter format must be passed in options hash.") unless options[:format]
494
+ path = '/channels/%{channelId}/record' % options
495
+ response = client(options).post(path, options)
496
+ LiveRecording.new(response.merge(client: options[:client]))
497
+ end
498
+
499
+ def record(options = {})
500
+ self.class.record(options.merge(channelId: self.id, client: @client))
501
+ end
502
+
503
+ # GET /channels/%{channelId}/variable
504
+ #
505
+ # Variables on a channel
506
+ #
507
+ #
508
+ # Parameters:
509
+ #
510
+ # channelId (required) - Channel's id
511
+ # variable (required) - The channel variable or function to get
512
+ #
513
+ def self.get_channel_var(options = {})
514
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
515
+ raise ArgumentError.new("Parameter variable must be passed in options hash.") unless options[:variable]
516
+ path = '/channels/%{channelId}/variable' % options
517
+ response = client(options).get(path, options)
518
+ Variable.new(response.merge(client: options[:client]))
519
+ end
520
+ class << self; alias_method :getChannelVar, :get_channel_var; end
521
+
522
+ def get_channel_var(options = {})
523
+ self.class.get_channel_var(options.merge(channelId: self.id, client: @client))
524
+ end
525
+
526
+ # POST /channels/%{channelId}/variable
527
+ #
528
+ # Variables on a channel
529
+ #
530
+ #
531
+ # Parameters:
532
+ #
533
+ # channelId (required) - Channel's id
534
+ # variable (required) - The channel variable or function to set
535
+ # value - The value to set the variable to
536
+ #
537
+ def self.set_channel_var(options = {})
538
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
539
+ raise ArgumentError.new("Parameter variable must be passed in options hash.") unless options[:variable]
540
+ path = '/channels/%{channelId}/variable' % options
541
+ response = client(options).post(path, options)
542
+ end
543
+ class << self; alias_method :setChannelVar, :set_channel_var; end
544
+
545
+ def set_channel_var(options = {})
546
+ self.class.set_channel_var(options.merge(channelId: self.id, client: @client))
547
+ end
548
+
549
+ # POST /channels/%{channelId}/snoop
550
+ #
551
+ # Snoop (spy/whisper) on a channel
552
+ #
553
+ #
554
+ # Parameters:
555
+ #
556
+ # channelId (required) - Channel's id
557
+ # spy - Direction of audio to spy on
558
+ # whisper - Direction of audio to whisper into
559
+ # app (required) - Application the snooping channel is placed into
560
+ # appArgs - The application arguments to pass to the Stasis application
561
+ # snoopId - Unique ID to assign to snooping channel
562
+ #
563
+ def self.snoop_channel(options = {})
564
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
565
+ raise ArgumentError.new("Parameter app must be passed in options hash.") unless options[:app]
566
+ path = '/channels/%{channelId}/snoop' % options
567
+ response = client(options).post(path, options)
568
+ Channel.new(response.merge(client: options[:client]))
569
+ end
570
+ class << self; alias_method :snoopChannel, :snoop_channel; end
571
+
572
+ def snoop_channel(options = {})
573
+ self.class.snoop_channel(options.merge(channelId: self.id, client: @client))
574
+ end
575
+
576
+ # POST /channels/%{channelId}/snoop/%{snoopId}
577
+ #
578
+ # Snoop (spy/whisper) on a channel
579
+ #
580
+ #
581
+ # Parameters:
582
+ #
583
+ # channelId (required) - Channel's id
584
+ # snoopId (required) - Unique ID to assign to snooping channel
585
+ # spy - Direction of audio to spy on
586
+ # whisper - Direction of audio to whisper into
587
+ # app (required) - Application the snooping channel is placed into
588
+ # appArgs - The application arguments to pass to the Stasis application
589
+ #
590
+ def self.snoop_channel_with_id(options = {})
591
+ raise ArgumentError.new("Parameter channelId must be passed in options hash.") unless options[:channelId]
592
+ raise ArgumentError.new("Parameter snoopId must be passed in options hash.") unless options[:snoopId]
593
+ raise ArgumentError.new("Parameter app must be passed in options hash.") unless options[:app]
594
+ path = '/channels/%{channelId}/snoop/%{snoopId}' % options
595
+ response = client(options).post(path, options)
596
+ Channel.new(response.merge(client: options[:client]))
597
+ end
598
+ class << self; alias_method :snoopChannelWithId, :snoop_channel_with_id; end
599
+
600
+ def snoop_channel_with_id(options = {})
601
+ self.class.snoop_channel_with_id(options.merge(channelId: self.id, client: @client))
602
+ end
603
+
604
+
605
+ end
606
+ end
607
+
608
+ Ari::Client.send :define_method, 'channels' do
609
+ Ari::ListResource.new(self, Ari::Channel)
610
+ end