Class: ARI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ari/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :host (String) — default: "localhost"

    Host name

  • :port (Integer) — default: 8088

    Port number

  • :prefix (String)

    Prefix allows you to specify a prefix for all requests to the server.

  • :username (String)

    username for basic auth

  • :password (String)

    password for basic auth



23
24
25
26
27
28
29
# File 'lib/ari/client.rb', line 23

def initialize(options = {})
  @host     = options[:host] || "localhost"
  @port     = options[:port] || 8088
  @prefix   = options[:prefix] if options[:prefix]
  @username = options[:username] if options[:username]
  @password = options[:password] if options[:password]
end

Instance Attribute Details

#hostString (readonly)

Returns Host name.

Returns:

  • (String)

    Host name



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/ari/client.rb', line 15

class Client

  # @param [Hash] options
  # @option options [String] :host ("localhost") Host name
  # @option options [Integer] :port (8088) Port number
  # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
  # @option options [String] :username username for basic auth
  # @option options [String] :password password for basic auth
  def initialize(options = {})
    @host     = options[:host] || "localhost"
    @port     = options[:port] || 8088
    @prefix   = options[:prefix] if options[:prefix]
    @username = options[:username] if options[:username]
    @password = options[:password] if options[:password]
  end
  attr_reader :host, :port, :prefix, :username, :password

  %w(get post put delete).each do |verb|
    define_method(verb) do |path, params = {}|
      api_call(path, params, verb)
    end
  end

  # Asterisk REST API

  # GET
  # /asterisk/info
  # AsteriskInfo
  # Gets Asterisk system information.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
  #
  # @param [String] only Filter information returned. Allows comma separated values.
  def asterisk_get_info
    get "asterisk/info"
  end

  # GET
  # /asterisk/variable
  # Variable
  # Get the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
  #
  # @param [Hash] params
  # @option params [String] variable *required The variable to get
  #
  # Error Responses
  #
  # return 400 - Missing variable parameter.
  def asterisk_get_global_var(params = {})
    get "asterisk/variable", params
  end

  # POST
  # /asterisk/variable
  # void
  # Set the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
  #
  # @param [Hash] params
  # @option params [String] :variable *required The variable to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  # 400 - Missing variable parameter.
  def asterisk_set_global_var(params = {})
    post "asterisk/variable", params
  end


  # Bridges REST API
  #

  # GET
  # /bridges
  # List[Bridge]
  # List all active bridges in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
  def bridges_list
    get "bridges"
  end

  # POST
  # /bridges
  # Bridge
  # Create a new bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
  #
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
  # @option params [String] :bridgeId Unique ID to give to the bridge being created.
  # @option params [String] :name Name to give to the bridge being created.
  def bridges_create(params = {})
    post "bridges", params
  end

  # POST
  # /bridges/:bridgeId
  # Bridge
  # Create a new bridge or updates an existing one.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
  #
  # @param [String] bridge_id Unique ID to give to the bridge being created.
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
  # @option params [String] :name Set the name of the bridge.
  def bridges_create_or_update_with_id(bridge_id, params = {})
    post "bridges/#{bridge_id}", params
  end

  # GET
  # /bridges/:bridgeId
  # Bridge
  # Get bridge details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_get(bridge_id)
    get "bridges/#{bridge_id}"
  end

  # DELETE
  # /bridges/:bridgeId
  # void
  # Shut down a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_destroy(bridge_id)
    delete "bridges/#{bridge_id}"
  end

  # POST
  # /bridges/:bridgeId/addChannel
  # void
  # Add a channel to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to add to bridge
  # Allows comma separated values.
  # @option params [String] :role Channel's role in the bridge
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application; Channel currently recording
  # 422 - Channel not in Stasis application
  def bridges_add_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/addChannel", params
  end

  # POST
  # /bridges/:bridgeId/removeChannel
  # void
  # Remove a channel from a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  # 422 - Channel not in this bridge
  def bridges_remove_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/removeChannel", params
  end

  # POST
  # /bridges/:bridgeId/moh
  # void
  # Play music on hold to a bridge or change the MOH class that is playing.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :mohClass Channel's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_start_moh(bridge_id, params = {})
    post "bridges/#{bridge_id}/moh", params
  end

  # DELETE
  # /bridges/:bridgeId/moh
  # void
  # Stop playing music on hold to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_stop_moh(bridge_id)
    delete "bridges/#{bridge_id}/moh"
  end

  # POST
  # /bridges/:bridgeId/play
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback Id.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play(bridge_id, params = {})
    post "bridges/#{bridge_id}/play", params
  end

  # POST
  # /bridges/:bridgeId/play/:playbackId
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
  #
  # @param [String] bridge_id Bridge's id
  # @param [String] playback_id Playback ID.
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play_with_id(bridge_id, playback_id, params = {})
    post "bridges/#{bridge_id}/play/#{playback_id}", params
  end

  # POST
  # /bridges/:bridgeId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
  # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
  # @option params [Boolean] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Bridge not found
  # 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
  # 422 - The format specified is unknown on this system
  def bridges_record(bridge_id, params = {})
    post "bridges/#{bridge_id}/record", params
  end

  # Channels REST API
  # GET
  # /channels
  # List[Channel]
  # List all active channels in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
  #
  def channels_list
    get "channels"
  end

  # POST
  # /channels
  # Channel
  # Create a new channel (originate).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
  #
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :channelId The unique id to assign the channel on creation.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate(params = {})
    post "channels", params
  end

  # GET
  # /channels/:channelId
  # Channel
  # Channel details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  def channels_get(channel_id)
    get "channels/#{channel_id}"
  end

  # POST
  # /channels/:channelId
  # Channel
  # Create a new channel (originate with id).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
  #
  # @param [String] channel_id The unique id to assign the channel on creation.
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate_with_id(channel_id, params = {})
    post "channels/#{channel_id}", params
  end

  # DELETE
  # /channels/:channelId
  # void
  # Delete (i.e. hangup) a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :reason Reason for hanging up the channel
  #
  # Error Responses
  #
  # 400 - Invalid reason for hangup provided
  # 404 - Channel not found
  def channels_hangup(channel_id, params = {})
    delete "channels/#{channel_id}", params
  end

  # POST
  # /channels/:channelId/continue
  # void
  # Exit application; continue execution in the dialplan.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :context The context to continue to.
  # @option params [String] :extension The extension to continue to.
  # @option params [Integer] :priority The priority to continue to.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_continue_in_dialplan(channel_id, params = {})
    post "channels/#{channel_id}/continue", params
  end

  # POST
  # /channels/:channelId/answer
  # void
  # Answer a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_answer(channel_id)
    post "channels/#{channel_id}/answer"
  end

  # POST
  # /channels/:channelId/ring
  # void
  # Indicate ringing to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring(channel_id)
    post "channels/#{channel_id}/ring"
  end

  # DELETE
  # /channels/:channelId/ring
  # void
  # Stop ringing indication on a channel if locally generated.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring_stop(channel_id)
    delete "channels/#{channel_id}/ring"
  end

  # POST
  # /channels/:channelId/dtmf
  # void
  # Send provided DTMF to a given channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :dtmf DTMF To send.
  # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
  # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
  # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
  # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
  #
  # Error Responses
  #
  # 400 - DTMF is required
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_send_dtmf(channel_id, params = {})
    post "channels/#{channel_id}/dtmf", params
  end

  # POST
  # /channels/:channelId/mute
  # void
  # Mute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to mute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_mute(channel_id, params = {})
    post "channels/#{channel_id}/mute", params
  end

  # DELETE
  # /channels/:channelId/mute
  # void
  # Unmute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to unmute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unmute(channel_id, params = {})
    delete "channels/#{channel_id}/mute", params
  end

  # POST
  # /channels/:channelId/hold
  # void
  # Hold a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
  #
  # @param [String] channel_id  Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_hold(channel_id)
    post "channels/#{channel_id}/hold"
  end

  # DELETE
  # /channels/:channelId/hold
  # void
  # Remove a channel from hold.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unhold(channel_id)
    delete "channels/#{channel_id}/hold"
  end

  # POST
  # /channels/:channelId/moh
  # void
  # Play music on hold to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :mohClass Music on hold class to use
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_moh(channel_id, params = {})
    post "channels/#{channel_id}/moh", params
  end

  # DELETE
  # /channels/:channelId/moh
  # void
  # Stop playing music on hold to a channel.
  # POST
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_moh(channel_id)
    delete "channels/#{channel_id}/moh"
  end

  # /channels/:channelId/silence
  # void
  # Play silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_silence(channel_id)
    post "channels/#{channel_id}/silence"
  end

  # DELETE
  # /channels/:channelId/silence
  # void
  # Stop playing silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_silence(channel_id)
    delete "channels/#{channel_id}/silence"
  end

  # POST
  # /channels/:channelId/play
  # Playback
  # Start playback of media.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback ID.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play(channel_id, params = {})
    post "channels/#{channel_id}/play", params
  end

  # POST
  # /channels/:channelId/play/:playbackId
  # Playback
  # Start playback of media and specify the playbackId.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
  #
  # @param [String] channel_id channel_id
  # @param [String] playback_id playback_id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play_with_id(channel_id, playback_id, params = {})
    post "channels/#{channel_id}/play/#{playback_id}", params
  end

  # POST
  # /channels/:channelId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
  # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
  # @option params [Boolen] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  # 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
  # 422 - The format specified is unknown on this system
  def channels_record(channel_id, params = {})
    post "channels/#{channel_id}/record", params
  end

  # GET
  # /channels/:channelId/variable
  # Variable
  # Get the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
  #
  # @param [String] channel_id channel_id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to get
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_get_channel_var(channel_id, params = {})
    get "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/variable
  # void
  # Set the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_set_channel_var(channel_id, params = {})
    post "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/snoop
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :spy ("none") Direction of audio to spy on
  # @option params [String] :whisper ("none") Direction of audio to whisper into
  # @option params [String] :app *required Application the snooping channel is placed into
  # @option params [String] :appArgs The application arguments to pass to the Stasis application
  # @option params [String] :snoopId Unique ID to assign to snooping channel
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel(channel_id, params = {})
    post "channels/#{channel_id}/snoop", params
  end

  # POST
  # /channels/:channelId/snoop/:snoopId
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
  #
  # @param [String] channel_id Channel's id
  # @param [String] snoop_id Unique ID to assign to snooping channel
  # @param [Hash] params
  # @option param [String] :spy ("none") Direction of audio to spy on
  # @option param [String] :whisper ("none") Direction of audio to whisper into
  # @option param [String] :app *required Application the snooping channel is placed into
  # @option param [String] :appArgs The application arguments to pass to the Stasis application
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
    post "channels/#{channel_id}/snoop/#{snoop_id}", params
  end

  # Endpoints REST API

  # GET
  # /endpoints
  # List[Endpoint]
  # List all endpoints.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
  def endpoints_list
    get "endpoints"
  end

  # PUT
  # /endpoints/sendMessage
  # void
  # Send a message to some technology URI or endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
  #
  # @param [Hash] params
  # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 404 - Endpoint not found
  def endpoints_send_message(params = {})
    put "endpoints/sendMessage", params
  end

  # GET
  # /endpoints/:tech
  # List[Endpoint]
  # List available endoints for a given endpoint technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
  #
  # @param [String] tech Technology of the endpoints (sip,iax2,...)
  #
  # Error Responses
  #
  # 404 - Endpoints not found
  def endpoints_list_by_tech(tech)
    get "endpoints/#{tech}"
  end

  # GET
  # /endpoints/:tech/:resource
  # Endpoint
  # Details for an endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoints not found
  def endpoints_get(tech, resource)
    get "endpoints/#{tech}/#{resource}"
  end

  # PUT
  # /endpoints/:tech/:resource/sendMessage
  # void
  # Send a message to some endpoint in a technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  # @param [Hash] params
  # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option params [String] :body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoint not found
  def endpoints_send_message_to_endpoint(tech, resource, params = {})
    put "endpoints/#{tech}/#{resource}/sendMessage", params
  end

  # TODO
  # # Events REST API

  # # GET
  # # /events
  # # Message
  # # WebSocket connection for events.
  # #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
  # def events_event_websocket
  #   get "events"
  # end

  # POST
  # /events/user/:eventName
  # void
  # Generate a user event.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
  #
  # @param [String] event_name event_name
  # @param [Hash] params
  # @option param [String] application #required The name of the application that will receive this event
  # @option param [String] source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName}. Allows comma separated values.
  #
  # Body parameter
  #
  # variables: containers - The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } }
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  # 422 - Event source not found.
  # 400 - Invalid even tsource URI or userevent data.
  def events_user_event(event_name, params = {})
    post "events/user/#{event_name}", params
  end

  # Recordings REST API

  # GET
  # /recordings/stored
  # List[StoredRecording]
  # List recordings that are complete.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
  def recordings_list_stored
    get "recordings/stored"
  end

  # GET
  #
  # /recordings/stored/:recordingName
  #
  # StoredRecording
  # Get a stored recording's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_stored(recording_name)
    get "recordings/stored/#{recording_name}"
  end

  # DELETE
  # /recordings/stored/:recordingName
  # void
  # Delete a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_delete_stored(recording_name)
    delete "recordings/stored/#{recording_name}"
  end

  # POST
  # /recordings/stored/:recordingName/copy
  # StoredRecording
  # Copy a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
  #
  # @param [String] recording_name The name of the recording to copy
  # @param [Hash] params
  # @option params [String] :destinationRecordingName *required The destination name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - A recording with the same name already exists on the system
  def recordings_copy_stored(recording_name, params = {})
    post "recordings/stored/#{recording_name}/copy", params
  end

  # GET
  # /recordings/live/:recordingName
  # LiveRecording
  # List live recordings.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_live(recording_name)
    get "recordings/live/#{recording_name}"
  end

  # DELETE
  # /recordings/live/:recordingName
  # void
  # Stop a live recording and discard it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_cancel(recording_name)
    delete "recordings/live/#{recording_name}"
  end

  # POST
  # /recordings/live/:recordingName/stop
  # void
  # Stop a live recording and store it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_stop(recording_name)
    post "recordings/live/#{recording_name}/stop"
  end

  # POST
  # /recordings/live/:recordingName/pause
  # void
  # Pause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_pause(recording_name)
    post "recordings/live/#{recording_name}/pause"
  end

  # DELETE
  # /recordings/live/:recordingName/pause
  # void
  # Unpause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unpause(recording_name)
    delete "recordings/live/#{recording_name}/pause"
  end

  # POST
  # /recordings/live/:recordingName/mute
  # void
  # Mute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_mute(recording_name)
    post "recordings/live/#{recording_name}/mute"
  end

  # DELETE
  # /recordings/live/:recordingName/mute
  # void
  # Unmute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unmute(recording_name)
    delete "recordings/live/#{recording_name}/mute"
  end

  # Sounds REST API

  # GET
  # /sounds
  # List[Sound]
  # List all sounds.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
  #
  # @param [Hash] params
  # @option param [String] lang Lookup sound for a specific language.
  # @option param [String] format Lookup sound in a specific format.
  def sounds_list(params = {})
    get "sounds", params
  end

  # GET
  # /sounds/:soundId
  # Sound
  # Get a sound's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
  #
  # @param [String] sound_id Sound's id
  def sounds_get(sound_id)
    get "sounds/#{sound_id}"
  end

  # Applications REST API

  # GET
  # /applications
  # List[Application]
  # List all applications.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
  def applications_list
    get "applications"
  end

  # GET
  # /applications/:applicationName
  # Application
  # Get details of an application.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
  #
  # @param [String] application_name Application's name
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  def applications_get(application_name)
    get "applications/#{application_name}"
  end

  # POST
  # /applications/:applicationName/subscription
  # Application
  # Subscribe an application to a event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 422 - Event source does not exist.
  def applications_subscribe(application_name, params = {})
    post "applications/#{application_name}/subscription", params
  end

  # DELETE
  # /applications/:applicationName/subscription
  # Application
  # Unsubscribe an application from an event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 409 - Application not subscribed to event source.
  # 422 - Event source does not exist.
  def applications_unsubscribe(application_name, params = {})
    delete "applications/#{application_name}/subscription", params
  end

  # Playbacks REST API

  # GET
  # /playbacks/:playbackId
  # Playback
  # Get a playback's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_get(playback_id)
    get "playbacks/#{playback_id}"
  end

  # DELETE
  # /playbacks/:playbackId
  # void
  # Stop a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_stop(playback_id)
    delete "playbacks/#{playback_id}"
  end

  # POST
  # /playbacks/:playbackId/control
  # void
  # Control a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
  #
  # @param [String] playback_id Playback's id
  # @param [Hash] params
  # @option params [String] :operation *required Operation to perform on the playback.
  #
  # Error Responses
  #
  # 400 - The provided operation parameter was invalid
  # 404 - The playback cannot be found
  # 409 - The operation cannot be performed in the playback's current state
  def playbacks_control(playback_id, params = {})
    post "playbacks/#{playback_id}/control", params
  end

  # Devicestates REST API

  # GET
  # /deviceStates
  # List[DeviceState]
  # List all ARI controlled device states.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
  def device_states_list
    get "deviceStates"
  end

  # GET
  # /deviceStates/:deviceName
  # DeviceState
  # Retrieve the current state of a device.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
  #
  # @param [String] device_name Name of the device
  def device_states_get(device_name)
    get "deviceStates/#{device_name}"
  end

  # PUT
  # /deviceStates/:deviceName
  # void
  # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
  #
  # @param [String] device_name Name of the device
  # @param [Hash] params
  # @option params [String] :deviceState *required Device state value
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_update(device_name, params = {})
    put "deviceStates/#{device_name}", params
  end

  # DELETE
  # /deviceStates/:deviceName
  # void
  # Destroy a device-state controlled by ARI.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
  #
  # @param [String] device_name Name of the device
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_delete(device_name)
    delete "deviceStates/#{device_name}"
  end

  # Mailboxes REST API

  # GET
  # /mailboxes
  # List[Mailbox]
  # List all mailboxes.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
  def mailboxes_list
    get "mailboxes"
  end

  # GET
  # /mailboxes/:mailboxName
  # Mailbox
  # Retrieve the current state of a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_get(mailbox_name)
    get "mailboxes/#{mailbox_name}"
  end

  # PUT
  # /mailboxes/:mailboxName
  # void
  # Change the state of a mailbox. (Note - implicitly creates the mailbox).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
  #
  # @param [String] mailbox_name Name of the mailbox
  # @param [Hash] params
  # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
  # @option params [Integer] :newMessages *required Count of new messages in the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_update(mailbox_name, params = {})
    put "mailboxes/#{mailbox_name}", params
  end

  # DELETE
  # /mailboxes/:mailboxName
  # void
  # Destroy a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_delete(mailbox_name)
    delete "mailboxes/#{mailbox_name}"
  end

  private

    def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
      # Setup args for make_request
      path = "/ari/#{path}" unless path =~ /^\//
      path = "/#{@prefix}#{path}" if @prefix

      options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
      # Make request via the provided service
      result = ARI.make_request path, args, verb, options

      if result.status >= 500
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body
        }
        raise ARI::ServerError.new(result.body, error_detail)
      elsif result.status >= 400
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body,
          :data        => ARI::JSON.load(result.body)
        }
        raise ARI::APIError.new(result.body, error_detail)
      end

      # Parse the body
      body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
        ARI::JSON.load result.body.to_s
      else
        result.body.to_s
      end
      # Return result
      if options[:http_component]
        result.send options[:http_component]
      else
        body
      end
    end

