plivo 0.2.12 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/plivo.rb +29 -68
  2. metadata +24 -10
  3. data/lib/test.rb +0 -7
data/lib/plivo.rb CHANGED
@@ -21,7 +21,7 @@ module Plivo
21
21
  end
22
22
 
23
23
  def hash_to_params(myhash)
24
- return myhash.map{|k,v| "#{CGI.escape(k)}=#{CGI.escape(v)}"}.join("&")
24
+ return myhash.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join("&")
25
25
  end
26
26
 
27
27
  def request(method, path, params=nil)
@@ -444,22 +444,39 @@ module Plivo
444
444
 
445
445
  attr_accessor :node, :name
446
446
 
447
- def initialize(body=nil, attributes={})
447
+ def initialize(body=nil, attributes={}, &block)
448
448
  @name = self.class.name.split('::')[1]
449
449
  @body = body
450
450
  @node = REXML::Element.new @name
451
451
  attributes.each do |k, v|
452
- if self.class.valid_attributes.include?(k)
453
- @node.attributes[k] = convert_value(v)
452
+ if self.class.valid_attributes.include?(k.to_s)
453
+ @node.attributes[k.to_s] = convert_value(v)
454
454
  else
455
- raise PlivoError, 'invalid attribute ' + k + ' for ' + @name
455
+ raise PlivoError, "invalid attribute #{k.to_s} for #{@name}"
456
456
  end
457
457
  end
458
458
  if @body
459
459
  @node.text = @body
460
460
  end
461
+
462
+ # Allow for nested "nestable" elements using a code block
463
+ # ie
464
+ # Plivo::Response.new do |r|
465
+ # r.Dial do |n|
466
+ # n.Number '+15557779999'
467
+ # end
468
+ # end
469
+ yield(self) if block_given?
470
+ end
471
+
472
+ def method_missing(method, *args, &block)
473
+ # Handle the addElement methods
474
+ method = $1.to_sym if method.to_s =~ /^add(.*)/
475
+ # Add the element
476
+ add(Plivo.const_get(method).new(*args, &block))
461
477
  end
462
478
 
479
+
463
480
  def convert_value(v)
464
481
  if v == true
465
482
  return "true"
@@ -484,7 +501,7 @@ module Plivo
484
501
  @node.elements << element.node
485
502
  return element
486
503
  else
487
- raise PlivoError, element.name + ' not nestable in ' + @name
504
+ raise PlivoError, "#{element.name} not nestable in #{@name}"
488
505
  end
489
506
  end
490
507
 
@@ -495,62 +512,6 @@ module Plivo
495
512
  def to_s
496
513
  return @node.to_s
497
514
  end
498
-
499
- def addSpeak(body, attributes={})
500
- return add(Speak.new(body, attributes))
501
- end
502
-
503
- def addPlay(body, attributes={})
504
- return add(Play.new(body, attributes))
505
- end
506
-
507
- def addGetDigits(attributes={})
508
- return add(GetDigits.new(attributes))
509
- end
510
-
511
- def addRecord(attributes={})
512
- return add(Record.new(attributes))
513
- end
514
-
515
- def addDial(attributes={})
516
- return add(Dial.new(attributes))
517
- end
518
-
519
- def addNumber(body, attributes={})
520
- return add(Number.new(body, attributes))
521
- end
522
-
523
- def addUser(body, attributes={})
524
- return add(User.new(body, attributes))
525
- end
526
-
527
- def addRedirect(body, attributes={})
528
- return add(Redirect.new(body, attributes))
529
- end
530
-
531
- def addWait(attributes={})
532
- return add(Wait.new(attributes))
533
- end
534
-
535
- def addHangup(attributes={})
536
- return add(Hangup.new(attributes))
537
- end
538
-
539
- def addPreAnswer(attributes={})
540
- return add(PreAnswer.new(attributes))
541
- end
542
-
543
- def addConference(body, attributes={})
544
- return add(Conference.new(body, attributes))
545
- end
546
-
547
- def addMessage(body, attributes={})
548
- return add(Message.new(body, attributes))
549
- end
550
-
551
- def addDTMF(body, attributes={})
552
- return add(DTMF.new(body, attributes))
553
- end
554
515
  end
555
516
 
556
517
 
@@ -639,8 +600,8 @@ module Plivo
639
600
  'validDigits', 'playBeep', 'redirect',
640
601
  'digitTimeout']
641
602
 
642
- def initialize(attributes={})
643
- super(nil, attributes)
603
+ def initialize(attributes={}, &block)
604
+ super(nil, attributes, &block)
644
605
  end
645
606
  end
646
607
 
@@ -679,8 +640,8 @@ module Plivo
679
640
  'callbackUrl', 'callbackMethod', 'digitsMatch',
680
641
  'sipHeaders']
681
642
 
682
- def initialize(attributes={})
683
- super(nil, attributes)
643
+ def initialize(attributes={}, &block)
644
+ super(nil, attributes, &block)
684
645
  end
685
646
  end
686
647
 
@@ -720,8 +681,8 @@ module Plivo
720
681
  @nestables = ['Play', 'Speak', 'GetDigits', 'Wait', 'Redirect', 'Message', 'DTMF']
721
682
  @valid_attributes = []
722
683
 
723
- def initialize(attributes={})
724
- super(nil, attributes)
684
+ def initialize(attributes={}, &block)
685
+ super(nil, attributes, &block)
725
686
  end
726
687
  end
727
688
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-11 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: builder
16
- requirement: &20717940 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 2.1.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20717940
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.1.2
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rest-client
27
- requirement: &20715780 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 1.6.7
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *20715780
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.6.7
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: json
38
- requirement: &20712520 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: 1.6.6
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *20712520
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.6
47
62
  description: A Ruby gem for interacting with the Plivo Platform
48
63
  email: support@plivo.com
49
64
  executables: []
@@ -51,7 +66,6 @@ extensions: []
51
66
  extra_rdoc_files:
52
67
  - README.md
53
68
  files:
54
- - lib/test.rb
55
69
  - lib/plivo.rb
56
70
  - README.md
57
71
  homepage: http://www.plivo.com
@@ -74,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
88
  version: '0'
75
89
  requirements: []
76
90
  rubyforge_project:
77
- rubygems_version: 1.8.11
91
+ rubygems_version: 1.8.23
78
92
  signing_key:
79
93
  specification_version: 3
80
94
  summary: A Ruby gem for communicating with the Plivo Platform
data/lib/test.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'plivo'
3
- include Plivo
4
-
5
-
6
-
7
- p = RestAPI.new('asdf','asdf')