plivo 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rst +46 -0
  2. data/lib/plivo.rb +810 -0
  3. data/lib/plivo_account.rb +39 -0
  4. metadata +83 -0
@@ -0,0 +1,46 @@
1
+ Plivo Ruby Library
2
+ ---------------------------
3
+
4
+ Description
5
+ ~~~~~~~~~~~
6
+
7
+ The Plivo Ruby library simplifies the process of making REST calls and generating RESTXML.
8
+
9
+ See `Plivo Documentation <http://www.plivo.com/docs/>`_ for more information.
10
+
11
+
12
+ GEM Installation
13
+ ~~~~~~~~~~~~~
14
+
15
+ $ sudo gem install plivo
16
+
17
+
18
+ Manual Installation
19
+ ~~~~~~~~~~~~~~~~~~~~
20
+
21
+ To use the rake command to build the gem and
22
+
23
+ **Download the source and run:**
24
+ $ sudo gem install /path/to/plivo/gem
25
+
26
+ to finish the installation
27
+
28
+
29
+ Usage
30
+ ~~~~~
31
+
32
+ To use the Plivo Ruby library, you will need to specify the AUTH_ID and AUTH_TOKEN, before you can make REST requests.
33
+
34
+ See `Plivo Documentation <http://www.plivo.com/docs/>`_ for more information.
35
+
36
+
37
+
38
+ Files
39
+ ~~~~~
40
+
41
+ **lib/plivo.rb:** include this library in your code
42
+
43
+ License
44
+ -------
45
+
46
+ The Plivo Ruby library is distributed under the MPL 1.1 License
@@ -0,0 +1,810 @@
1
+ require 'rubygems'
2
+ require 'restclient'
3
+ require 'json'
4
+ require 'rexml/document'
5
+
6
+
7
+
8
+ class PlivoError < Exception
9
+ end
10
+
11
+
12
+
13
+ class RestAPI
14
+ attr_accessor :auth_id, :auth_token, :url, :version, :api, :headers, :rest
15
+
16
+ def initialize(auth_id, auth_token, url="http://api.plivo.com", version="v1")
17
+ @auth_id = auth_id
18
+ @auth_token = auth_token
19
+ @url = url.chomp('/')
20
+ @version = version
21
+ @api = @url + '/' + @version + '/Account/' + @auth_id
22
+ @headers = {"User-Agent" => "RubyPlivo"}
23
+ @rest = RestClient::Resource.new(@api, @auth_id, @auth_token)
24
+ end
25
+
26
+ def hash_to_params(myhash)
27
+ return myhash.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
28
+ end
29
+
30
+ def request(method, path, params=nil)
31
+ if method == "POST"
32
+ if params
33
+ r = @rest[path].post params.to_json, :content_type => 'application/json'
34
+ else
35
+ r = @rest[path].post
36
+ end
37
+ code = r.code
38
+ raw = r.to_str
39
+ response = JSON.parse(raw)
40
+ return [code, response]
41
+ elsif method == "GET"
42
+ if params
43
+ path = path + '?' + hash_to_params(params)
44
+ r = @rest[path].get
45
+ else
46
+ r = @rest[path].get
47
+ end
48
+ code = r.code
49
+ raw = r.to_str
50
+ response = JSON.parse(raw)
51
+ return [code, response]
52
+ elsif method == "DELETE"
53
+ if params
54
+ path = path + '?' + hash_to_params(params)
55
+ r = @rest[path].delete
56
+ else
57
+ r = @rest[path].delete
58
+ end
59
+ code = r.code
60
+ return [code, ""]
61
+ end
62
+ return [405, 'Method Not Supported']
63
+ end
64
+
65
+ ## Accounts ##
66
+ def get_account(params={})
67
+ return request('GET', '/')
68
+ end
69
+
70
+ def modify_account(params={})
71
+ return request('POST', '/', params)
72
+ end
73
+
74
+ def get_subaccounts(params={})
75
+ return request('GET', '/Subaccount/')
76
+ end
77
+
78
+ def create_subaccount(params={})
79
+ return request('POST', '/Subaccount/', params)
80
+ end
81
+
82
+ def get_subaccount(params={})
83
+ subauth_id = params.delete("subauth_id")
84
+ return request('GET', '/Subaccount/#{subauth_id}/')
85
+ end
86
+
87
+ def modify_subaccount(params={})
88
+ subauth_id = params.delete("subauth_id")
89
+ return request('POST', '/Subaccount/#{subauth_id}/', params)
90
+ end
91
+
92
+ def delete_subaccount(params={})
93
+ subauth_id = params.delete("subauth_id")
94
+ return request('DELETE', '/Subaccount/#{subauth_id}/')
95
+ end
96
+
97
+ ## Applications ##
98
+ def get_applications(params={})
99
+ return request('GET', '/Application/', params)
100
+ end
101
+
102
+ def create_application(params={})
103
+ return request('POST', '/Application/', params)
104
+ end
105
+
106
+ def get_application(params={})
107
+ app_id = params.delete("app_id")
108
+ return request('GET', '/Application/#{app_id}/')
109
+ end
110
+
111
+ def modify_application(params={})
112
+ app_id = params.delete("app_id")
113
+ return request('POST', '/Application/#{app_id}/', params)
114
+ end
115
+
116
+ def delete_application(params={})
117
+ app_id = params.delete("app_id")
118
+ return request('DELETE', '/Application/#{app_id}/')
119
+ end
120
+
121
+ def get_subaccount_applications(params={})
122
+ subauth_id = params.delete("subauth_id")
123
+ return request('GET', '/Subaccount/#{subauth_id}/Application/')
124
+ end
125
+
126
+ def get_subaccount_application(params={})
127
+ subauth_id = params.delete("subauth_id")
128
+ app_id = params.delete("app_id")
129
+ return request('GET', '/Subaccount/#{subauth_id}/Application/#{app_id}/')
130
+ end
131
+
132
+ def create_subaccount_application(params={})
133
+ subauth_id = params.delete("subauth_id")
134
+ return request('POST', '/Subaccount/#{subauth_id}/Application/', params)
135
+ end
136
+
137
+ def modify_subaccount_application(params={})
138
+ subauth_id = params.delete("subauth_id")
139
+ app_id = params.delete("app_id")
140
+ return request('POST', '/Subaccount/#{subauth_id}/Application/#{app_id}/', params)
141
+ end
142
+
143
+ def delete_subaccount_application(params={})
144
+ subauth_id = params.delete("subauth_id")
145
+ app_id = params.delete("app_id")
146
+ return request('DELETE', '/Subaccount/#{subauth_id}/Application/#{app_id}/')
147
+ end
148
+
149
+ ## Numbers ##
150
+ def get_numbers(params={})
151
+ return request('GET', '/Number/', params)
152
+ end
153
+
154
+ def search_numbers(params={})
155
+ return request('GET', '/AvailableNumber/', params)
156
+ end
157
+
158
+ def get_number(params={})
159
+ number = params.delete("number")
160
+ return request('GET', '/Number/#{number}/')
161
+ end
162
+
163
+ def rent_number(params={})
164
+ number = params.delete("number")
165
+ return request('POST', '/AvailableNumber/#{number}/')
166
+ end
167
+
168
+ def unrent_number(params={})
169
+ number = params.delete("number")
170
+ return request('DELETE', '/Number/#{number}/')
171
+ end
172
+
173
+ def link_application_number(params={})
174
+ number = params.delete("number")
175
+ return request('POST', '/Number/#{number}/', params)
176
+ end
177
+
178
+ def unlink_application_number(params={})
179
+ number = params.delete("number")
180
+ params = {"app_id" => ""}
181
+ return request('POST', '/Number/#{number}/', params)
182
+ end
183
+
184
+ def get_subaccount_numbers(params={})
185
+ subauth_id = params.delete("subauth_id")
186
+ return request('GET', '/Subaccount/#{subauth_id}/Number/', params)
187
+ end
188
+
189
+ def get_subaccount_number(params={})
190
+ subauth_id = params.delete("subauth_id")
191
+ number = params.delete("number")
192
+ return request('GET', '/Subaccount/#{subauth_id}/Number/#{number}/')
193
+ end
194
+
195
+ ## Schedule ##
196
+ def get_scheduled_tasks(params={})
197
+ return request('GET', '/Schedule/')
198
+ end
199
+
200
+ def cancel_scheduled_task(params={})
201
+ task_id = params.delete("task_id")
202
+ return request('DELETE', '/Schedule/#{task_id}/')
203
+ end
204
+
205
+ ## Calls ##
206
+ def get_cdrs(params={})
207
+ return request('GET', '/Call/', params)
208
+ end
209
+
210
+ def get_cdr(params={})
211
+ record_id = params.delete('record_id')
212
+ return request('GET', '/Call/#{record_id}/')
213
+ end
214
+
215
+ def get_live_calls(params={})
216
+ return request('GET', '/Call/', params={'status'=>'live'})
217
+ end
218
+
219
+ def get_live_call(params={})
220
+ call_uuid = params.delete('call_uuid')
221
+ return request('GET', '/Call/#{call_uuid}/', params={'status'=>'live'})
222
+ end
223
+
224
+ def make_call(params={})
225
+ return request('POST', '/Call/', params)
226
+ end
227
+
228
+ def hangup_all_calls(params={})
229
+ return request('DELETE', '/Call/')
230
+ end
231
+
232
+ def transfer_call(params={})
233
+ call_uuid = params.delete('call_uuid')
234
+ return request('POST', '/Call/#{call_uuid}/', params)
235
+ end
236
+
237
+ def hangup_call(params={})
238
+ call_uuid = params.delete('call_uuid')
239
+ return request('DELETE', '/Call/#{call_uuid}/')
240
+ end
241
+
242
+ def record(params={})
243
+ call_uuid = params.delete('call_uuid')
244
+ return request('POST', '/Call/#{call_uuid}/Record/', params)
245
+ end
246
+
247
+ def stop_record(params={})
248
+ call_uuid = params.delete('call_uuid')
249
+ return request('DELETE', '/Call/#{call_uuid}/Record/')
250
+ end
251
+
252
+ def play(params={})
253
+ call_uuid = params.delete('call_uuid')
254
+ return request('POST', '/Call/#{call_uuid}/Play/', params)
255
+ end
256
+
257
+ def stop_play(params={})
258
+ call_uuid = params.delete('call_uuid')
259
+ return request('DELETE', '/Call/#{call_uuid}/Play/')
260
+ end
261
+
262
+ def speak(params={})
263
+ call_uuid = params.delete('call_uuid')
264
+ return request('POST', '/Call/#{call_uuid}/Speak/', params)
265
+ end
266
+
267
+ def send_digits(params={})
268
+ call_uuid = params.delete('call_uuid')
269
+ return request('POST', '/Call/#{call_uuid}/DTMF/', params)
270
+ end
271
+
272
+ def get_subaccount_cdrs(params={})
273
+ subauth_id = params.delete('subauth_id')
274
+ return request('GET', '/Subaccount/#{subauth_id}/Call/', params)
275
+ end
276
+
277
+ def get_subaccount_cdr(params={})
278
+ subauth_id = params.delete('subauth_id')
279
+ record_id = params.delete('record_id')
280
+ return request('GET', '/Subaccount/#{subauth_id}/Call/#{record_id}/')
281
+ end
282
+
283
+ ## Calls requests ##
284
+ def hangup_request(params={})
285
+ request_uuid = params.delete('request_uuid')
286
+ return request('DELETE', '/Request/#{request_uuid}/')
287
+ end
288
+
289
+ ## Conferences ##
290
+ def get_live_conferences(params={})
291
+ return request('GET', '/Conference/', params)
292
+ end
293
+
294
+ def hangup_all_conferences(params={})
295
+ return request('DELETE', '/Conference/')
296
+ end
297
+
298
+ def get_live_conference(params={})
299
+ conference_id = params.delete('conference_id')
300
+ return request('GET', '/Conference/#{conference_id}/', params)
301
+ end
302
+
303
+ def hangup_conference(params={})
304
+ conference_id = params.delete('conference_id')
305
+ return request('DELETE', '/Conference/#{conference_id}/')
306
+ end
307
+
308
+ def hangup_member(params={})
309
+ conference_id = params.delete('conference_id')
310
+ member_id = params.delete('member_id')
311
+ return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/')
312
+ end
313
+
314
+ def play_member(params={})
315
+ conference_id = params.delete('conference_id')
316
+ member_id = params.delete('member_id')
317
+ return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Play/', params)
318
+ end
319
+
320
+ def stop_play_member(params={})
321
+ conference_id = params.delete('conference_id')
322
+ member_id = params.delete('member_id')
323
+ return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Play/')
324
+ end
325
+
326
+ def speak_member(params={})
327
+ conference_id = params.delete('conference_id')
328
+ member_id = params.delete('member_id')
329
+ return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Speak/', params)
330
+ end
331
+
332
+ def deaf_member(params={})
333
+ conference_id = params.delete('conference_id')
334
+ member_id = params.delete('member_id')
335
+ return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Deaf/')
336
+ end
337
+
338
+ def undeaf_member(params={})
339
+ conference_id = params.delete('conference_id')
340
+ member_id = params.delete('member_id')
341
+ return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Deaf/')
342
+ end
343
+
344
+ def mute_member(params={})
345
+ conference_id = params.delete('conference_id')
346
+ member_id = params.delete('member_id')
347
+ return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Mute/')
348
+ end
349
+
350
+ def unmute_member(params={})
351
+ conference_id = params.delete('conference_id')
352
+ member_id = params.delete('member_id')
353
+ return request('DELETE', '/Conference/#{conference_id}/Member/#{member_id}/Mute/')
354
+ end
355
+
356
+ def kick_member(params={})
357
+ conference_id = params.delete('conference_id')
358
+ member_id = params.delete('member_id')
359
+ return request('POST', '/Conference/#{conference_id}/Member/#{member_id}/Kick/')
360
+ end
361
+
362
+ def record_conference(params={})
363
+ conference_id = params.delete('conference_id')
364
+ return request('POST', '/Conference/#{conference_id}/Record/', params)
365
+ end
366
+
367
+ def stop_record_conference(params={})
368
+ conference_id = params.delete('conference_id')
369
+ return request('DELETE', '/Conference/#{conference_id}/Record/')
370
+ end
371
+
372
+ ## Recordings ##
373
+ def get_recordings(params={})
374
+ return request('GET', '/Recording/', params)
375
+ end
376
+
377
+ def get_recording(params={})
378
+ recording_id = params.delete('recording_id')
379
+ return request('GET', '/Recording/#{recording_id}/')
380
+ end
381
+
382
+ def get_subaccount_recordings(params={})
383
+ subauth_id = params.delete('subauth_id')
384
+ return request('GET', '/Subaccount/#{subauth_id}/Recording/')
385
+ end
386
+
387
+ def get_subaccount_recording(params={})
388
+ subauth_id = params.delete('subauth_id')
389
+ recording_id = params.delete('recording_id')
390
+ return request('GET', '/Subaccount/#{subauth_id}/Recording/#{recording_id}/')
391
+ end
392
+
393
+ ## Endpoints ##
394
+ def get_endpoints(params={})
395
+ return request('GET', '/Endpoint/', params)
396
+ end
397
+
398
+ def create_endpoint(params={})
399
+ return request('POST', '/Endpoint/', params)
400
+ end
401
+
402
+ def get_endpoint(params={})
403
+ endpoint_id = params.delete('endpoint_id')
404
+ return request('GET', '/Endpoint/#{endpoint_id}/')
405
+ end
406
+
407
+ def modify_endpoint(params={})
408
+ endpoint_id = params.delete('endpoint_id')
409
+ return request('POST', '/Endpoint/#{endpoint_id}/', params)
410
+ end
411
+
412
+ def delete_endpoint(params={})
413
+ endpoint_id = params.delete('endpoint_id')
414
+ return request('DELETE', '/Endpoint/#{endpoint_id}/')
415
+ end
416
+
417
+ def get_subaccount_endpoints(params={})
418
+ subauth_id = params.delete('subauth_id')
419
+ return request('GET', '/Subaccount/#{subauth_id}/Endpoint/')
420
+ end
421
+
422
+ def create_subaccount_endpoint(params={})
423
+ subauth_id = params.delete('subauth_id')
424
+ return request('POST', '/Subaccount/#{subauth_id}/Endpoint/', params)
425
+ end
426
+
427
+ def get_subaccount_endpoint(params={})
428
+ subauth_id = params.delete('subauth_id')
429
+ endpoint_id = params.delete('endpoint_id')
430
+ return request('GET', '/Subaccount/#{subauth_id}/Endpoint/#{endpoint_id}/')
431
+ end
432
+
433
+ def modify_subaccount_endpoint(params={})
434
+ subauth_id = params.delete('subauth_id')
435
+ endpoint_id = params.delete('endpoint_id')
436
+ return request('POST', '/Subaccount/#{subauth_id}/Endpoint/#{endpoint_id}/', params)
437
+ end
438
+
439
+ def delete_subaccount_endpoint(params={})
440
+ subauth_id = params.delete('subauth_id')
441
+ endpoint_id = params.delete('endpoint_id')
442
+ return request('DELETE', '/Subaccount/#{subauth_id}/Endpoint/#{endpoint_id}/')
443
+ end
444
+
445
+ ## Carriers ##
446
+ def get_carriers(params={})
447
+ return request('GET', '/Carrier/', params)
448
+ end
449
+
450
+ def create_carrier(params={})
451
+ return request('POST', '/Carrier/', params)
452
+ end
453
+
454
+ def get_carrier(params={})
455
+ carrier_id = params.delete('carrier_id')
456
+ return request('GET', '/Carrier/#{carrier_id}/')
457
+ end
458
+
459
+ def modify_carrier(params={})
460
+ carrier_id = params.delete('carrier_id')
461
+ return request('POST', '/Carrier/#{carrier_id}/', params)
462
+ end
463
+
464
+ def delete_carrier(params={})
465
+ carrier_id = params.delete('carrier_id')
466
+ return request('DELETE', '/Carrier/#{carrier_id}/')
467
+ end
468
+
469
+ ## Carrier Routings ##
470
+ def get_carrier_routings(params={})
471
+ return request('GET', '/CarrierRouting/', params)
472
+ end
473
+
474
+ def create_carrier_routing(params={})
475
+ return request('POST', '/CarrierRouting/', params)
476
+ end
477
+
478
+ def get_carrier_routing(params={})
479
+ routing_id = params.delete('routing_id')
480
+ return request('GET', '/CarrierRouting/#{routing_id}/')
481
+ end
482
+
483
+ def modify_carrier_routing(params={})
484
+ routing_id = params.delete('routing_id')
485
+ return request('POST', '/CarrierRouting/#{routing_id}/', params)
486
+ end
487
+
488
+ def delete_carrier_routing(params={})
489
+ routing_id = params.delete('routing_id')
490
+ return request('DELETE', '/CarrierRouting/#{routing_id}/')
491
+ end
492
+
493
+ ## Message ##
494
+ def send_message(params={})
495
+ return request('POST', '/Message/', params)
496
+ end
497
+ end
498
+
499
+
500
+
501
+ class Element
502
+ class << self
503
+ attr_accessor :valid_attributes, :nestables
504
+ end
505
+ @nestables = []
506
+ @valid_attributes = []
507
+
508
+ attr_accessor :name, :node
509
+
510
+ def initialize(body=nil, attributes={})
511
+ @name = self.class.name
512
+ @body = body
513
+ @node = REXML::Element.new @name
514
+ attributes.each do |k, v|
515
+ if self.class.valid_attributes.include?(k)
516
+ @node.attributes[k] = convert_value(v)
517
+ else
518
+ raise PlivoError, 'invalid attribute ' + k + ' for ' + @name
519
+ end
520
+ end
521
+ if @body
522
+ @node.text = @body
523
+ end
524
+ end
525
+
526
+ def convert_value(v)
527
+ if v == true
528
+ return "true"
529
+ elsif v == false
530
+ return "false"
531
+ elsif v == nil
532
+ return "none"
533
+ elsif v == "get"
534
+ return "GET"
535
+ elsif v == "post"
536
+ return "POST"
537
+ else
538
+ return v
539
+ end
540
+ end
541
+
542
+ def add(element)
543
+ if self.class.nestables.include?(element.name)
544
+ @node.elements << element.node
545
+ return element
546
+ else
547
+ raise PlivoError, element.name + ' not nestable in ' + @name
548
+ end
549
+ end
550
+
551
+ def to_xml
552
+ return @node.to_s
553
+ end
554
+
555
+ def to_s
556
+ return @node.to_s
557
+ end
558
+
559
+ def addSpeak(body, attributes={})
560
+ return add(Speak.new(body, attributes))
561
+ end
562
+
563
+ def addPlay(body, attributes={})
564
+ return add(Play.new(body, attributes))
565
+ end
566
+
567
+ def addGetDigits(attributes={})
568
+ return add(GetDigits.new(attributes))
569
+ end
570
+
571
+ def addRecord(attributes={})
572
+ return add(Record.new(attributes))
573
+ end
574
+
575
+ def addDial(attributes={})
576
+ return add(Dial.new(attributes))
577
+ end
578
+
579
+ def addNumber(body, attributes={})
580
+ return add(Number.new(body, attributes))
581
+ end
582
+
583
+ def addUser(body, attributes={})
584
+ return add(User.new(body, attributes))
585
+ end
586
+
587
+ def addRedirect(body, attributes={})
588
+ return add(Redirect.new(body, attributes))
589
+ end
590
+
591
+ def addWait(attributes={})
592
+ return add(Wait.new(attributes))
593
+ end
594
+
595
+ def addHangup(attributes={})
596
+ return add(Hangup.new(attributes))
597
+ end
598
+
599
+ def addPreAnswer(attributes={})
600
+ return add(PreAnswer.new(attributes))
601
+ end
602
+
603
+ def addConference(body, attributes={})
604
+ return add(Conference.new(body, attributes))
605
+ end
606
+
607
+ def addMessage(body, attributes={})
608
+ return add(Message.new(body, attributes))
609
+ end
610
+ end
611
+
612
+
613
+ class Response < Element
614
+ @nestables = ['Speak', 'Play', 'GetDigits', 'Record', 'Dial', 'Message',
615
+ 'Redirect', 'Wait', 'Hangup', 'PreAnswer', 'Conference']
616
+ @valid_attributes = []
617
+
618
+ def initialize()
619
+ super(nil, {})
620
+ end
621
+
622
+ def to_xml()
623
+ return '<?xml version="1.0" encoding="utf-8" ?>' + super()
624
+ end
625
+
626
+ def to_s()
627
+ return '<?xml version="1.0" encoding="utf-8" ?>' + super()
628
+ end
629
+ end
630
+
631
+
632
+ class Speak < Element
633
+ @nestables = []
634
+ @valid_attributes = ['voice', 'language', 'loop']
635
+
636
+ def initialize(body, attributes={})
637
+ if not body:
638
+ raise PlivoError, 'No text set for ' + @name
639
+ end
640
+ super(body, attributes)
641
+ end
642
+ end
643
+
644
+
645
+ class Play < Element
646
+ @nestables = []
647
+ @valid_attributes = ['loop']
648
+
649
+ def initialize(body, attributes={})
650
+ if not body:
651
+ raise PlivoError 'No url set for ' + @name
652
+ end
653
+ super(body, attributes)
654
+ end
655
+ end
656
+
657
+
658
+ class Wait < Element
659
+ @nestables = []
660
+ @valid_attributes = ['length']
661
+
662
+ def initialize(attributes={})
663
+ super(nil, attributes)
664
+ end
665
+ end
666
+
667
+
668
+ class Redirect < Element
669
+ @nestables = []
670
+ @valid_attributes = ['method']
671
+
672
+ def initialize(body, attributes={})
673
+ if not body
674
+ raise PlivoError 'No url set for ' + @name
675
+ end
676
+ super(body, attributes)
677
+ end
678
+ end
679
+
680
+
681
+ class Hangup < Element
682
+ @nestables = []
683
+ @valid_attributes = ['schedule', 'reason']
684
+
685
+ def initialize(attributes={})
686
+ super(nil, attributes)
687
+ end
688
+ end
689
+
690
+
691
+ class GetDigits < Element
692
+ @nestables = ['Speak', 'Play', 'Wait']
693
+ @valid_attributes = ['action', 'method', 'timeout', 'finishOnKey',
694
+ 'numDigits', 'retries', 'invalidDigitsSound',
695
+ 'validDigits', 'playBeep']
696
+
697
+ def initialize(attributes={})
698
+ super(nil, attributes)
699
+ end
700
+ end
701
+
702
+
703
+ class Number < Element
704
+ @nestables = []
705
+ @valid_attributes = ['sendDigits', 'sendOnPreanswer']
706
+
707
+ def initialize(body, attributes={})
708
+ if not body
709
+ raise PlivoError, 'No number set for ' + @name
710
+ end
711
+ super(body, attributes)
712
+ end
713
+ end
714
+
715
+
716
+ class User < Element
717
+ @nestables = []
718
+ @valid_attributes = ['sendDigits', 'sendOnPreanswer']
719
+
720
+ def initialize(body, attributes={})
721
+ if not body:
722
+ raise PlivoError, 'No user set for ' + @name
723
+ end
724
+ super(body, attributes)
725
+ end
726
+ end
727
+
728
+
729
+ class Dial < Element
730
+ @nestables = ['Number', 'User']
731
+ @valid_attributes = ['action','method','timeout','hangupOnStar',
732
+ 'timeLimit','callerId', 'callerName', 'confirmSound',
733
+ 'dialMusic', 'confirmKey', 'redirect',
734
+ 'callbackUrl', 'callbackMethod', 'digitsMatch']
735
+
736
+ def initialize(attributes={})
737
+ super(nil, attributes)
738
+ end
739
+ end
740
+
741
+
742
+ class Conference < Element
743
+ @nestables = []
744
+ @valid_attributes = ['muted','beep','startConferenceOnEnter',
745
+ 'endConferenceOnExit','waitSound','enterSound', 'exitSound',
746
+ 'timeLimit', 'hangupOnStar', 'maxMembers',
747
+ 'record', 'recordFileFormat', 'action', 'method', 'redirect',
748
+ 'digitsMatch', 'callbackUrl', 'callbackMethod',
749
+ 'stayAlone', 'floorEvent']
750
+
751
+ def initialize(body, attributes={})
752
+ if not body:
753
+ raise PlivoError, 'No conference name set for ' + @name
754
+ end
755
+ super(body, attributes)
756
+ end
757
+ end
758
+
759
+
760
+ class Record < Element
761
+ @nestables = []
762
+ @valid_attributes = ['action', 'method', 'timeout','finishOnKey',
763
+ 'maxLength', 'bothLegs', 'playBeep',
764
+ 'redirect', 'fileFormat']
765
+
766
+ def initialize(attributes={})
767
+ super(nil, attributes)
768
+ end
769
+ end
770
+
771
+
772
+ class PreAnswer < Element
773
+ @nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect']
774
+ @valid_attributes = []
775
+
776
+ def initialize(attributes={})
777
+ super(nil, attributes)
778
+ end
779
+ end
780
+
781
+
782
+ class Message < Element
783
+ @nestables = []
784
+ @valid_attributes = ['src', 'dst', 'type']
785
+
786
+ def initialize(body, attributes={})
787
+ if not body:
788
+ raise PlivoError, 'No text set for ' + @name
789
+ end
790
+ super(body, attributes)
791
+ end
792
+ end
793
+
794
+
795
+ #p = RestAPI.new('MAGWNTM3ZTK1M2YZMDYX', 'MThhNmRjZDFmY2I3MTg1NjAwODIxYWZiZWViNTQx',
796
+ # 'http://testapi.plivo.com', 'v1')
797
+ #require 'pp'
798
+ #pp p.get_live_calls()
799
+ #pp p.get_cdrs()
800
+
801
+ #pp p.modify_account({"name" => "Cloud test account"})
802
+ #pp p.get_account()
803
+
804
+
805
+ #r = Response.new
806
+ #s = r.addSpeak("hello world", {"voice" => "MAN"})
807
+ #s = r.addPlay("http://toto.com/toto.mp3")
808
+ #puts r.to_xml()
809
+
810
+
@@ -0,0 +1,39 @@
1
+ require 'plivo.rb'
2
+
3
+
4
+ AUTH_ID = "MAGWNTM3ZTK1M2YZMDF5"
5
+ AUTH_TOKEN = "MThhNmRjZDFmY2I3MTg1NjAwODIxYWZi1UViNTQx"
6
+
7
+
8
+ p = RestAPI.new(AUTH_ID, AUTH_TOKEN)
9
+
10
+
11
+ # Making a call
12
+ params = {'to' => '919986410895',
13
+ 'from' => '919986410895',
14
+ 'answer_url' => 'http://high-fire-9181.herokuapp.com/AnswerUrl',
15
+ 'answer_method' => 'GET',
16
+ 'hangup_url' => 'http://high-fire-9181.herokuapp.com/AnswerUrl',
17
+ }
18
+ response = p.make_call(params)
19
+
20
+ # Get live calls
21
+ response = p.get_live_calls()
22
+
23
+
24
+ # Get details of a live call
25
+ params = {'call_uuid' => 'XXXXXXXXXXXXXXXXXXXXXXX'}
26
+ response = p.get_live_call(params)
27
+
28
+
29
+ # Transfer calls
30
+ params = {'transfer_url' => 'http://example.com/TransferUrl'}
31
+ response = p.transfer_call(params)
32
+
33
+
34
+ # Hangup calls
35
+ params = {'call_uuid' => 'XXXXXXXXXXXXXXXXXXXXXXX'}
36
+ response = p.hangup_call(params)
37
+
38
+
39
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plivo
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Plivo Inc
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-03-20 00:00:00 +05:30
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: builder
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 1
32
+ - 2
33
+ version: 2.1.2
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ description: A Ruby gem for interacting with the Plivo Platform
37
+ email: support@plivo.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.rst
44
+ files:
45
+ - lib/plivo.rb
46
+ - lib/plivo_account.rb
47
+ - README.rst
48
+ has_rdoc: true
49
+ homepage: http://www.plivo.com
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: A Ruby gem for communicating with the Plivo Platform
82
+ test_files: []
83
+