end

#passwordString (readonly)

Returns password for basic auth.

Returns:

  • (String)

    password for basic auth



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/ari/client.rb', line 15

class Client

  # @param [Hash] options
  # @option options [String] :host ("localhost") Host name
  # @option options [Integer] :port (8088) Port number
  # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
  # @option options [String] :username username for basic auth
  # @option options [String] :password password for basic auth
  def initialize(options = {})
    @host     = options[:host] || "localhost"
    @port     = options[:port] || 8088
    @prefix   = options[:prefix] if options[:prefix]
    @username = options[:username] if options[:username]
    @password = options[:password] if options[:password]
  end
  attr_reader :host, :port, :prefix, :username, :password

  %w(get post put delete).each do |verb|
    define_method(verb) do |path, params = {}|
      api_call(path, params, verb)
    end
  end

  # Asterisk REST API

  # GET
  # /asterisk/info
  # AsteriskInfo
  # Gets Asterisk system information.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
  #
  # @param [String] only Filter information returned. Allows comma separated values.
  def asterisk_get_info
    get "asterisk/info"
  end

  # GET
  # /asterisk/variable
  # Variable
  # Get the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
  #
  # @param [Hash] params
  # @option params [String] variable *required The variable to get
  #
  # Error Responses
  #
  # return 400 - Missing variable parameter.
  def asterisk_get_global_var(params = {})
    get "asterisk/variable", params
  end

  # POST
  # /asterisk/variable
  # void
  # Set the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
  #
  # @param [Hash] params
  # @option params [String] :variable *required The variable to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  # 400 - Missing variable parameter.
  def asterisk_set_global_var(params = {})
    post "asterisk/variable", params
  end


  # Bridges REST API
  #

  # GET
  # /bridges
  # List[Bridge]
  # List all active bridges in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
  def bridges_list
    get "bridges"
  end

  # POST
  # /bridges
  # Bridge
  # Create a new bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
  #
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
  # @option params [String] :bridgeId Unique ID to give to the bridge being created.
  # @option params [String] :name Name to give to the bridge being created.
  def bridges_create(params = {})
    post "bridges", params
  end

  # POST
  # /bridges/:bridgeId
  # Bridge
  # Create a new bridge or updates an existing one.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
  #
  # @param [String] bridge_id Unique ID to give to the bridge being created.
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
  # @option params [String] :name Set the name of the bridge.
  def bridges_create_or_update_with_id(bridge_id, params = {})
    post "bridges/#{bridge_id}", params
  end

  # GET
  # /bridges/:bridgeId
  # Bridge
  # Get bridge details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_get(bridge_id)
    get "bridges/#{bridge_id}"
  end

  # DELETE
  # /bridges/:bridgeId
  # void
  # Shut down a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_destroy(bridge_id)
    delete "bridges/#{bridge_id}"
  end

  # POST
  # /bridges/:bridgeId/addChannel
  # void
  # Add a channel to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to add to bridge
  # Allows comma separated values.
  # @option params [String] :role Channel's role in the bridge
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application; Channel currently recording
  # 422 - Channel not in Stasis application
  def bridges_add_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/addChannel", params
  end

  # POST
  # /bridges/:bridgeId/removeChannel
  # void
  # Remove a channel from a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  # 422 - Channel not in this bridge
  def bridges_remove_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/removeChannel", params
  end

  # POST
  # /bridges/:bridgeId/moh
  # void
  # Play music on hold to a bridge or change the MOH class that is playing.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :mohClass Channel's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_start_moh(bridge_id, params = {})
    post "bridges/#{bridge_id}/moh", params
  end

  # DELETE
  # /bridges/:bridgeId/moh
  # void
  # Stop playing music on hold to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_stop_moh(bridge_id)
    delete "bridges/#{bridge_id}/moh"
  end

  # POST
  # /bridges/:bridgeId/play
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback Id.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play(bridge_id, params = {})
    post "bridges/#{bridge_id}/play", params
  end

  # POST
  # /bridges/:bridgeId/play/:playbackId
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
  #
  # @param [String] bridge_id Bridge's id
  # @param [String] playback_id Playback ID.
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play_with_id(bridge_id, playback_id, params = {})
    post "bridges/#{bridge_id}/play/#{playback_id}", params
  end

  # POST
  # /bridges/:bridgeId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
  # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
  # @option params [Boolean] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Bridge not found
  # 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
  # 422 - The format specified is unknown on this system
  def bridges_record(bridge_id, params = {})
    post "bridges/#{bridge_id}/record", params
  end

  # Channels REST API
  # GET
  # /channels
  # List[Channel]
  # List all active channels in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
  #
  def channels_list
    get "channels"
  end

  # POST
  # /channels
  # Channel
  # Create a new channel (originate).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
  #
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :channelId The unique id to assign the channel on creation.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate(params = {})
    post "channels", params
  end

  # GET
  # /channels/:channelId
  # Channel
  # Channel details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  def channels_get(channel_id)
    get "channels/#{channel_id}"
  end

  # POST
  # /channels/:channelId
  # Channel
  # Create a new channel (originate with id).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
  #
  # @param [String] channel_id The unique id to assign the channel on creation.
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate_with_id(channel_id, params = {})
    post "channels/#{channel_id}", params
  end

  # DELETE
  # /channels/:channelId
  # void
  # Delete (i.e. hangup) a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :reason Reason for hanging up the channel
  #
  # Error Responses
  #
  # 400 - Invalid reason for hangup provided
  # 404 - Channel not found
  def channels_hangup(channel_id, params = {})
    delete "channels/#{channel_id}", params
  end

  # POST
  # /channels/:channelId/continue
  # void
  # Exit application; continue execution in the dialplan.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :context The context to continue to.
  # @option params [String] :extension The extension to continue to.
  # @option params [Integer] :priority The priority to continue to.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_continue_in_dialplan(channel_id, params = {})
    post "channels/#{channel_id}/continue", params
  end

  # POST
  # /channels/:channelId/answer
  # void
  # Answer a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_answer(channel_id)
    post "channels/#{channel_id}/answer"
  end

  # POST
  # /channels/:channelId/ring
  # void
  # Indicate ringing to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring(channel_id)
    post "channels/#{channel_id}/ring"
  end

  # DELETE
  # /channels/:channelId/ring
  # void
  # Stop ringing indication on a channel if locally generated.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring_stop(channel_id)
    delete "channels/#{channel_id}/ring"
  end

  # POST
  # /channels/:channelId/dtmf
  # void
  # Send provided DTMF to a given channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :dtmf DTMF To send.
  # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
  # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
  # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
  # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
  #
  # Error Responses
  #
  # 400 - DTMF is required
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_send_dtmf(channel_id, params = {})
    post "channels/#{channel_id}/dtmf", params
  end

  # POST
  # /channels/:channelId/mute
  # void
  # Mute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to mute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_mute(channel_id, params = {})
    post "channels/#{channel_id}/mute", params
  end

  # DELETE
  # /channels/:channelId/mute
  # void
  # Unmute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to unmute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unmute(channel_id, params = {})
    delete "channels/#{channel_id}/mute", params
  end

  # POST
  # /channels/:channelId/hold
  # void
  # Hold a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
  #
  # @param [String] channel_id  Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_hold(channel_id)
    post "channels/#{channel_id}/hold"
  end

  # DELETE
  # /channels/:channelId/hold
  # void
  # Remove a channel from hold.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unhold(channel_id)
    delete "channels/#{channel_id}/hold"
  end

  # POST
  # /channels/:channelId/moh
  # void
  # Play music on hold to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :mohClass Music on hold class to use
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_moh(channel_id, params = {})
    post "channels/#{channel_id}/moh", params
  end

  # DELETE
  # /channels/:channelId/moh
  # void
  # Stop playing music on hold to a channel.
  # POST
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_moh(channel_id)
    delete "channels/#{channel_id}/moh"
  end

  # /channels/:channelId/silence
  # void
  # Play silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_silence(channel_id)
    post "channels/#{channel_id}/silence"
  end

  # DELETE
  # /channels/:channelId/silence
  # void
  # Stop playing silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_silence(channel_id)
    delete "channels/#{channel_id}/silence"
  end

  # POST
  # /channels/:channelId/play
  # Playback
  # Start playback of media.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback ID.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play(channel_id, params = {})
    post "channels/#{channel_id}/play", params
  end

  # POST
  # /channels/:channelId/play/:playbackId
  # Playback
  # Start playback of media and specify the playbackId.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
  #
  # @param [String] channel_id channel_id
  # @param [String] playback_id playback_id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play_with_id(channel_id, playback_id, params = {})
    post "channels/#{channel_id}/play/#{playback_id}", params
  end

  # POST
  # /channels/:channelId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
  # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
  # @option params [Boolen] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  # 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
  # 422 - The format specified is unknown on this system
  def channels_record(channel_id, params = {})
    post "channels/#{channel_id}/record", params
  end

  # GET
  # /channels/:channelId/variable
  # Variable
  # Get the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
  #
  # @param [String] channel_id channel_id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to get
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_get_channel_var(channel_id, params = {})
    get "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/variable
  # void
  # Set the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_set_channel_var(channel_id, params = {})
    post "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/snoop
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :spy ("none") Direction of audio to spy on
  # @option params [String] :whisper ("none") Direction of audio to whisper into
  # @option params [String] :app *required Application the snooping channel is placed into
  # @option params [String] :appArgs The application arguments to pass to the Stasis application
  # @option params [String] :snoopId Unique ID to assign to snooping channel
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel(channel_id, params = {})
    post "channels/#{channel_id}/snoop", params
  end

  # POST
  # /channels/:channelId/snoop/:snoopId
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
  #
  # @param [String] channel_id Channel's id
  # @param [String] snoop_id Unique ID to assign to snooping channel
  # @param [Hash] params
  # @option param [String] :spy ("none") Direction of audio to spy on
  # @option param [String] :whisper ("none") Direction of audio to whisper into
  # @option param [String] :app *required Application the snooping channel is placed into
  # @option param [String] :appArgs The application arguments to pass to the Stasis application
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
    post "channels/#{channel_id}/snoop/#{snoop_id}", params
  end

  # Endpoints REST API

  # GET
  # /endpoints
  # List[Endpoint]
  # List all endpoints.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
  def endpoints_list
    get "endpoints"
  end

  # PUT
  # /endpoints/sendMessage
  # void
  # Send a message to some technology URI or endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
  #
  # @param [Hash] params
  # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 404 - Endpoint not found
  def endpoints_send_message(params = {})
    put "endpoints/sendMessage", params
  end

  # GET
  # /endpoints/:tech
  # List[Endpoint]
  # List available endoints for a given endpoint technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
  #
  # @param [String] tech Technology of the endpoints (sip,iax2,...)
  #
  # Error Responses
  #
  # 404 - Endpoints not found
  def endpoints_list_by_tech(tech)
    get "endpoints/#{tech}"
  end

  # GET
  # /endpoints/:tech/:resource
  # Endpoint
  # Details for an endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoints not found
  def endpoints_get(tech, resource)
    get "endpoints/#{tech}/#{resource}"
  end

  # PUT
  # /endpoints/:tech/:resource/sendMessage
  # void
  # Send a message to some endpoint in a technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  # @param [Hash] params
  # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option params [String] :body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoint not found
  def endpoints_send_message_to_endpoint(tech, resource, params = {})
    put "endpoints/#{tech}/#{resource}/sendMessage", params
  end

  # TODO
  # # Events REST API

  # # GET
  # # /events
  # # Message
  # # WebSocket connection for events.
  # #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
  # def events_event_websocket
  #   get "events"
  # end

  # POST
  # /events/user/:eventName
  # void
  # Generate a user event.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
  #
  # @param [String] event_name event_name
  # @param [Hash] params
  # @option param [String] application #required The name of the application that will receive this event
  # @option param [String] source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName}. Allows comma separated values.
  #
  # Body parameter
  #
  # variables: containers - The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } }
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  # 422 - Event source not found.
  # 400 - Invalid even tsource URI or userevent data.
  def events_user_event(event_name, params = {})
    post "events/user/#{event_name}", params
  end

  # Recordings REST API

  # GET
  # /recordings/stored
  # List[StoredRecording]
  # List recordings that are complete.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
  def recordings_list_stored
    get "recordings/stored"
  end

  # GET
  #
  # /recordings/stored/:recordingName
  #
  # StoredRecording
  # Get a stored recording's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_stored(recording_name)
    get "recordings/stored/#{recording_name}"
  end

  # DELETE
  # /recordings/stored/:recordingName
  # void
  # Delete a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_delete_stored(recording_name)
    delete "recordings/stored/#{recording_name}"
  end

  # POST
  # /recordings/stored/:recordingName/copy
  # StoredRecording
  # Copy a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
  #
  # @param [String] recording_name The name of the recording to copy
  # @param [Hash] params
  # @option params [String] :destinationRecordingName *required The destination name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - A recording with the same name already exists on the system
  def recordings_copy_stored(recording_name, params = {})
    post "recordings/stored/#{recording_name}/copy", params
  end

  # GET
  # /recordings/live/:recordingName
  # LiveRecording
  # List live recordings.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_live(recording_name)
    get "recordings/live/#{recording_name}"
  end

  # DELETE
  # /recordings/live/:recordingName
  # void
  # Stop a live recording and discard it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_cancel(recording_name)
    delete "recordings/live/#{recording_name}"
  end

  # POST
  # /recordings/live/:recordingName/stop
  # void
  # Stop a live recording and store it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_stop(recording_name)
    post "recordings/live/#{recording_name}/stop"
  end

  # POST
  # /recordings/live/:recordingName/pause
  # void
  # Pause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_pause(recording_name)
    post "recordings/live/#{recording_name}/pause"
  end

  # DELETE
  # /recordings/live/:recordingName/pause
  # void
  # Unpause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unpause(recording_name)
    delete "recordings/live/#{recording_name}/pause"
  end

  # POST
  # /recordings/live/:recordingName/mute
  # void
  # Mute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_mute(recording_name)
    post "recordings/live/#{recording_name}/mute"
  end

  # DELETE
  # /recordings/live/:recordingName/mute
  # void
  # Unmute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unmute(recording_name)
    delete "recordings/live/#{recording_name}/mute"
  end

  # Sounds REST API

  # GET
  # /sounds
  # List[Sound]
  # List all sounds.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
  #
  # @param [Hash] params
  # @option param [String] lang Lookup sound for a specific language.
  # @option param [String] format Lookup sound in a specific format.
  def sounds_list(params = {})
    get "sounds", params
  end

  # GET
  # /sounds/:soundId
  # Sound
  # Get a sound's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
  #
  # @param [String] sound_id Sound's id
  def sounds_get(sound_id)
    get "sounds/#{sound_id}"
  end

  # Applications REST API

  # GET
  # /applications
  # List[Application]
  # List all applications.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
  def applications_list
    get "applications"
  end

  # GET
  # /applications/:applicationName
  # Application
  # Get details of an application.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
  #
  # @param [String] application_name Application's name
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  def applications_get(application_name)
    get "applications/#{application_name}"
  end

  # POST
  # /applications/:applicationName/subscription
  # Application
  # Subscribe an application to a event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 422 - Event source does not exist.
  def applications_subscribe(application_name, params = {})
    post "applications/#{application_name}/subscription", params
  end

  # DELETE
  # /applications/:applicationName/subscription
  # Application
  # Unsubscribe an application from an event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 409 - Application not subscribed to event source.
  # 422 - Event source does not exist.
  def applications_unsubscribe(application_name, params = {})
    delete "applications/#{application_name}/subscription", params
  end

  # Playbacks REST API

  # GET
  # /playbacks/:playbackId
  # Playback
  # Get a playback's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_get(playback_id)
    get "playbacks/#{playback_id}"
  end

  # DELETE
  # /playbacks/:playbackId
  # void
  # Stop a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_stop(playback_id)
    delete "playbacks/#{playback_id}"
  end

  # POST
  # /playbacks/:playbackId/control
  # void
  # Control a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
  #
  # @param [String] playback_id Playback's id
  # @param [Hash] params
  # @option params [String] :operation *required Operation to perform on the playback.
  #
  # Error Responses
  #
  # 400 - The provided operation parameter was invalid
  # 404 - The playback cannot be found
  # 409 - The operation cannot be performed in the playback's current state
  def playbacks_control(playback_id, params = {})
    post "playbacks/#{playback_id}/control", params
  end

  # Devicestates REST API

  # GET
  # /deviceStates
  # List[DeviceState]
  # List all ARI controlled device states.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
  def device_states_list
    get "deviceStates"
  end

  # GET
  # /deviceStates/:deviceName
  # DeviceState
  # Retrieve the current state of a device.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
  #
  # @param [String] device_name Name of the device
  def device_states_get(device_name)
    get "deviceStates/#{device_name}"
  end

  # PUT
  # /deviceStates/:deviceName
  # void
  # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
  #
  # @param [String] device_name Name of the device
  # @param [Hash] params
  # @option params [String] :deviceState *required Device state value
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_update(device_name, params = {})
    put "deviceStates/#{device_name}", params
  end

  # DELETE
  # /deviceStates/:deviceName
  # void
  # Destroy a device-state controlled by ARI.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
  #
  # @param [String] device_name Name of the device
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_delete(device_name)
    delete "deviceStates/#{device_name}"
  end

  # Mailboxes REST API

  # GET
  # /mailboxes
  # List[Mailbox]
  # List all mailboxes.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
  def mailboxes_list
    get "mailboxes"
  end

  # GET
  # /mailboxes/:mailboxName
  # Mailbox
  # Retrieve the current state of a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_get(mailbox_name)
    get "mailboxes/#{mailbox_name}"
  end

  # PUT
  # /mailboxes/:mailboxName
  # void
  # Change the state of a mailbox. (Note - implicitly creates the mailbox).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
  #
  # @param [String] mailbox_name Name of the mailbox
  # @param [Hash] params
  # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
  # @option params [Integer] :newMessages *required Count of new messages in the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_update(mailbox_name, params = {})
    put "mailboxes/#{mailbox_name}", params
  end

  # DELETE
  # /mailboxes/:mailboxName
  # void
  # Destroy a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_delete(mailbox_name)
    delete "mailboxes/#{mailbox_name}"
  end

  private

    def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
      # Setup args for make_request
      path = "/ari/#{path}" unless path =~ /^\//
      path = "/#{@prefix}#{path}" if @prefix

      options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
      # Make request via the provided service
      result = ARI.make_request path, args, verb, options

      if result.status >= 500
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body
        }
        raise ARI::ServerError.new(result.body, error_detail)
      elsif result.status >= 400
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body,
          :data        => ARI::JSON.load(result.body)
        }
        raise ARI::APIError.new(result.body, error_detail)
      end

      # Parse the body
      body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
        ARI::JSON.load result.body.to_s
      else
        result.body.to_s
      end
      # Return result
      if options[:http_component]
        result.send options[:http_component]
      else
        body
      end
    end

end

#portInteger (readonly)

Returns Port number.

Returns:

  • (Integer)

    Port number



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/ari/client.rb', line 15

class Client

  # @param [Hash] options
  # @option options [String] :host ("localhost") Host name
  # @option options [Integer] :port (8088) Port number
  # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
  # @option options [String] :username username for basic auth
  # @option options [String] :password password for basic auth
  def initialize(options = {})
    @host     = options[:host] || "localhost"
    @port     = options[:port] || 8088
    @prefix   = options[:prefix] if options[:prefix]
    @username = options[:username] if options[:username]
    @password = options[:password] if options[:password]
  end
  attr_reader :host, :port, :prefix, :username, :password

  %w(get post put delete).each do |verb|
    define_method(verb) do |path, params = {}|
      api_call(path, params, verb)
    end
  end

  # Asterisk REST API

  # GET
  # /asterisk/info
  # AsteriskInfo
  # Gets Asterisk system information.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
  #
  # @param [String] only Filter information returned. Allows comma separated values.
  def asterisk_get_info
    get "asterisk/info"
  end

  # GET
  # /asterisk/variable
  # Variable
  # Get the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
  #
  # @param [Hash] params
  # @option params [String] variable *required The variable to get
  #
  # Error Responses
  #
  # return 400 - Missing variable parameter.
  def asterisk_get_global_var(params = {})
    get "asterisk/variable", params
  end

  # POST
  # /asterisk/variable
  # void
  # Set the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
  #
  # @param [Hash] params
  # @option params [String] :variable *required The variable to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  # 400 - Missing variable parameter.
  def asterisk_set_global_var(params = {})
    post "asterisk/variable", params
  end


  # Bridges REST API
  #

  # GET
  # /bridges
  # List[Bridge]
  # List all active bridges in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
  def bridges_list
    get "bridges"
  end

  # POST
  # /bridges
  # Bridge
  # Create a new bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
  #
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
  # @option params [String] :bridgeId Unique ID to give to the bridge being created.
  # @option params [String] :name Name to give to the bridge being created.
  def bridges_create(params = {})
    post "bridges", params
  end

  # POST
  # /bridges/:bridgeId
  # Bridge
  # Create a new bridge or updates an existing one.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
  #
  # @param [String] bridge_id Unique ID to give to the bridge being created.
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
  # @option params [String] :name Set the name of the bridge.
  def bridges_create_or_update_with_id(bridge_id, params = {})
    post "bridges/#{bridge_id}", params
  end

  # GET
  # /bridges/:bridgeId
  # Bridge
  # Get bridge details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_get(bridge_id)
    get "bridges/#{bridge_id}"
  end

  # DELETE
  # /bridges/:bridgeId
  # void
  # Shut down a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_destroy(bridge_id)
    delete "bridges/#{bridge_id}"
  end

  # POST
  # /bridges/:bridgeId/addChannel
  # void
  # Add a channel to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to add to bridge
  # Allows comma separated values.
  # @option params [String] :role Channel's role in the bridge
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application; Channel currently recording
  # 422 - Channel not in Stasis application
  def bridges_add_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/addChannel", params
  end

  # POST
  # /bridges/:bridgeId/removeChannel
  # void
  # Remove a channel from a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  # 422 - Channel not in this bridge
  def bridges_remove_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/removeChannel", params
  end

  # POST
  # /bridges/:bridgeId/moh
  # void
  # Play music on hold to a bridge or change the MOH class that is playing.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :mohClass Channel's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_start_moh(bridge_id, params = {})
    post "bridges/#{bridge_id}/moh", params
  end

  # DELETE
  # /bridges/:bridgeId/moh
  # void
  # Stop playing music on hold to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_stop_moh(bridge_id)
    delete "bridges/#{bridge_id}/moh"
  end

  # POST
  # /bridges/:bridgeId/play
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback Id.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play(bridge_id, params = {})
    post "bridges/#{bridge_id}/play", params
  end

  # POST
  # /bridges/:bridgeId/play/:playbackId
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
  #
  # @param [String] bridge_id Bridge's id
  # @param [String] playback_id Playback ID.
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play_with_id(bridge_id, playback_id, params = {})
    post "bridges/#{bridge_id}/play/#{playback_id}", params
  end

  # POST
  # /bridges/:bridgeId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
  # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
  # @option params [Boolean] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Bridge not found
  # 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
  # 422 - The format specified is unknown on this system
  def bridges_record(bridge_id, params = {})
    post "bridges/#{bridge_id}/record", params
  end

  # Channels REST API
  # GET
  # /channels
  # List[Channel]
  # List all active channels in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
  #
  def channels_list
    get "channels"
  end

  # POST
  # /channels
  # Channel
  # Create a new channel (originate).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
  #
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :channelId The unique id to assign the channel on creation.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate(params = {})
    post "channels", params
  end

  # GET
  # /channels/:channelId
  # Channel
  # Channel details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  def channels_get(channel_id)
    get "channels/#{channel_id}"
  end

  # POST
  # /channels/:channelId
  # Channel
  # Create a new channel (originate with id).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
  #
  # @param [String] channel_id The unique id to assign the channel on creation.
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate_with_id(channel_id, params = {})
    post "channels/#{channel_id}", params
  end

  # DELETE
  # /channels/:channelId
  # void
  # Delete (i.e. hangup) a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :reason Reason for hanging up the channel
  #
  # Error Responses
  #
  # 400 - Invalid reason for hangup provided
  # 404 - Channel not found
  def channels_hangup(channel_id, params = {})
    delete "channels/#{channel_id}", params
  end

  # POST
  # /channels/:channelId/continue
  # void
  # Exit application; continue execution in the dialplan.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :context The context to continue to.
  # @option params [String] :extension The extension to continue to.
  # @option params [Integer] :priority The priority to continue to.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_continue_in_dialplan(channel_id, params = {})
    post "channels/#{channel_id}/continue", params
  end

  # POST
  # /channels/:channelId/answer
  # void
  # Answer a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_answer(channel_id)
    post "channels/#{channel_id}/answer"
  end

  # POST
  # /channels/:channelId/ring
  # void
  # Indicate ringing to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring(channel_id)
    post "channels/#{channel_id}/ring"
  end

  # DELETE
  # /channels/:channelId/ring
  # void
  # Stop ringing indication on a channel if locally generated.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring_stop(channel_id)
    delete "channels/#{channel_id}/ring"
  end

  # POST
  # /channels/:channelId/dtmf
  # void
  # Send provided DTMF to a given channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :dtmf DTMF To send.
  # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
  # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
  # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
  # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
  #
  # Error Responses
  #
  # 400 - DTMF is required
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_send_dtmf(channel_id, params = {})
    post "channels/#{channel_id}/dtmf", params
  end

  # POST
  # /channels/:channelId/mute
  # void
  # Mute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to mute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_mute(channel_id, params = {})
    post "channels/#{channel_id}/mute", params
  end

  # DELETE
  # /channels/:channelId/mute
  # void
  # Unmute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to unmute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unmute(channel_id, params = {})
    delete "channels/#{channel_id}/mute", params
  end

  # POST
  # /channels/:channelId/hold
  # void
  # Hold a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
  #
  # @param [String] channel_id  Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_hold(channel_id)
    post "channels/#{channel_id}/hold"
  end

  # DELETE
  # /channels/:channelId/hold
  # void
  # Remove a channel from hold.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unhold(channel_id)
    delete "channels/#{channel_id}/hold"
  end

  # POST
  # /channels/:channelId/moh
  # void
  # Play music on hold to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :mohClass Music on hold class to use
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_moh(channel_id, params = {})
    post "channels/#{channel_id}/moh", params
  end

  # DELETE
  # /channels/:channelId/moh
  # void
  # Stop playing music on hold to a channel.
  # POST
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_moh(channel_id)
    delete "channels/#{channel_id}/moh"
  end

  # /channels/:channelId/silence
  # void
  # Play silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_silence(channel_id)
    post "channels/#{channel_id}/silence"
  end

  # DELETE
  # /channels/:channelId/silence
  # void
  # Stop playing silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_silence(channel_id)
    delete "channels/#{channel_id}/silence"
  end

  # POST
  # /channels/:channelId/play
  # Playback
  # Start playback of media.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback ID.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play(channel_id, params = {})
    post "channels/#{channel_id}/play", params
  end

  # POST
  # /channels/:channelId/play/:playbackId
  # Playback
  # Start playback of media and specify the playbackId.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
  #
  # @param [String] channel_id channel_id
  # @param [String] playback_id playback_id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play_with_id(channel_id, playback_id, params = {})
    post "channels/#{channel_id}/play/#{playback_id}", params
  end

  # POST
  # /channels/:channelId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
  # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
  # @option params [Boolen] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  # 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
  # 422 - The format specified is unknown on this system
  def channels_record(channel_id, params = {})
    post "channels/#{channel_id}/record", params
  end

  # GET
  # /channels/:channelId/variable
  # Variable
  # Get the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
  #
  # @param [String] channel_id channel_id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to get
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_get_channel_var(channel_id, params = {})
    get "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/variable
  # void
  # Set the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_set_channel_var(channel_id, params = {})
    post "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/snoop
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :spy ("none") Direction of audio to spy on
  # @option params [String] :whisper ("none") Direction of audio to whisper into
  # @option params [String] :app *required Application the snooping channel is placed into
  # @option params [String] :appArgs The application arguments to pass to the Stasis application
  # @option params [String] :snoopId Unique ID to assign to snooping channel
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel(channel_id, params = {})
    post "channels/#{channel_id}/snoop", params
  end

  # POST
  # /channels/:channelId/snoop/:snoopId
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
  #
  # @param [String] channel_id Channel's id
  # @param [String] snoop_id Unique ID to assign to snooping channel
  # @param [Hash] params
  # @option param [String] :spy ("none") Direction of audio to spy on
  # @option param [String] :whisper ("none") Direction of audio to whisper into
  # @option param [String] :app *required Application the snooping channel is placed into
  # @option param [String] :appArgs The application arguments to pass to the Stasis application
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
    post "channels/#{channel_id}/snoop/#{snoop_id}", params
  end

  # Endpoints REST API

  # GET
  # /endpoints
  # List[Endpoint]
  # List all endpoints.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
  def endpoints_list
    get "endpoints"
  end

  # PUT
  # /endpoints/sendMessage
  # void
  # Send a message to some technology URI or endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
  #
  # @param [Hash] params
  # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 404 - Endpoint not found
  def endpoints_send_message(params = {})
    put "endpoints/sendMessage", params
  end

  # GET
  # /endpoints/:tech
  # List[Endpoint]
  # List available endoints for a given endpoint technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
  #
  # @param [String] tech Technology of the endpoints (sip,iax2,...)
  #
  # Error Responses
  #
  # 404 - Endpoints not found
  def endpoints_list_by_tech(tech)
    get "endpoints/#{tech}"
  end

  # GET
  # /endpoints/:tech/:resource
  # Endpoint
  # Details for an endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoints not found
  def endpoints_get(tech, resource)
    get "endpoints/#{tech}/#{resource}"
  end

  # PUT
  # /endpoints/:tech/:resource/sendMessage
  # void
  # Send a message to some endpoint in a technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  # @param [Hash] params
  # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option params [String] :body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoint not found
  def endpoints_send_message_to_endpoint(tech, resource, params = {})
    put "endpoints/#{tech}/#{resource}/sendMessage", params
  end

  # TODO
  # # Events REST API

  # # GET
  # # /events
  # # Message
  # # WebSocket connection for events.
  # #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
  # def events_event_websocket
  #   get "events"
  # end

  # POST
  # /events/user/:eventName
  # void
  # Generate a user event.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
  #
  # @param [String] event_name event_name
  # @param [Hash] params
  # @option param [String] application #required The name of the application that will receive this event
  # @option param [String] source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName}. Allows comma separated values.
  #
  # Body parameter
  #
  # variables: containers - The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } }
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  # 422 - Event source not found.
  # 400 - Invalid even tsource URI or userevent data.
  def events_user_event(event_name, params = {})
    post "events/user/#{event_name}", params
  end

  # Recordings REST API

  # GET
  # /recordings/stored
  # List[StoredRecording]
  # List recordings that are complete.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
  def recordings_list_stored
    get "recordings/stored"
  end

  # GET
  #
  # /recordings/stored/:recordingName
  #
  # StoredRecording
  # Get a stored recording's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_stored(recording_name)
    get "recordings/stored/#{recording_name}"
  end

  # DELETE
  # /recordings/stored/:recordingName
  # void
  # Delete a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_delete_stored(recording_name)
    delete "recordings/stored/#{recording_name}"
  end

  # POST
  # /recordings/stored/:recordingName/copy
  # StoredRecording
  # Copy a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
  #
  # @param [String] recording_name The name of the recording to copy
  # @param [Hash] params
  # @option params [String] :destinationRecordingName *required The destination name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - A recording with the same name already exists on the system
  def recordings_copy_stored(recording_name, params = {})
    post "recordings/stored/#{recording_name}/copy", params
  end

  # GET
  # /recordings/live/:recordingName
  # LiveRecording
  # List live recordings.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_live(recording_name)
    get "recordings/live/#{recording_name}"
  end

  # DELETE
  # /recordings/live/:recordingName
  # void
  # Stop a live recording and discard it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_cancel(recording_name)
    delete "recordings/live/#{recording_name}"
  end

  # POST
  # /recordings/live/:recordingName/stop
  # void
  # Stop a live recording and store it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_stop(recording_name)
    post "recordings/live/#{recording_name}/stop"
  end

  # POST
  # /recordings/live/:recordingName/pause
  # void
  # Pause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_pause(recording_name)
    post "recordings/live/#{recording_name}/pause"
  end

  # DELETE
  # /recordings/live/:recordingName/pause
  # void
  # Unpause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unpause(recording_name)
    delete "recordings/live/#{recording_name}/pause"
  end

  # POST
  # /recordings/live/:recordingName/mute
  # void
  # Mute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_mute(recording_name)
    post "recordings/live/#{recording_name}/mute"
  end

  # DELETE
  # /recordings/live/:recordingName/mute
  # void
  # Unmute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unmute(recording_name)
    delete "recordings/live/#{recording_name}/mute"
  end

  # Sounds REST API

  # GET
  # /sounds
  # List[Sound]
  # List all sounds.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
  #
  # @param [Hash] params
  # @option param [String] lang Lookup sound for a specific language.
  # @option param [String] format Lookup sound in a specific format.
  def sounds_list(params = {})
    get "sounds", params
  end

  # GET
  # /sounds/:soundId
  # Sound
  # Get a sound's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
  #
  # @param [String] sound_id Sound's id
  def sounds_get(sound_id)
    get "sounds/#{sound_id}"
  end

  # Applications REST API

  # GET
  # /applications
  # List[Application]
  # List all applications.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
  def applications_list
    get "applications"
  end

  # GET
  # /applications/:applicationName
  # Application
  # Get details of an application.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
  #
  # @param [String] application_name Application's name
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  def applications_get(application_name)
    get "applications/#{application_name}"
  end

  # POST
  # /applications/:applicationName/subscription
  # Application
  # Subscribe an application to a event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 422 - Event source does not exist.
  def applications_subscribe(application_name, params = {})
    post "applications/#{application_name}/subscription", params
  end

  # DELETE
  # /applications/:applicationName/subscription
  # Application
  # Unsubscribe an application from an event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 409 - Application not subscribed to event source.
  # 422 - Event source does not exist.
  def applications_unsubscribe(application_name, params = {})
    delete "applications/#{application_name}/subscription", params
  end

  # Playbacks REST API

  # GET
  # /playbacks/:playbackId
  # Playback
  # Get a playback's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_get(playback_id)
    get "playbacks/#{playback_id}"
  end

  # DELETE
  # /playbacks/:playbackId
  # void
  # Stop a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_stop(playback_id)
    delete "playbacks/#{playback_id}"
  end

  # POST
  # /playbacks/:playbackId/control
  # void
  # Control a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
  #
  # @param [String] playback_id Playback's id
  # @param [Hash] params
  # @option params [String] :operation *required Operation to perform on the playback.
  #
  # Error Responses
  #
  # 400 - The provided operation parameter was invalid
  # 404 - The playback cannot be found
  # 409 - The operation cannot be performed in the playback's current state
  def playbacks_control(playback_id, params = {})
    post "playbacks/#{playback_id}/control", params
  end

  # Devicestates REST API

  # GET
  # /deviceStates
  # List[DeviceState]
  # List all ARI controlled device states.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
  def device_states_list
    get "deviceStates"
  end

  # GET
  # /deviceStates/:deviceName
  # DeviceState
  # Retrieve the current state of a device.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
  #
  # @param [String] device_name Name of the device
  def device_states_get(device_name)
    get "deviceStates/#{device_name}"
  end

  # PUT
  # /deviceStates/:deviceName
  # void
  # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
  #
  # @param [String] device_name Name of the device
  # @param [Hash] params
  # @option params [String] :deviceState *required Device state value
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_update(device_name, params = {})
    put "deviceStates/#{device_name}", params
  end

  # DELETE
  # /deviceStates/:deviceName
  # void
  # Destroy a device-state controlled by ARI.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
  #
  # @param [String] device_name Name of the device
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_delete(device_name)
    delete "deviceStates/#{device_name}"
  end

  # Mailboxes REST API

  # GET
  # /mailboxes
  # List[Mailbox]
  # List all mailboxes.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
  def mailboxes_list
    get "mailboxes"
  end

  # GET
  # /mailboxes/:mailboxName
  # Mailbox
  # Retrieve the current state of a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_get(mailbox_name)
    get "mailboxes/#{mailbox_name}"
  end

  # PUT
  # /mailboxes/:mailboxName
  # void
  # Change the state of a mailbox. (Note - implicitly creates the mailbox).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
  #
  # @param [String] mailbox_name Name of the mailbox
  # @param [Hash] params
  # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
  # @option params [Integer] :newMessages *required Count of new messages in the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_update(mailbox_name, params = {})
    put "mailboxes/#{mailbox_name}", params
  end

  # DELETE
  # /mailboxes/:mailboxName
  # void
  # Destroy a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_delete(mailbox_name)
    delete "mailboxes/#{mailbox_name}"
  end

  private

    def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
      # Setup args for make_request
      path = "/ari/#{path}" unless path =~ /^\//
      path = "/#{@prefix}#{path}" if @prefix

      options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
      # Make request via the provided service
      result = ARI.make_request path, args, verb, options

      if result.status >= 500
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body
        }
        raise ARI::ServerError.new(result.body, error_detail)
      elsif result.status >= 400
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body,
          :data        => ARI::JSON.load(result.body)
        }
        raise ARI::APIError.new(result.body, error_detail)
      end

      # Parse the body
      body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
        ARI::JSON.load result.body.to_s
      else
        result.body.to_s
      end
      # Return result
      if options[:http_component]
        result.send options[:http_component]
      else
        body
      end
    end

end

#prefixString (readonly)

Returns Prefix allows you to specify a prefix for all requests to the server.

Returns:

  • (String)

    Prefix allows you to specify a prefix for all requests to the server.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/ari/client.rb', line 15

class Client

  # @param [Hash] options
  # @option options [String] :host ("localhost") Host name
  # @option options [Integer] :port (8088) Port number
  # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
  # @option options [String] :username username for basic auth
  # @option options [String] :password password for basic auth
  def initialize(options = {})
    @host     = options[:host] || "localhost"
    @port     = options[:port] || 8088
    @prefix   = options[:prefix] if options[:prefix]
    @username = options[:username] if options[:username]
    @password = options[:password] if options[:password]
  end
  attr_reader :host, :port, :prefix, :username, :password

  %w(get post put delete).each do |verb|
    define_method(verb) do |path, params = {}|
      api_call(path, params, verb)
    end
  end

  # Asterisk REST API

  # GET
  # /asterisk/info
  # AsteriskInfo
  # Gets Asterisk system information.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
  #
  # @param [String] only Filter information returned. Allows comma separated values.
  def asterisk_get_info
    get "asterisk/info"
  end

  # GET
  # /asterisk/variable
  # Variable
  # Get the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
  #
  # @param [Hash] params
  # @option params [String] variable *required The variable to get
  #
  # Error Responses
  #
  # return 400 - Missing variable parameter.
  def asterisk_get_global_var(params = {})
    get "asterisk/variable", params
  end

  # POST
  # /asterisk/variable
  # void
  # Set the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
  #
  # @param [Hash] params
  # @option params [String] :variable *required The variable to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  # 400 - Missing variable parameter.
  def asterisk_set_global_var(params = {})
    post "asterisk/variable", params
  end


  # Bridges REST API
  #

  # GET
  # /bridges
  # List[Bridge]
  # List all active bridges in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
  def bridges_list
    get "bridges"
  end

  # POST
  # /bridges
  # Bridge
  # Create a new bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
  #
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
  # @option params [String] :bridgeId Unique ID to give to the bridge being created.
  # @option params [String] :name Name to give to the bridge being created.
  def bridges_create(params = {})
    post "bridges", params
  end

  # POST
  # /bridges/:bridgeId
  # Bridge
  # Create a new bridge or updates an existing one.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
  #
  # @param [String] bridge_id Unique ID to give to the bridge being created.
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
  # @option params [String] :name Set the name of the bridge.
  def bridges_create_or_update_with_id(bridge_id, params = {})
    post "bridges/#{bridge_id}", params
  end

  # GET
  # /bridges/:bridgeId
  # Bridge
  # Get bridge details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_get(bridge_id)
    get "bridges/#{bridge_id}"
  end

  # DELETE
  # /bridges/:bridgeId
  # void
  # Shut down a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_destroy(bridge_id)
    delete "bridges/#{bridge_id}"
  end

  # POST
  # /bridges/:bridgeId/addChannel
  # void
  # Add a channel to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to add to bridge
  # Allows comma separated values.
  # @option params [String] :role Channel's role in the bridge
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application; Channel currently recording
  # 422 - Channel not in Stasis application
  def bridges_add_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/addChannel", params
  end

  # POST
  # /bridges/:bridgeId/removeChannel
  # void
  # Remove a channel from a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  # 422 - Channel not in this bridge
  def bridges_remove_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/removeChannel", params
  end

  # POST
  # /bridges/:bridgeId/moh
  # void
  # Play music on hold to a bridge or change the MOH class that is playing.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :mohClass Channel's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_start_moh(bridge_id, params = {})
    post "bridges/#{bridge_id}/moh", params
  end

  # DELETE
  # /bridges/:bridgeId/moh
  # void
  # Stop playing music on hold to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_stop_moh(bridge_id)
    delete "bridges/#{bridge_id}/moh"
  end

  # POST
  # /bridges/:bridgeId/play
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback Id.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play(bridge_id, params = {})
    post "bridges/#{bridge_id}/play", params
  end

  # POST
  # /bridges/:bridgeId/play/:playbackId
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
  #
  # @param [String] bridge_id Bridge's id
  # @param [String] playback_id Playback ID.
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play_with_id(bridge_id, playback_id, params = {})
    post "bridges/#{bridge_id}/play/#{playback_id}", params
  end

  # POST
  # /bridges/:bridgeId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
  # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
  # @option params [Boolean] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Bridge not found
  # 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
  # 422 - The format specified is unknown on this system
  def bridges_record(bridge_id, params = {})
    post "bridges/#{bridge_id}/record", params
  end

  # Channels REST API
  # GET
  # /channels
  # List[Channel]
  # List all active channels in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
  #
  def channels_list
    get "channels"
  end

  # POST
  # /channels
  # Channel
  # Create a new channel (originate).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
  #
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :channelId The unique id to assign the channel on creation.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate(params = {})
    post "channels", params
  end

  # GET
  # /channels/:channelId
  # Channel
  # Channel details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  def channels_get(channel_id)
    get "channels/#{channel_id}"
  end

  # POST
  # /channels/:channelId
  # Channel
  # Create a new channel (originate with id).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
  #
  # @param [String] channel_id The unique id to assign the channel on creation.
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate_with_id(channel_id, params = {})
    post "channels/#{channel_id}", params
  end

  # DELETE
  # /channels/:channelId
  # void
  # Delete (i.e. hangup) a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :reason Reason for hanging up the channel
  #
  # Error Responses
  #
  # 400 - Invalid reason for hangup provided
  # 404 - Channel not found
  def channels_hangup(channel_id, params = {})
    delete "channels/#{channel_id}", params
  end

  # POST
  # /channels/:channelId/continue
  # void
  # Exit application; continue execution in the dialplan.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :context The context to continue to.
  # @option params [String] :extension The extension to continue to.
  # @option params [Integer] :priority The priority to continue to.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_continue_in_dialplan(channel_id, params = {})
    post "channels/#{channel_id}/continue", params
  end

  # POST
  # /channels/:channelId/answer
  # void
  # Answer a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_answer(channel_id)
    post "channels/#{channel_id}/answer"
  end

  # POST
  # /channels/:channelId/ring
  # void
  # Indicate ringing to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring(channel_id)
    post "channels/#{channel_id}/ring"
  end

  # DELETE
  # /channels/:channelId/ring
  # void
  # Stop ringing indication on a channel if locally generated.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring_stop(channel_id)
    delete "channels/#{channel_id}/ring"
  end

  # POST
  # /channels/:channelId/dtmf
  # void
  # Send provided DTMF to a given channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :dtmf DTMF To send.
  # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
  # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
  # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
  # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
  #
  # Error Responses
  #
  # 400 - DTMF is required
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_send_dtmf(channel_id, params = {})
    post "channels/#{channel_id}/dtmf", params
  end

  # POST
  # /channels/:channelId/mute
  # void
  # Mute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to mute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_mute(channel_id, params = {})
    post "channels/#{channel_id}/mute", params
  end

  # DELETE
  # /channels/:channelId/mute
  # void
  # Unmute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to unmute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unmute(channel_id, params = {})
    delete "channels/#{channel_id}/mute", params
  end

  # POST
  # /channels/:channelId/hold
  # void
  # Hold a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
  #
  # @param [String] channel_id  Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_hold(channel_id)
    post "channels/#{channel_id}/hold"
  end

  # DELETE
  # /channels/:channelId/hold
  # void
  # Remove a channel from hold.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unhold(channel_id)
    delete "channels/#{channel_id}/hold"
  end

  # POST
  # /channels/:channelId/moh
  # void
  # Play music on hold to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :mohClass Music on hold class to use
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_moh(channel_id, params = {})
    post "channels/#{channel_id}/moh", params
  end

  # DELETE
  # /channels/:channelId/moh
  # void
  # Stop playing music on hold to a channel.
  # POST
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_moh(channel_id)
    delete "channels/#{channel_id}/moh"
  end

  # /channels/:channelId/silence
  # void
  # Play silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_silence(channel_id)
    post "channels/#{channel_id}/silence"
  end

  # DELETE
  # /channels/:channelId/silence
  # void
  # Stop playing silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_silence(channel_id)
    delete "channels/#{channel_id}/silence"
  end

  # POST
  # /channels/:channelId/play
  # Playback
  # Start playback of media.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback ID.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play(channel_id, params = {})
    post "channels/#{channel_id}/play", params
  end

  # POST
  # /channels/:channelId/play/:playbackId
  # Playback
  # Start playback of media and specify the playbackId.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
  #
  # @param [String] channel_id channel_id
  # @param [String] playback_id playback_id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play_with_id(channel_id, playback_id, params = {})
    post "channels/#{channel_id}/play/#{playback_id}", params
  end

  # POST
  # /channels/:channelId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
  # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
  # @option params [Boolen] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  # 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
  # 422 - The format specified is unknown on this system
  def channels_record(channel_id, params = {})
    post "channels/#{channel_id}/record", params
  end

  # GET
  # /channels/:channelId/variable
  # Variable
  # Get the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
  #
  # @param [String] channel_id channel_id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to get
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_get_channel_var(channel_id, params = {})
    get "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/variable
  # void
  # Set the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_set_channel_var(channel_id, params = {})
    post "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/snoop
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :spy ("none") Direction of audio to spy on
  # @option params [String] :whisper ("none") Direction of audio to whisper into
  # @option params [String] :app *required Application the snooping channel is placed into
  # @option params [String] :appArgs The application arguments to pass to the Stasis application
  # @option params [String] :snoopId Unique ID to assign to snooping channel
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel(channel_id, params = {})
    post "channels/#{channel_id}/snoop", params
  end

  # POST
  # /channels/:channelId/snoop/:snoopId
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
  #
  # @param [String] channel_id Channel's id
  # @param [String] snoop_id Unique ID to assign to snooping channel
  # @param [Hash] params
  # @option param [String] :spy ("none") Direction of audio to spy on
  # @option param [String] :whisper ("none") Direction of audio to whisper into
  # @option param [String] :app *required Application the snooping channel is placed into
  # @option param [String] :appArgs The application arguments to pass to the Stasis application
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
    post "channels/#{channel_id}/snoop/#{snoop_id}", params
  end

  # Endpoints REST API

  # GET
  # /endpoints
  # List[Endpoint]
  # List all endpoints.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
  def endpoints_list
    get "endpoints"
  end

  # PUT
  # /endpoints/sendMessage
  # void
  # Send a message to some technology URI or endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
  #
  # @param [Hash] params
  # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 404 - Endpoint not found
  def endpoints_send_message(params = {})
    put "endpoints/sendMessage", params
  end

  # GET
  # /endpoints/:tech
  # List[Endpoint]
  # List available endoints for a given endpoint technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
  #
  # @param [String] tech Technology of the endpoints (sip,iax2,...)
  #
  # Error Responses
  #
  # 404 - Endpoints not found
  def endpoints_list_by_tech(tech)
    get "endpoints/#{tech}"
  end

  # GET
  # /endpoints/:tech/:resource
  # Endpoint
  # Details for an endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoints not found
  def endpoints_get(tech, resource)
    get "endpoints/#{tech}/#{resource}"
  end

  # PUT
  # /endpoints/:tech/:resource/sendMessage
  # void
  # Send a message to some endpoint in a technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  # @param [Hash] params
  # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option params [String] :body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoint not found
  def endpoints_send_message_to_endpoint(tech, resource, params = {})
    put "endpoints/#{tech}/#{resource}/sendMessage", params
  end

  # TODO
  # # Events REST API

  # # GET
  # # /events
  # # Message
  # # WebSocket connection for events.
  # #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
  # def events_event_websocket
  #   get "events"
  # end

  # POST
  # /events/user/:eventName
  # void
  # Generate a user event.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
  #
  # @param [String] event_name event_name
  # @param [Hash] params
  # @option param [String] application #required The name of the application that will receive this event
  # @option param [String] source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName}. Allows comma separated values.
  #
  # Body parameter
  #
  # variables: containers - The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } }
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  # 422 - Event source not found.
  # 400 - Invalid even tsource URI or userevent data.
  def events_user_event(event_name, params = {})
    post "events/user/#{event_name}", params
  end

  # Recordings REST API

  # GET
  # /recordings/stored
  # List[StoredRecording]
  # List recordings that are complete.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
  def recordings_list_stored
    get "recordings/stored"
  end

  # GET
  #
  # /recordings/stored/:recordingName
  #
  # StoredRecording
  # Get a stored recording's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_stored(recording_name)
    get "recordings/stored/#{recording_name}"
  end

  # DELETE
  # /recordings/stored/:recordingName
  # void
  # Delete a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_delete_stored(recording_name)
    delete "recordings/stored/#{recording_name}"
  end

  # POST
  # /recordings/stored/:recordingName/copy
  # StoredRecording
  # Copy a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
  #
  # @param [String] recording_name The name of the recording to copy
  # @param [Hash] params
  # @option params [String] :destinationRecordingName *required The destination name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - A recording with the same name already exists on the system
  def recordings_copy_stored(recording_name, params = {})
    post "recordings/stored/#{recording_name}/copy", params
  end

  # GET
  # /recordings/live/:recordingName
  # LiveRecording
  # List live recordings.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_live(recording_name)
    get "recordings/live/#{recording_name}"
  end

  # DELETE
  # /recordings/live/:recordingName
  # void
  # Stop a live recording and discard it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_cancel(recording_name)
    delete "recordings/live/#{recording_name}"
  end

  # POST
  # /recordings/live/:recordingName/stop
  # void
  # Stop a live recording and store it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_stop(recording_name)
    post "recordings/live/#{recording_name}/stop"
  end

  # POST
  # /recordings/live/:recordingName/pause
  # void
  # Pause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_pause(recording_name)
    post "recordings/live/#{recording_name}/pause"
  end

  # DELETE
  # /recordings/live/:recordingName/pause
  # void
  # Unpause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unpause(recording_name)
    delete "recordings/live/#{recording_name}/pause"
  end

  # POST
  # /recordings/live/:recordingName/mute
  # void
  # Mute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_mute(recording_name)
    post "recordings/live/#{recording_name}/mute"
  end

  # DELETE
  # /recordings/live/:recordingName/mute
  # void
  # Unmute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unmute(recording_name)
    delete "recordings/live/#{recording_name}/mute"
  end

  # Sounds REST API

  # GET
  # /sounds
  # List[Sound]
  # List all sounds.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
  #
  # @param [Hash] params
  # @option param [String] lang Lookup sound for a specific language.
  # @option param [String] format Lookup sound in a specific format.
  def sounds_list(params = {})
    get "sounds", params
  end

  # GET
  # /sounds/:soundId
  # Sound
  # Get a sound's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
  #
  # @param [String] sound_id Sound's id
  def sounds_get(sound_id)
    get "sounds/#{sound_id}"
  end

  # Applications REST API

  # GET
  # /applications
  # List[Application]
  # List all applications.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
  def applications_list
    get "applications"
  end

  # GET
  # /applications/:applicationName
  # Application
  # Get details of an application.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
  #
  # @param [String] application_name Application's name
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  def applications_get(application_name)
    get "applications/#{application_name}"
  end

  # POST
  # /applications/:applicationName/subscription
  # Application
  # Subscribe an application to a event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 422 - Event source does not exist.
  def applications_subscribe(application_name, params = {})
    post "applications/#{application_name}/subscription", params
  end

  # DELETE
  # /applications/:applicationName/subscription
  # Application
  # Unsubscribe an application from an event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 409 - Application not subscribed to event source.
  # 422 - Event source does not exist.
  def applications_unsubscribe(application_name, params = {})
    delete "applications/#{application_name}/subscription", params
  end

  # Playbacks REST API

  # GET
  # /playbacks/:playbackId
  # Playback
  # Get a playback's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_get(playback_id)
    get "playbacks/#{playback_id}"
  end

  # DELETE
  # /playbacks/:playbackId
  # void
  # Stop a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_stop(playback_id)
    delete "playbacks/#{playback_id}"
  end

  # POST
  # /playbacks/:playbackId/control
  # void
  # Control a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
  #
  # @param [String] playback_id Playback's id
  # @param [Hash] params
  # @option params [String] :operation *required Operation to perform on the playback.
  #
  # Error Responses
  #
  # 400 - The provided operation parameter was invalid
  # 404 - The playback cannot be found
  # 409 - The operation cannot be performed in the playback's current state
  def playbacks_control(playback_id, params = {})
    post "playbacks/#{playback_id}/control", params
  end

  # Devicestates REST API

  # GET
  # /deviceStates
  # List[DeviceState]
  # List all ARI controlled device states.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
  def device_states_list
    get "deviceStates"
  end

  # GET
  # /deviceStates/:deviceName
  # DeviceState
  # Retrieve the current state of a device.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
  #
  # @param [String] device_name Name of the device
  def device_states_get(device_name)
    get "deviceStates/#{device_name}"
  end

  # PUT
  # /deviceStates/:deviceName
  # void
  # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
  #
  # @param [String] device_name Name of the device
  # @param [Hash] params
  # @option params [String] :deviceState *required Device state value
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_update(device_name, params = {})
    put "deviceStates/#{device_name}", params
  end

  # DELETE
  # /deviceStates/:deviceName
  # void
  # Destroy a device-state controlled by ARI.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
  #
  # @param [String] device_name Name of the device
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_delete(device_name)
    delete "deviceStates/#{device_name}"
  end

  # Mailboxes REST API

  # GET
  # /mailboxes
  # List[Mailbox]
  # List all mailboxes.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
  def mailboxes_list
    get "mailboxes"
  end

  # GET
  # /mailboxes/:mailboxName
  # Mailbox
  # Retrieve the current state of a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_get(mailbox_name)
    get "mailboxes/#{mailbox_name}"
  end

  # PUT
  # /mailboxes/:mailboxName
  # void
  # Change the state of a mailbox. (Note - implicitly creates the mailbox).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
  #
  # @param [String] mailbox_name Name of the mailbox
  # @param [Hash] params
  # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
  # @option params [Integer] :newMessages *required Count of new messages in the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_update(mailbox_name, params = {})
    put "mailboxes/#{mailbox_name}", params
  end

  # DELETE
  # /mailboxes/:mailboxName
  # void
  # Destroy a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_delete(mailbox_name)
    delete "mailboxes/#{mailbox_name}"
  end

  private

    def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
      # Setup args for make_request
      path = "/ari/#{path}" unless path =~ /^\//
      path = "/#{@prefix}#{path}" if @prefix

      options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
      # Make request via the provided service
      result = ARI.make_request path, args, verb, options

      if result.status >= 500
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body
        }
        raise ARI::ServerError.new(result.body, error_detail)
      elsif result.status >= 400
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body,
          :data        => ARI::JSON.load(result.body)
        }
        raise ARI::APIError.new(result.body, error_detail)
      end

      # Parse the body
      body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
        ARI::JSON.load result.body.to_s
      else
        result.body.to_s
      end
      # Return result
      if options[:http_component]
        result.send options[:http_component]
      else
        body
      end
    end

end

#usernameString (readonly)

Returns username for basic auth.

Returns:

  • (String)

    username for basic auth



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
# File 'lib/ari/client.rb', line 15

class Client

  # @param [Hash] options
  # @option options [String] :host ("localhost") Host name
  # @option options [Integer] :port (8088) Port number
  # @option options [String] :prefix Prefix allows you to specify a prefix for all requests to the server.
  # @option options [String] :username username for basic auth
  # @option options [String] :password password for basic auth
  def initialize(options = {})
    @host     = options[:host] || "localhost"
    @port     = options[:port] || 8088
    @prefix   = options[:prefix] if options[:prefix]
    @username = options[:username] if options[:username]
    @password = options[:password] if options[:password]
  end
  attr_reader :host, :port, :prefix, :username, :password

  %w(get post put delete).each do |verb|
    define_method(verb) do |path, params = {}|
      api_call(path, params, verb)
    end
  end

  # Asterisk REST API

  # GET
  # /asterisk/info
  # AsteriskInfo
  # Gets Asterisk system information.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getInfo
  #
  # @param [String] only Filter information returned. Allows comma separated values.
  def asterisk_get_info
    get "asterisk/info"
  end

  # GET
  # /asterisk/variable
  # Variable
  # Get the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-getGlobalVar
  #
  # @param [Hash] params
  # @option params [String] variable *required The variable to get
  #
  # Error Responses
  #
  # return 400 - Missing variable parameter.
  def asterisk_get_global_var(params = {})
    get "asterisk/variable", params
  end

  # POST
  # /asterisk/variable
  # void
  # Set the value of a global variable.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Asterisk+REST+API#Asterisk12AsteriskRESTAPI-setGlobalVar
  #
  # @param [Hash] params
  # @option params [String] :variable *required The variable to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  # 400 - Missing variable parameter.
  def asterisk_set_global_var(params = {})
    post "asterisk/variable", params
  end


  # Bridges REST API
  #

  # GET
  # /bridges
  # List[Bridge]
  # List all active bridges in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-list
  def bridges_list
    get "bridges"
  end

  # POST
  # /bridges
  # Bridge
  # Create a new bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create
  #
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).
  # @option params [String] :bridgeId Unique ID to give to the bridge being created.
  # @option params [String] :name Name to give to the bridge being created.
  def bridges_create(params = {})
    post "bridges", params
  end

  # POST
  # /bridges/:bridgeId
  # Bridge
  # Create a new bridge or updates an existing one.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-create_or_update_with_id
  #
  # @param [String] bridge_id Unique ID to give to the bridge being created.
  # @param [Hash] params
  # @option params [String] :type Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.
  # @option params [String] :name Set the name of the bridge.
  def bridges_create_or_update_with_id(bridge_id, params = {})
    post "bridges/#{bridge_id}", params
  end

  # GET
  # /bridges/:bridgeId
  # Bridge
  # Get bridge details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-get
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_get(bridge_id)
    get "bridges/#{bridge_id}"
  end

  # DELETE
  # /bridges/:bridgeId
  # void
  # Shut down a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-destroy
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  def bridges_destroy(bridge_id)
    delete "bridges/#{bridge_id}"
  end

  # POST
  # /bridges/:bridgeId/addChannel
  # void
  # Add a channel to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-addChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to add to bridge
  # Allows comma separated values.
  # @option params [String] :role Channel's role in the bridge
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application; Channel currently recording
  # 422 - Channel not in Stasis application
  def bridges_add_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/addChannel", params
  end

  # POST
  # /bridges/:bridgeId/removeChannel
  # void
  # Remove a channel from a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-removeChannel
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :channel *required Ids of channels to remove from bridge. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Channel not found
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  # 422 - Channel not in this bridge
  def bridges_remove_channel(bridge_id, params = {})
    post "bridges/#{bridge_id}/removeChannel", params
  end

  # POST
  # /bridges/:bridgeId/moh
  # void
  # Play music on hold to a bridge or change the MOH class that is playing.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-startMoh
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :mohClass Channel's id
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_start_moh(bridge_id, params = {})
    post "bridges/#{bridge_id}/moh", params
  end

  # DELETE
  # /bridges/:bridgeId/moh
  # void
  # Stop playing music on hold to a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-stopMoh
  #
  # @param [String] bridge_id Bridge's id
  #
  # Error Responses
  # 404 - Bridge not found
  # 409 - Bridge not in Stasis application
  def bridges_stop_moh(bridge_id)
    delete "bridges/#{bridge_id}/moh"
  end

  # POST
  # /bridges/:bridgeId/play
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-play
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback Id.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play(bridge_id, params = {})
    post "bridges/#{bridge_id}/play", params
  end

  # POST
  # /bridges/:bridgeId/play/:playbackId
  # Playback
  # Start playback of media on a bridge.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-playWithId
  #
  # @param [String] bridge_id Bridge's id
  # @param [String] playback_id Playback ID.
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Bridge not found
  # 409 - Bridge not in a Stasis application
  def bridges_play_with_id(bridge_id, playback_id, params = {})
    post "bridges/#{bridge_id}/play/#{playback_id}", params
  end

  # POST
  # /bridges/:bridgeId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Bridges+REST+API#Asterisk12BridgesRESTAPI-record
  #
  # @param [String] bridge_id Bridge's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit.
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit.
  # @option params [String] :ifExists ("fail") Action to take if a recording with the same name already exists.
  # @option params [Boolean] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording.
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Bridge not found
  # 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
  # 422 - The format specified is unknown on this system
  def bridges_record(bridge_id, params = {})
    post "bridges/#{bridge_id}/record", params
  end

  # Channels REST API
  # GET
  # /channels
  # List[Channel]
  # List all active channels in Asterisk.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-list
  #
  def channels_list
    get "channels"
  end

  # POST
  # /channels
  # Channel
  # Create a new channel (originate).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originate
  #
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] :priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :channelId The unique id to assign the channel on creation.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate(params = {})
    post "channels", params
  end

  # GET
  # /channels/:channelId
  # Channel
  # Channel details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-get
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  def channels_get(channel_id)
    get "channels/#{channel_id}"
  end

  # POST
  # /channels/:channelId
  # Channel
  # Create a new channel (originate with id).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-originateWithId
  #
  # @param [String] channel_id The unique id to assign the channel on creation.
  # @param [Hash] params
  # @option params [String] :endpoint *required Endpoint to call.
  # @option params [String] :extension The extension to dial after the endpoint answers
  # @option params [String] :context The context to dial after the endpoint answers. If omitted, uses 'default'
  # @option params [Long] priority The priority to dial after the endpoint answers. If omitted, uses 1
  # @option params [String] :app The application that is subscribed to the originated channel, and passed to the Stasis application.
  # @option params [String] :appArgs The application arguments to pass to the Stasis application.
  # @option params [String] :callerId CallerID to use when dialing the endpoint or extension.
  # @option params [Integer] :timeout (30) Timeout (in seconds) before giving up dialing, or -1 for no timeout.
  # @option params [String] :otherChannelId The unique id to assign the second channel when using local channels.
  #
  # Body parameter
  #
  # 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" } }
  #
  # Error Responses
  #
  # 400 - Invalid parameters for originating a channel.
  def channels_originate_with_id(channel_id, params = {})
    post "channels/#{channel_id}", params
  end

  # DELETE
  # /channels/:channelId
  # void
  # Delete (i.e. hangup) a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hangup
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :reason Reason for hanging up the channel
  #
  # Error Responses
  #
  # 400 - Invalid reason for hangup provided
  # 404 - Channel not found
  def channels_hangup(channel_id, params = {})
    delete "channels/#{channel_id}", params
  end

  # POST
  # /channels/:channelId/continue
  # void
  # Exit application; continue execution in the dialplan.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-continueInDialplan
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :context The context to continue to.
  # @option params [String] :extension The extension to continue to.
  # @option params [Integer] :priority The priority to continue to.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_continue_in_dialplan(channel_id, params = {})
    post "channels/#{channel_id}/continue", params
  end

  # POST
  # /channels/:channelId/answer
  # void
  # Answer a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-answer
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_answer(channel_id)
    post "channels/#{channel_id}/answer"
  end

  # POST
  # /channels/:channelId/ring
  # void
  # Indicate ringing to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ring
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring(channel_id)
    post "channels/#{channel_id}/ring"
  end

  # DELETE
  # /channels/:channelId/ring
  # void
  # Stop ringing indication on a channel if locally generated.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-ringStop
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_ring_stop(channel_id)
    delete "channels/#{channel_id}/ring"
  end

  # POST
  # /channels/:channelId/dtmf
  # void
  # Send provided DTMF to a given channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-sendDTMF
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :dtmf DTMF To send.
  # @option params [Integer] :before Amount of time to wait before DTMF digits (specified in milliseconds) start.
  # @option params [Integer] :between (100) Amount of time in between DTMF digits (specified in milliseconds).
  # @option params [Integer] :duration (100) Length of each DTMF digit (specified in milliseconds).
  # @option params [Integer] :after Amount of time to wait after DTMF digits (specified in milliseconds) end.
  #
  # Error Responses
  #
  # 400 - DTMF is required
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_send_dtmf(channel_id, params = {})
    post "channels/#{channel_id}/dtmf", params
  end

  # POST
  # /channels/:channelId/mute
  # void
  # Mute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-mute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to mute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_mute(channel_id, params = {})
    post "channels/#{channel_id}/mute", params
  end

  # DELETE
  # /channels/:channelId/mute
  # void
  # Unmute a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unmute
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :direction ("both") Direction in which to unmute audio
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unmute(channel_id, params = {})
    delete "channels/#{channel_id}/mute", params
  end

  # POST
  # /channels/:channelId/hold
  # void
  # Hold a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-hold
  #
  # @param [String] channel_id  Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_hold(channel_id)
    post "channels/#{channel_id}/hold"
  end

  # DELETE
  # /channels/:channelId/hold
  # void
  # Remove a channel from hold.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-unhold
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_unhold(channel_id)
    delete "channels/#{channel_id}/hold"
  end

  # POST
  # /channels/:channelId/moh
  # void
  # Play music on hold to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startMoh
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :mohClass Music on hold class to use
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_moh(channel_id, params = {})
    post "channels/#{channel_id}/moh", params
  end

  # DELETE
  # /channels/:channelId/moh
  # void
  # Stop playing music on hold to a channel.
  # POST
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopMoh
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_moh(channel_id)
    delete "channels/#{channel_id}/moh"
  end

  # /channels/:channelId/silence
  # void
  # Play silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-startSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_start_silence(channel_id)
    post "channels/#{channel_id}/silence"
  end

  # DELETE
  # /channels/:channelId/silence
  # void
  # Stop playing silence to a channel.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-stopSilence
  #
  # @param [String] channel_id Channel's id
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_stop_silence(channel_id)
    delete "channels/#{channel_id}/silence"
  end

  # POST
  # /channels/:channelId/play
  # Playback
  # Start playback of media.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-play
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  # @option params [String] :playbackId Playback ID.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play(channel_id, params = {})
    post "channels/#{channel_id}/play", params
  end

  # POST
  # /channels/:channelId/play/:playbackId
  # Playback
  # Start playback of media and specify the playbackId.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-playWithId
  #
  # @param [String] channel_id channel_id
  # @param [String] playback_id playback_id
  # @param [Hash] params
  # @option params [String] :media *required Media's URI to play.
  # @option params [String] :lang For sounds, selects language for sound.
  # @option params [Integer] :offsetms Number of media to skip before playing.
  # @option params [Integer] :skipms (3000) Number of milliseconds to skip for forward/reverse operations.
  #
  # Error Responses
  #
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_play_with_id(channel_id, playback_id, params = {})
    post "channels/#{channel_id}/play/#{playback_id}", params
  end

  # POST
  # /channels/:channelId/record
  # LiveRecording
  # Start a recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-record
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :name *required Recording's filename
  # @option params [String] :format *required Format to encode audio in
  # @option params [Integer] :maxDurationSeconds Maximum duration of the recording, in seconds. 0 for no limit
  # @option params [Integer] :maxSilenceSeconds Maximum duration of silence, in seconds. 0 for no limit
  # @option params [String] :ifExists ("fail") - Action to take if a recording with the same name already exists.
  # @option params [Boolen] :beep Play beep when recording begins
  # @option params [String] :terminateOn ("none") DTMF input to terminate recording
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  # 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
  # 422 - The format specified is unknown on this system
  def channels_record(channel_id, params = {})
    post "channels/#{channel_id}/record", params
  end

  # GET
  # /channels/:channelId/variable
  # Variable
  # Get the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-getChannelVar
  #
  # @param [String] channel_id channel_id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to get
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_get_channel_var(channel_id, params = {})
    get "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/variable
  # void
  # Set the value of a channel variable or function.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-setChannelVar
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :variable *required The channel variable or function to set
  # @option params [String] :value The value to set the variable to
  #
  # Error Responses
  #
  # 400 - Missing variable parameter.
  # 404 - Channel not found
  # 409 - Channel not in a Stasis application
  def channels_set_channel_var(channel_id, params = {})
    post "channels/#{channel_id}/variable", params
  end

  # POST
  # /channels/:channelId/snoop
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannel
  #
  # @param [String] channel_id Channel's id
  # @param [Hash] params
  # @option params [String] :spy ("none") Direction of audio to spy on
  # @option params [String] :whisper ("none") Direction of audio to whisper into
  # @option params [String] :app *required Application the snooping channel is placed into
  # @option params [String] :appArgs The application arguments to pass to the Stasis application
  # @option params [String] :snoopId Unique ID to assign to snooping channel
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel(channel_id, params = {})
    post "channels/#{channel_id}/snoop", params
  end

  # POST
  # /channels/:channelId/snoop/:snoopId
  # Channel
  # Start snooping.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Channels+REST+API#Asterisk12ChannelsRESTAPI-snoopChannelWithId
  #
  # @param [String] channel_id Channel's id
  # @param [String] snoop_id Unique ID to assign to snooping channel
  # @param [Hash] params
  # @option param [String] :spy ("none") Direction of audio to spy on
  # @option param [String] :whisper ("none") Direction of audio to whisper into
  # @option param [String] :app *required Application the snooping channel is placed into
  # @option param [String] :appArgs The application arguments to pass to the Stasis application
  #
  # Error Responses
  #
  # 400 - Invalid parameters
  # 404 - Channel not found
  def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
    post "channels/#{channel_id}/snoop/#{snoop_id}", params
  end

  # Endpoints REST API

  # GET
  # /endpoints
  # List[Endpoint]
  # List all endpoints.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-list
  def endpoints_list
    get "endpoints"
  end

  # PUT
  # /endpoints/sendMessage
  # void
  # Send a message to some technology URI or endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessage
  #
  # @param [Hash] params
  # @option param [String] to *required The endpoint resource or technology specific URI to send the message to. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option param [String] body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 404 - Endpoint not found
  def endpoints_send_message(params = {})
    put "endpoints/sendMessage", params
  end

  # GET
  # /endpoints/:tech
  # List[Endpoint]
  # List available endoints for a given endpoint technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-listByTech
  #
  # @param [String] tech Technology of the endpoints (sip,iax2,...)
  #
  # Error Responses
  #
  # 404 - Endpoints not found
  def endpoints_list_by_tech(tech)
    get "endpoints/#{tech}"
  end

  # GET
  # /endpoints/:tech/:resource
  # Endpoint
  # Details for an endpoint.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-get
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoints not found
  def endpoints_get(tech, resource)
    get "endpoints/#{tech}/#{resource}"
  end

  # PUT
  # /endpoints/:tech/:resource/sendMessage
  # void
  # Send a message to some endpoint in a technology.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Endpoints+REST+API#Asterisk12EndpointsRESTAPI-sendMessageToEndpoint
  #
  # @param [String] tech Technology of the endpoint
  # @param [String] resource ID of the endpoint
  # @param [Hash] params
  # @option params [String] :from *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.
  # @option params [String] :body The body of the message
  #
  # Body parameter
  #
  # variables: containers -
  #
  # Error Responses
  #
  # 400 - Invalid parameters for sending a message.
  # 404 - Endpoint not found
  def endpoints_send_message_to_endpoint(tech, resource, params = {})
    put "endpoints/#{tech}/#{resource}/sendMessage", params
  end

  # TODO
  # # Events REST API

  # # GET
  # # /events
  # # Message
  # # WebSocket connection for events.
  # #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-eventWebsocket
  # def events_event_websocket
  #   get "events"
  # end

  # POST
  # /events/user/:eventName
  # void
  # Generate a user event.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Events+REST+API#Asterisk12EventsRESTAPI-userEvent
  #
  # @param [String] event_name event_name
  # @param [Hash] params
  # @option param [String] application #required The name of the application that will receive this event
  # @option param [String] source URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}/{resource}, deviceState:{deviceName}. Allows comma separated values.
  #
  # Body parameter
  #
  # variables: containers - The "variables" key in the body object holds custom key/value pairs to add to the user event. Ex. { "variables": { "key": "value" } }
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  # 422 - Event source not found.
  # 400 - Invalid even tsource URI or userevent data.
  def events_user_event(event_name, params = {})
    post "events/user/#{event_name}", params
  end

  # Recordings REST API

  # GET
  # /recordings/stored
  # List[StoredRecording]
  # List recordings that are complete.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-listStored
  def recordings_list_stored
    get "recordings/stored"
  end

  # GET
  #
  # /recordings/stored/:recordingName
  #
  # StoredRecording
  # Get a stored recording's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_stored(recording_name)
    get "recordings/stored/#{recording_name}"
  end

  # DELETE
  # /recordings/stored/:recordingName
  # void
  # Delete a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-deleteStored
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_delete_stored(recording_name)
    delete "recordings/stored/#{recording_name}"
  end

  # POST
  # /recordings/stored/:recordingName/copy
  # StoredRecording
  # Copy a stored recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-copyStored
  #
  # @param [String] recording_name The name of the recording to copy
  # @param [Hash] params
  # @option params [String] :destinationRecordingName *required The destination name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - A recording with the same name already exists on the system
  def recordings_copy_stored(recording_name, params = {})
    post "recordings/stored/#{recording_name}/copy", params
  end

  # GET
  # /recordings/live/:recordingName
  # LiveRecording
  # List live recordings.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-getLive
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_get_live(recording_name)
    get "recordings/live/#{recording_name}"
  end

  # DELETE
  # /recordings/live/:recordingName
  # void
  # Stop a live recording and discard it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-cancel
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_cancel(recording_name)
    delete "recordings/live/#{recording_name}"
  end

  # POST
  # /recordings/live/:recordingName/stop
  # void
  # Stop a live recording and store it.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-stop
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  def recordings_stop(recording_name)
    post "recordings/live/#{recording_name}/stop"
  end

  # POST
  # /recordings/live/:recordingName/pause
  # void
  # Pause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-pause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_pause(recording_name)
    post "recordings/live/#{recording_name}/pause"
  end

  # DELETE
  # /recordings/live/:recordingName/pause
  # void
  # Unpause a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unpause
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unpause(recording_name)
    delete "recordings/live/#{recording_name}/pause"
  end

  # POST
  # /recordings/live/:recordingName/mute
  # void
  # Mute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-mute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_mute(recording_name)
    post "recordings/live/#{recording_name}/mute"
  end

  # DELETE
  # /recordings/live/:recordingName/mute
  # void
  # Unmute a live recording.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Recordings+REST+API#Asterisk12RecordingsRESTAPI-unmute
  #
  # @param [String] recording_name The name of the recording
  #
  # Error Responses
  #
  # 404 - Recording not found
  # 409 - Recording not in session
  def recordings_unmute(recording_name)
    delete "recordings/live/#{recording_name}/mute"
  end

  # Sounds REST API

  # GET
  # /sounds
  # List[Sound]
  # List all sounds.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-list
  #
  # @param [Hash] params
  # @option param [String] lang Lookup sound for a specific language.
  # @option param [String] format Lookup sound in a specific format.
  def sounds_list(params = {})
    get "sounds", params
  end

  # GET
  # /sounds/:soundId
  # Sound
  # Get a sound's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Sounds+REST+API#Asterisk12SoundsRESTAPI-get
  #
  # @param [String] sound_id Sound's id
  def sounds_get(sound_id)
    get "sounds/#{sound_id}"
  end

  # Applications REST API

  # GET
  # /applications
  # List[Application]
  # List all applications.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-list
  def applications_list
    get "applications"
  end

  # GET
  # /applications/:applicationName
  # Application
  # Get details of an application.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-get
  #
  # @param [String] application_name Application's name
  #
  # Error Responses
  #
  # 404 - Application does not exist.
  def applications_get(application_name)
    get "applications/#{application_name}"
  end

  # POST
  # /applications/:applicationName/subscription
  # Application
  # Subscribe an application to a event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-subscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 422 - Event source does not exist.
  def applications_subscribe(application_name, params = {})
    post "applications/#{application_name}/subscription", params
  end

  # DELETE
  # /applications/:applicationName/subscription
  # Application
  # Unsubscribe an application from an event source.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Applications+REST+API#Asterisk12ApplicationsRESTAPI-unsubscribe
  #
  # @param [String] application_name Application's name
  # @param [Hash] params
  # @option params [String] :eventSource *required URI for event source (channel:{channelId}, bridge:{bridgeId}, endpoint:{tech}[/{resource}], deviceState:{deviceName}. Allows comma separated values.
  #
  # Error Responses
  #
  # 400 - Missing parameter.
  # 404 - Application does not exist.
  # 409 - Application not subscribed to event source.
  # 422 - Event source does not exist.
  def applications_unsubscribe(application_name, params = {})
    delete "applications/#{application_name}/subscription", params
  end

  # Playbacks REST API

  # GET
  # /playbacks/:playbackId
  # Playback
  # Get a playback's details.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-get
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_get(playback_id)
    get "playbacks/#{playback_id}"
  end

  # DELETE
  # /playbacks/:playbackId
  # void
  # Stop a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-stop
  #
  # @param [String] playback_id Playback's id
  #
  # Error Responses
  #
  # 404 - The playback cannot be found
  def playbacks_stop(playback_id)
    delete "playbacks/#{playback_id}"
  end

  # POST
  # /playbacks/:playbackId/control
  # void
  # Control a playback.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Playbacks+REST+API#Asterisk12PlaybacksRESTAPI-control
  #
  # @param [String] playback_id Playback's id
  # @param [Hash] params
  # @option params [String] :operation *required Operation to perform on the playback.
  #
  # Error Responses
  #
  # 400 - The provided operation parameter was invalid
  # 404 - The playback cannot be found
  # 409 - The operation cannot be performed in the playback's current state
  def playbacks_control(playback_id, params = {})
    post "playbacks/#{playback_id}/control", params
  end

  # Devicestates REST API

  # GET
  # /deviceStates
  # List[DeviceState]
  # List all ARI controlled device states.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-list
  def device_states_list
    get "deviceStates"
  end

  # GET
  # /deviceStates/:deviceName
  # DeviceState
  # Retrieve the current state of a device.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-get
  #
  # @param [String] device_name Name of the device
  def device_states_get(device_name)
    get "deviceStates/#{device_name}"
  end

  # PUT
  # /deviceStates/:deviceName
  # void
  # Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-update
  #
  # @param [String] device_name Name of the device
  # @param [Hash] params
  # @option params [String] :deviceState *required Device state value
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_update(device_name, params = {})
    put "deviceStates/#{device_name}", params
  end

  # DELETE
  # /deviceStates/:deviceName
  # void
  # Destroy a device-state controlled by ARI.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Devicestates+REST+API#Asterisk12DevicestatesRESTAPI-delete
  #
  # @param [String] device_name Name of the device
  #
  # Error Responses
  #
  # 404 - Device name is missing
  # 409 - Uncontrolled device specified
  def device_states_delete(device_name)
    delete "deviceStates/#{device_name}"
  end

  # Mailboxes REST API

  # GET
  # /mailboxes
  # List[Mailbox]
  # List all mailboxes.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-list
  def mailboxes_list
    get "mailboxes"
  end

  # GET
  # /mailboxes/:mailboxName
  # Mailbox
  # Retrieve the current state of a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-get
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_get(mailbox_name)
    get "mailboxes/#{mailbox_name}"
  end

  # PUT
  # /mailboxes/:mailboxName
  # void
  # Change the state of a mailbox. (Note - implicitly creates the mailbox).
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-update
  #
  # @param [String] mailbox_name Name of the mailbox
  # @param [Hash] params
  # @option params [Integer] :oldMessages *required Count of old messages in the mailbox
  # @option params [Integer] :newMessages *required Count of new messages in the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_update(mailbox_name, params = {})
    put "mailboxes/#{mailbox_name}", params
  end

  # DELETE
  # /mailboxes/:mailboxName
  # void
  # Destroy a mailbox.
  #
  # @see https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+Mailboxes+REST+API#Asterisk12MailboxesRESTAPI-delete
  #
  # @param [String] mailbox_name Name of the mailbox
  #
  # Error Responses
  #
  # 404 - Mailbox not found
  def mailboxes_delete(mailbox_name)
    delete "mailboxes/#{mailbox_name}"
  end

  private

    def api_call(path, args = {}, verb = "get", options = {}, &error_checking_block)
      # Setup args for make_request
      path = "/ari/#{path}" unless path =~ /^\//
      path = "/#{@prefix}#{path}" if @prefix

      options.merge!({:host => @host, :port => @port, :username => @username, :password => @password})
      # Make request via the provided service
      result = ARI.make_request path, args, verb, options

      if result.status >= 500
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body
        }
        raise ARI::ServerError.new(result.body, error_detail)
      elsif result.status >= 400
        error_detail = {
          :http_status => result.status.to_i,
          :body        => result.body,
          :data        => ARI::JSON.load(result.body)
        }
        raise ARI::APIError.new(result.body, error_detail)
      end

      # Parse the body
      body = if result.headers["Content-Type"] && result.headers["Content-Type"].match("json")
        ARI::JSON.load result.body.to_s
      else
        result.body.to_s
      end
      # Return result
      if options[:http_component]
        result.send options[:http_component]
      else
        body
      end
    end

end

Instance Method Details

#applications_get(application_name) ⇒ Object

GET /applications/:applicationName Application Get details of an application.

Error Responses

404 - Application does not exist.

Parameters:

  • application_name (String)

    Application’s name

See Also:



1184
1185
1186
# File 'lib/ari/client.rb', line 1184

def applications_get(application_name)
  get "applications/#{application_name}"
end

#applications_listObject

GET /applications List List all applications.



1168
1169
1170
# File 'lib/ari/client.rb', line 1168

def applications_list
  get "applications"
end

#applications_subscribe(application_name, params = {}) ⇒ Object

POST /applications/:applicationName/subscription Application Subscribe an application to a event source.

Error Responses

400 - Missing parameter. 404 - Application does not exist. 422 - Event source does not exist.

Parameters:

  • application_name (String)

    Application’s name

  • params (Hash) (defaults to: {})

Options Hash (params):

See Also:



1204
1205
1206
# File 'lib/ari/client.rb', line 1204

def applications_subscribe(application_name, params = {})
  post "applications/#{application_name}/subscription", params
end

#applications_unsubscribe(application_name, params = {}) ⇒ Object

DELETE /applications/:applicationName/subscription Application Unsubscribe an application from an event source.

Error Responses

400 - Missing parameter. 404 - Application does not exist. 409 - Application not subscribed to event source. 422 - Event source does not exist.

Parameters:

  • application_name (String)

    Application’s name

  • params (Hash) (defaults to: {})

Options Hash (params):

See Also:



1225
1226
1227
# File 'lib/ari/client.rb', line 1225

def applications_unsubscribe(application_name, params = {})
  delete "applications/#{application_name}/subscription", params
end

#asterisk_get_global_var(params = {}) ⇒ Object

GET /asterisk/variable Variable Get the value of a global variable.

Error Responses

return 400 - Missing variable parameter.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • variable (String)

    *required The variable to get

See Also:



65
66
67
# File 'lib/ari/client.rb', line 65

def asterisk_get_global_var(params = {})
  get "asterisk/variable", params
end

#asterisk_get_infoObject

GET /asterisk/info AsteriskInfo Gets Asterisk system information.

Parameters:

  • only (String)

    Filter information returned. Allows comma separated values.

See Also:



48
49
50
# File 'lib/ari/client.rb', line 48

def asterisk_get_info
  get "asterisk/info"
end

#asterisk_set_global_var(params = {}) ⇒ Object

POST /asterisk/variable void Set the value of a global variable.

Error Responses 400 - Missing variable parameter.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :variable (String)

    *required The variable to set

  • :value (String)

    The value to set the variable to

See Also:



82
83
84
# File 'lib/ari/client.rb', line 82

def asterisk_set_global_var(params = {})
  post "asterisk/variable", params
end

#bridges_add_channel(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/addChannel void Add a channel to a bridge.

Allows comma separated values. Error Responses

400 - Channel not found 404 - Bridge not found 409 - Bridge not in Stasis application; Channel currently recording 422 - Channel not in Stasis application

Parameters:

  • bridge_id (String)

    Bridge’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :channel (String)

    *required Ids of channels to add to bridge

  • :role (String)

    Channel’s role in the bridge

See Also:



181
182
183
# File 'lib/ari/client.rb', line 181

def bridges_add_channel(bridge_id, params = {})
  post "bridges/#{bridge_id}/addChannel", params
end

#bridges_create(params = {}) ⇒ Object

POST /bridges Bridge Create a new bridge.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :type (String)

    Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media).

  • :bridgeId (String)

    Unique ID to give to the bridge being created.

  • :name (String)

    Name to give to the bridge being created.

See Also:



111
112
113
# File 'lib/ari/client.rb', line 111

def bridges_create(params = {})
  post "bridges", params
end

#bridges_create_or_update_with_id(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId Bridge Create a new bridge or updates an existing one.

Parameters:

  • bridge_id (String)

    Unique ID to give to the bridge being created.

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :type (String)

    Comma separated list of bridge type attributes (mixing, holding, dtmf_events, proxy_media) to set.

  • :name (String)

    Set the name of the bridge.

See Also:



126
127
128
# File 'lib/ari/client.rb', line 126

def bridges_create_or_update_with_id(bridge_id, params = {})
  post "bridges/#{bridge_id}", params
end

#bridges_destroy(bridge_id) ⇒ Object

DELETE /bridges/:bridgeId void Shut down a bridge.

Error Responses

404 - Bridge not found



158
159
160
# File 'lib/ari/client.rb', line 158

def bridges_destroy(bridge_id)
  delete "bridges/#{bridge_id}"
end

#bridges_get(bridge_id) ⇒ Object

GET /bridges/:bridgeId Bridge Get bridge details.

Error Responses

404 - Bridge not found



142
143
144
# File 'lib/ari/client.rb', line 142

def bridges_get(bridge_id)
  get "bridges/#{bridge_id}"
end

#bridges_listObject

GET /bridges List List all active bridges in Asterisk.



96
97
98
# File 'lib/ari/client.rb', line 96

def bridges_list
  get "bridges"
end

#bridges_play(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/play Playback Start playback of media on a bridge.

Error Responses

404 - Bridge not found 409 - Bridge not in a Stasis application

Parameters:

  • bridge_id (String)

    Bridge’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :media (String)

    *required Media’s URI to play.

  • :lang (String)

    For sounds, selects language for sound.

  • :offsetms (Integer)

    Number of media to skip before playing.

  • :skipms (Integer) — default: 3000

    Number of milliseconds to skip for forward/reverse operations.

  • :playbackId (String)

    Playback Id.

See Also:



260
261
262
# File 'lib/ari/client.rb', line 260

def bridges_play(bridge_id, params = {})
  post "bridges/#{bridge_id}/play", params
end

#bridges_play_with_id(bridge_id, playback_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/play/:playbackId Playback Start playback of media on a bridge.

Error Responses

404 - Bridge not found 409 - Bridge not in a Stasis application

Parameters:

  • bridge_id (String)

    Bridge’s id

  • playback_id (String)

    Playback ID.

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :media (String)

    *required Media’s URI to play.

  • :lang (String)

    For sounds, selects language for sound.

  • :offsetms (Integer)

    Number of media to skip before playing.

  • :skipms (Integer) — default: 3000

    Number of milliseconds to skip for forward/reverse operations.

See Also:



283
284
285
# File 'lib/ari/client.rb', line 283

def bridges_play_with_id(bridge_id, playback_id, params = {})
  post "bridges/#{bridge_id}/play/#{playback_id}", params
end

#bridges_record(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/record LiveRecording Start a recording.

Error Responses

400 - Invalid parameters 404 - Bridge not found 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 422 - The format specified is unknown on this system

Parameters:

  • bridge_id (String)

    Bridge’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :name (String)

    *required Recording’s filename

  • :format (String)

    *required Format to encode audio in

  • :maxDurationSeconds (Integer)

    Maximum duration of the recording, in seconds. 0 for no limit.

  • :maxSilenceSeconds (Integer)

    Maximum duration of silence, in seconds. 0 for no limit.

  • :ifExists (String) — default: "fail"

    Action to take if a recording with the same name already exists.

  • :beep (Boolean)

    Play beep when recording begins

  • :terminateOn (String) — default: "none"

    DTMF input to terminate recording.

See Also:



310
311
312
# File 'lib/ari/client.rb', line 310

def bridges_record(bridge_id, params = {})
  post "bridges/#{bridge_id}/record", params
end

#bridges_remove_channel(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/removeChannel void Remove a channel from a bridge.

Error Responses

400 - Channel not found 404 - Bridge not found 409 - Bridge not in Stasis application 422 - Channel not in this bridge

Parameters:

  • bridge_id (String)

    Bridge’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :channel (String)

    *required Ids of channels to remove from bridge. Allows comma separated values.

See Also:



202
203
204
# File 'lib/ari/client.rb', line 202

def bridges_remove_channel(bridge_id, params = {})
  post "bridges/#{bridge_id}/removeChannel", params
end

#bridges_start_moh(bridge_id, params = {}) ⇒ Object

POST /bridges/:bridgeId/moh void Play music on hold to a bridge or change the MOH class that is playing.

Error Responses

404 - Bridge not found 409 - Bridge not in Stasis application

Parameters:

  • bridge_id (String)

    Bridge’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :mohClass (String)

    Channel’s id

See Also:



221
222
223
# File 'lib/ari/client.rb', line 221

def bridges_start_moh(bridge_id, params = {})
  post "bridges/#{bridge_id}/moh", params
end

#bridges_stop_moh(bridge_id) ⇒ Object

DELETE /bridges/:bridgeId/moh void Stop playing music on hold to a bridge.

Error Responses 404 - Bridge not found 409 - Bridge not in Stasis application



237
238
239
# File 'lib/ari/client.rb', line 237

def bridges_stop_moh(bridge_id)
  delete "bridges/#{bridge_id}/moh"
end

#channels_answer(channel_id) ⇒ Object

POST /channels/:channelId/answer void Answer a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



455
456
457
# File 'lib/ari/client.rb', line 455

def channels_answer(channel_id)
  post "channels/#{channel_id}/answer"
end

#channels_continue_in_dialplan(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/continue void Exit application; continue execution in the dialplan.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :context (String)

    The context to continue to.

  • :extension (String)

    The extension to continue to.

  • :priority (Integer)

    The priority to continue to.

See Also:



438
439
440
# File 'lib/ari/client.rb', line 438

def channels_continue_in_dialplan(channel_id, params = {})
  post "channels/#{channel_id}/continue", params
end

#channels_get(channel_id) ⇒ Object

GET /channels/:channelId Channel Channel details.

Error Responses

404 - Channel not found



368
369
370
# File 'lib/ari/client.rb', line 368

def channels_get(channel_id)
  get "channels/#{channel_id}"
end

#channels_get_channel_var(channel_id, params = {}) ⇒ Object

GET /channels/:channelId/variable Variable Get the value of a channel variable or function.

Error Responses

400 - Missing variable parameter. 404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    channel_id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :variable (String)

    *required The channel variable or function to get

See Also:



748
749
750
# File 'lib/ari/client.rb', line 748

def channels_get_channel_var(channel_id, params = {})
  get "channels/#{channel_id}/variable", params
end

#channels_hangup(channel_id, params = {}) ⇒ Object

DELETE /channels/:channelId void Delete (i.e. hangup) a channel.

Error Responses

400 - Invalid reason for hangup provided 404 - Channel not found

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :reason (String)

    Reason for hanging up the channel

See Also:



417
418
419
# File 'lib/ari/client.rb', line 417

def channels_hangup(channel_id, params = {})
  delete "channels/#{channel_id}", params
end

#channels_hold(channel_id) ⇒ Object

POST /channels/:channelId/hold void Hold a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



568
569
570
# File 'lib/ari/client.rb', line 568

def channels_hold(channel_id)
  post "channels/#{channel_id}/hold"
end

#channels_listObject

Channels REST API GET /channels List List all active channels in Asterisk.



322
323
324
# File 'lib/ari/client.rb', line 322

def channels_list
  get "channels"
end

#channels_mute(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/mute void Mute a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :direction (String) — default: "both"

    Direction in which to mute audio

See Also:



532
533
534
# File 'lib/ari/client.rb', line 532

def channels_mute(channel_id, params = {})
  post "channels/#{channel_id}/mute", params
end

#channels_originate(params = {}) ⇒ Object

POST /channels Channel Create a new channel (originate).

Body parameter

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” } }

Error Responses

400 - Invalid parameters for originating a channel.

Parameters:

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :endpoint (String)

    *required Endpoint to call.

  • :extension (String)

    The extension to dial after the endpoint answers

  • :context (String)

    The context to dial after the endpoint answers. If omitted, uses ‘default’

  • :priority (Long)

    The priority to dial after the endpoint answers. If omitted, uses 1

  • :app (String)

    The application that is subscribed to the originated channel, and passed to the Stasis application.

  • :appArgs (String)

    The application arguments to pass to the Stasis application.

  • :callerId (String)

    CallerID to use when dialing the endpoint or extension.

  • :timeout (Integer) — default: 30

    Timeout (in seconds) before giving up dialing, or -1 for no timeout.

  • :channelId (String)

    The unique id to assign the channel on creation.

  • :otherChannelId (String)

    The unique id to assign the second channel when using local channels.

See Also:



352
353
354
# File 'lib/ari/client.rb', line 352

def channels_originate(params = {})
  post "channels", params
end

#channels_originate_with_id(channel_id, params = {}) ⇒ Object

POST /channels/:channelId Channel Create a new channel (originate with id).

Body parameter

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” } }

Error Responses

400 - Invalid parameters for originating a channel.

Parameters:

  • channel_id (String)

    The unique id to assign the channel on creation.

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :endpoint (String)

    *required Endpoint to call.

  • :extension (String)

    The extension to dial after the endpoint answers

  • :context (String)

    The context to dial after the endpoint answers. If omitted, uses ‘default’

  • priority (Long)

    The priority to dial after the endpoint answers. If omitted, uses 1

  • :app (String)

    The application that is subscribed to the originated channel, and passed to the Stasis application.

  • :appArgs (String)

    The application arguments to pass to the Stasis application.

  • :callerId (String)

    CallerID to use when dialing the endpoint or extension.

  • :timeout (Integer) — default: 30

    Timeout (in seconds) before giving up dialing, or -1 for no timeout.

  • :otherChannelId (String)

    The unique id to assign the second channel when using local channels.

See Also:



398
399
400
# File 'lib/ari/client.rb', line 398

def channels_originate_with_id(channel_id, params = {})
  post "channels/#{channel_id}", params
end

#channels_play(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/play Playback Start playback of media.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :media (String)

    *required Media’s URI to play.

  • :lang (String)

    For sounds, selects language for sound.

  • :offsetms (Integer)

    Number of media to skip before playing.

  • :skipms (Integer) — default: 3000

    Number of milliseconds to skip for forward/reverse operations.

  • :playbackId (String)

    Playback ID.

See Also:



678
679
680
# File 'lib/ari/client.rb', line 678

def channels_play(channel_id, params = {})
  post "channels/#{channel_id}/play", params
end

#channels_play_with_id(channel_id, playback_id, params = {}) ⇒ Object

POST /channels/:channelId/play/:playbackId Playback Start playback of media and specify the playbackId.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    channel_id

  • playback_id (String)

    playback_id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :media (String)

    *required Media’s URI to play.

  • :lang (String)

    For sounds, selects language for sound.

  • :offsetms (Integer)

    Number of media to skip before playing.

  • :skipms (Integer) — default: 3000

    Number of milliseconds to skip for forward/reverse operations.

See Also:



701
702
703
# File 'lib/ari/client.rb', line 701

def channels_play_with_id(channel_id, playback_id, params = {})
  post "channels/#{channel_id}/play/#{playback_id}", params
end

#channels_record(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/record LiveRecording Start a recording.

Error Responses

400 - Invalid parameters 404 - Channel not found 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 422 - The format specified is unknown on this system

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :name (String)

    *required Recording’s filename

  • :format (String)

    *required Format to encode audio in

  • :maxDurationSeconds (Integer)

    Maximum duration of the recording, in seconds. 0 for no limit

  • :maxSilenceSeconds (Integer)

    Maximum duration of silence, in seconds. 0 for no limit

  • :ifExists (String) — default: "fail"
    • Action to take if a recording with the same name already exists.

  • :beep (Boolen)

    Play beep when recording begins

  • :terminateOn (String) — default: "none"

    DTMF input to terminate recording

See Also:



728
729
730
# File 'lib/ari/client.rb', line 728

def channels_record(channel_id, params = {})
  post "channels/#{channel_id}/record", params
end

#channels_ring(channel_id) ⇒ Object

POST /channels/:channelId/ring void Indicate ringing to a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



472
473
474
# File 'lib/ari/client.rb', line 472

def channels_ring(channel_id)
  post "channels/#{channel_id}/ring"
end

#channels_ring_stop(channel_id) ⇒ Object

DELETE /channels/:channelId/ring void Stop ringing indication on a channel if locally generated.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



489
490
491
# File 'lib/ari/client.rb', line 489

def channels_ring_stop(channel_id)
  delete "channels/#{channel_id}/ring"
end

#channels_send_dtmf(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/dtmf void Send provided DTMF to a given channel.

Error Responses

400 - DTMF is required 404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :dtmf (String)

    DTMF To send.

  • :before (Integer)

    Amount of time to wait before DTMF digits (specified in milliseconds) start.

  • :between (Integer) — default: 100

    Amount of time in between DTMF digits (specified in milliseconds).

  • :duration (Integer) — default: 100

    Length of each DTMF digit (specified in milliseconds).

  • :after (Integer)

    Amount of time to wait after DTMF digits (specified in milliseconds) end.

See Also:



513
514
515
# File 'lib/ari/client.rb', line 513

def channels_send_dtmf(channel_id, params = {})
  post "channels/#{channel_id}/dtmf", params
end

#channels_set_channel_var(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/variable void Set the value of a channel variable or function.

Error Responses

400 - Missing variable parameter. 404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :variable (String)

    *required The channel variable or function to set

  • :value (String)

    The value to set the variable to

See Also:



769
770
771
# File 'lib/ari/client.rb', line 769

def channels_set_channel_var(channel_id, params = {})
  post "channels/#{channel_id}/variable", params
end

#channels_snoop_channel(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/snoop Channel Start snooping.

Error Responses

400 - Invalid parameters 404 - Channel not found

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :spy (String) — default: "none"

    Direction of audio to spy on

  • :whisper (String) — default: "none"

    Direction of audio to whisper into

  • :app (String)

    *required Application the snooping channel is placed into

  • :appArgs (String)

    The application arguments to pass to the Stasis application

  • :snoopId (String)

    Unique ID to assign to snooping channel

See Also:



792
793
794
# File 'lib/ari/client.rb', line 792

def channels_snoop_channel(channel_id, params = {})
  post "channels/#{channel_id}/snoop", params
end

#channels_snoop_channel_with_id(channel_id, snoop_id, params = {}) ⇒ Object

POST /channels/:channelId/snoop/:snoopId Channel Start snooping.

Error Responses

400 - Invalid parameters 404 - Channel not found

Parameters:

  • channel_id (String)

    Channel’s id

  • snoop_id (String)

    Unique ID to assign to snooping channel

  • params (Hash) (defaults to: {})
  • param (Hash)

    a customizable set of options

See Also:



815
816
817
# File 'lib/ari/client.rb', line 815

def channels_snoop_channel_with_id(channel_id, snoop_id, params = {})
  post "channels/#{channel_id}/snoop/#{snoop_id}", params
end

#channels_start_moh(channel_id, params = {}) ⇒ Object

POST /channels/:channelId/moh void Play music on hold to a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :mohClass (String)

    Music on hold class to use

See Also:



604
605
606
# File 'lib/ari/client.rb', line 604

def channels_start_moh(channel_id, params = {})
  post "channels/#{channel_id}/moh", params
end

#channels_start_silence(channel_id) ⇒ Object

/channels/:channelId/silence void Play silence to a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



638
639
640
# File 'lib/ari/client.rb', line 638

def channels_start_silence(channel_id)
  post "channels/#{channel_id}/silence"
end

#channels_stop_moh(channel_id) ⇒ Object

DELETE /channels/:channelId/moh void Stop playing music on hold to a channel. POST

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



622
623
624
# File 'lib/ari/client.rb', line 622

def channels_stop_moh(channel_id)
  delete "channels/#{channel_id}/moh"
end

#channels_stop_silence(channel_id) ⇒ Object

DELETE /channels/:channelId/silence void Stop playing silence to a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



655
656
657
# File 'lib/ari/client.rb', line 655

def channels_stop_silence(channel_id)
  delete "channels/#{channel_id}/silence"
end

#channels_unhold(channel_id) ⇒ Object

DELETE /channels/:channelId/hold void Remove a channel from hold.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application



585
586
587
# File 'lib/ari/client.rb', line 585

def channels_unhold(channel_id)
  delete "channels/#{channel_id}/hold"
end

#channels_unmute(channel_id, params = {}) ⇒ Object

DELETE /channels/:channelId/mute void Unmute a channel.

Error Responses

404 - Channel not found 409 - Channel not in a Stasis application

Parameters:

  • channel_id (String)

    Channel’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :direction (String) — default: "both"

    Direction in which to unmute audio

See Also:



551
552
553
# File 'lib/ari/client.rb', line 551

def channels_unmute(channel_id, params = {})
  delete "channels/#{channel_id}/mute", params
end

#device_states_delete(device_name) ⇒ Object

DELETE /deviceStates/:deviceName void Destroy a device-state controlled by ARI.

Error Responses

404 - Device name is missing 409 - Uncontrolled device specified



1339
1340
1341
# File 'lib/ari/client.rb', line 1339

def device_states_delete(device_name)
  delete "deviceStates/#{device_name}"
end

#device_states_get(device_name) ⇒ Object

GET /deviceStates/:deviceName DeviceState Retrieve the current state of a device.



1303
1304
1305
# File 'lib/ari/client.rb', line 1303

def device_states_get(device_name)
  get "deviceStates/#{device_name}"
end

#device_states_listObject

GET /deviceStates List List all ARI controlled device states.



1291
1292
1293
# File 'lib/ari/client.rb', line 1291

def device_states_list
  get "deviceStates"
end

#device_states_update(device_name, params = {}) ⇒ Object

PUT /deviceStates/:deviceName void Change the state of a device controlled by ARI. (Note - implicitly creates the device state).

Error Responses

404 - Device name is missing 409 - Uncontrolled device specified

Parameters:

  • device_name (String)

    Name of the device

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :deviceState (String)

    *required Device state value

See Also:



1322
1323
1324
# File 'lib/ari/client.rb', line 1322

def device_states_update(device_name, params = {})
  put "deviceStates/#{device_name}", params
end

#endpoints_get(tech, resource) ⇒ Object

GET /endpoints/:tech/:resource Endpoint Details for an endpoint.

Error Responses

400 - Invalid parameters for sending a message. 404 - Endpoints not found

Parameters:

  • tech (String)

    Technology of the endpoint

  • resource (String)

    ID of the endpoint

See Also:



884
885
886
# File 'lib/ari/client.rb', line 884

def endpoints_get(tech, resource)
  get "endpoints/#{tech}/#{resource}"
end

#endpoints_listObject

GET /endpoints List List all endpoints.



827
828
829
# File 'lib/ari/client.rb', line 827

def endpoints_list
  get "endpoints"
end

#endpoints_list_by_tech(tech) ⇒ Object

GET /endpoints/:tech List List available endoints for a given endpoint technology.

Error Responses

404 - Endpoints not found

Parameters:

  • tech (String)

    Technology of the endpoints (sip,iax2,…)

See Also:



866
867
868
# File 'lib/ari/client.rb', line 866

def endpoints_list_by_tech(tech)
  get "endpoints/#{tech}"
end

#endpoints_send_message(params = {}) ⇒ Object

PUT /endpoints/sendMessage void Send a message to some technology URI or endpoint.

Body parameter

variables: containers -

Error Responses

404 - Endpoint not found

Parameters:

  • params (Hash) (defaults to: {})
  • param (Hash)

    a customizable set of options

See Also:



850
851
852
# File 'lib/ari/client.rb', line 850

def endpoints_send_message(params = {})
  put "endpoints/sendMessage", params
end

#endpoints_send_message_to_endpoint(tech, resource, params = {}) ⇒ Object

PUT /endpoints/:tech/:resource/sendMessage void Send a message to some endpoint in a technology.

Body parameter

variables: containers -

Error Responses

400 - Invalid parameters for sending a message. 404 - Endpoint not found

Parameters:

  • tech (String)

    Technology of the endpoint

  • resource (String)

    ID of the endpoint

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :from (String)

    *required The endpoint resource or technology specific identity to send this message from. Valid resources are sip, pjsip, and xmpp.

  • :body (String)

    The body of the message

See Also:



909
910
911
# File 'lib/ari/client.rb', line 909

def endpoints_send_message_to_endpoint(tech, resource, params = {})
  put "endpoints/#{tech}/#{resource}/sendMessage", params
end

#events_user_event(event_name, params = {}) ⇒ Object

POST /events/user/:eventName void Generate a user event.

Body parameter

variables: containers - The “variables” key in the body object holds custom key/value pairs to add to the user event. Ex. { “variables”: { “key”: “value” } }

Error Responses

404 - Application does not exist. 422 - Event source not found. 400 - Invalid even tsource URI or userevent data.

Parameters:

  • event_name (String)

    event_name

  • params (Hash) (defaults to: {})
  • param (Hash)

    a customizable set of options

See Also:



947
948
949
# File 'lib/ari/client.rb', line 947

def events_user_event(event_name, params = {})
  post "events/user/#{event_name}", params
end

#mailboxes_delete(mailbox_name) ⇒ Object

DELETE /mailboxes/:mailboxName void Destroy a mailbox.

Error Responses

404 - Mailbox not found



1402
1403
1404
# File 'lib/ari/client.rb', line 1402

def mailboxes_delete(mailbox_name)
  delete "mailboxes/#{mailbox_name}"
end

#mailboxes_get(mailbox_name) ⇒ Object

GET /mailboxes/:mailboxName Mailbox Retrieve the current state of a mailbox.

Error Responses

404 - Mailbox not found

Parameters:

  • mailbox_name (String)

    Name of the mailbox

See Also:



1367
1368
1369
# File 'lib/ari/client.rb', line 1367

def mailboxes_get(mailbox_name)
  get "mailboxes/#{mailbox_name}"
end

#mailboxes_listObject

GET /mailboxes List List all mailboxes.



1351
1352
1353
# File 'lib/ari/client.rb', line 1351

def mailboxes_list
  get "mailboxes"
end

#mailboxes_update(mailbox_name, params = {}) ⇒ Object

PUT /mailboxes/:mailboxName void Change the state of a mailbox. (Note - implicitly creates the mailbox).

Error Responses

404 - Mailbox not found

Parameters:

  • mailbox_name (String)

    Name of the mailbox

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :oldMessages (Integer)

    *required Count of old messages in the mailbox

  • :newMessages (Integer)

    *required Count of new messages in the mailbox

See Also:



1386
1387
1388
# File 'lib/ari/client.rb', line 1386

def mailboxes_update(mailbox_name, params = {})
  put "mailboxes/#{mailbox_name}", params
end

#playbacks_control(playback_id, params = {}) ⇒ Object

POST /playbacks/:playbackId/control void Control a playback.

Error Responses

400 - The provided operation parameter was invalid 404 - The playback cannot be found 409 - The operation cannot be performed in the playback’s current state

Parameters:

  • playback_id (String)

    Playback’s id

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :operation (String)

    *required Operation to perform on the playback.

See Also:



1279
1280
1281
# File 'lib/ari/client.rb', line 1279

def playbacks_control(playback_id, params = {})
  post "playbacks/#{playback_id}/control", params
end

#playbacks_get(playback_id) ⇒ Object

GET /playbacks/:playbackId Playback Get a playback’s details.

Error Responses

404 - The playback cannot be found



1243
1244
1245
# File 'lib/ari/client.rb', line 1243

def playbacks_get(playback_id)
  get "playbacks/#{playback_id}"
end

#playbacks_stop(playback_id) ⇒ Object

DELETE /playbacks/:playbackId void Stop a playback.

Error Responses

404 - The playback cannot be found



1259
1260
1261
# File 'lib/ari/client.rb', line 1259

def playbacks_stop(playback_id)
  delete "playbacks/#{playback_id}"
end

#recordings_cancel(recording_name) ⇒ Object

DELETE /recordings/live/:recordingName void Stop a live recording and discard it.

Error Responses

404 - Recording not found

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1044
1045
1046
# File 'lib/ari/client.rb', line 1044

def recordings_cancel(recording_name)
  delete "recordings/live/#{recording_name}"
end

#recordings_copy_stored(recording_name, params = {}) ⇒ Object

POST /recordings/stored/:recordingName/copy StoredRecording Copy a stored recording.

Error Responses

404 - Recording not found 409 - A recording with the same name already exists on the system

Parameters:

  • recording_name (String)

    The name of the recording to copy

  • params (Hash) (defaults to: {})

Options Hash (params):

  • :destinationRecordingName (String)

    *required The destination name of the recording

See Also:



1012
1013
1014
# File 'lib/ari/client.rb', line 1012

def recordings_copy_stored(recording_name, params = {})
  post "recordings/stored/#{recording_name}/copy", params
end

#recordings_delete_stored(recording_name) ⇒ Object

DELETE /recordings/stored/:recordingName void Delete a stored recording.

Error Responses

404 - Recording not found

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



993
994
995
# File 'lib/ari/client.rb', line 993

def recordings_delete_stored(recording_name)
  delete "recordings/stored/#{recording_name}"
end

#recordings_get_live(recording_name) ⇒ Object

GET /recordings/live/:recordingName LiveRecording List live recordings.

Error Responses

404 - Recording not found

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1028
1029
1030
# File 'lib/ari/client.rb', line 1028

def recordings_get_live(recording_name)
  get "recordings/live/#{recording_name}"
end

#recordings_get_stored(recording_name) ⇒ Object

GET

/recordings/stored/:recordingName

StoredRecording Get a stored recording’s details.

Error Responses

404 - Recording not found

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



977
978
979
# File 'lib/ari/client.rb', line 977

def recordings_get_stored(recording_name)
  get "recordings/stored/#{recording_name}"
end

#recordings_list_storedObject

GET /recordings/stored List List recordings that are complete.



959
960
961
# File 'lib/ari/client.rb', line 959

def recordings_list_stored
  get "recordings/stored"
end

#recordings_mute(recording_name) ⇒ Object

POST /recordings/live/:recordingName/mute void Mute a live recording.

Error Responses

404 - Recording not found 409 - Recording not in session

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1111
1112
1113
# File 'lib/ari/client.rb', line 1111

def recordings_mute(recording_name)
  post "recordings/live/#{recording_name}/mute"
end

#recordings_pause(recording_name) ⇒ Object

POST /recordings/live/:recordingName/pause void Pause a live recording.

Error Responses

404 - Recording not found 409 - Recording not in session

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1077
1078
1079
# File 'lib/ari/client.rb', line 1077

def recordings_pause(recording_name)
  post "recordings/live/#{recording_name}/pause"
end

#recordings_stop(recording_name) ⇒ Object

POST /recordings/live/:recordingName/stop void Stop a live recording and store it.

Error Responses

404 - Recording not found

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1060
1061
1062
# File 'lib/ari/client.rb', line 1060

def recordings_stop(recording_name)
  post "recordings/live/#{recording_name}/stop"
end

#recordings_unmute(recording_name) ⇒ Object

DELETE /recordings/live/:recordingName/mute void Unmute a live recording.

Error Responses

404 - Recording not found 409 - Recording not in session

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1128
1129
1130
# File 'lib/ari/client.rb', line 1128

def recordings_unmute(recording_name)
  delete "recordings/live/#{recording_name}/mute"
end

#recordings_unpause(recording_name) ⇒ Object

DELETE /recordings/live/:recordingName/pause void Unpause a live recording.

Error Responses

404 - Recording not found 409 - Recording not in session

Parameters:

  • recording_name (String)

    The name of the recording

See Also:



1094
1095
1096
# File 'lib/ari/client.rb', line 1094

def recordings_unpause(recording_name)
  delete "recordings/live/#{recording_name}/pause"
end

#sounds_get(sound_id) ⇒ Object

GET /sounds/:soundId Sound Get a sound’s details.



1156
1157
1158
# File 'lib/ari/client.rb', line 1156

def sounds_get(sound_id)
  get "sounds/#{sound_id}"
end

#sounds_list(params = {}) ⇒ Object

GET /sounds List List all sounds.

Parameters:

  • params (Hash) (defaults to: {})
  • param (Hash)

    a customizable set of options

See Also:



1144
1145
1146
# File 'lib/ari/client.rb', line 1144

def sounds_list(params = {})
  get "sounds", params
end