plivo 0.3.19 → 4.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +11 -0
  5. data/AUTHORS.md +4 -0
  6. data/CHANGELOG.md +158 -0
  7. data/Gemfile +10 -0
  8. data/Jenkinsfile +7 -0
  9. data/LICENSE.txt +19 -0
  10. data/README.md +155 -24
  11. data/Rakefile +9 -0
  12. data/ci/config.yml +7 -0
  13. data/examples/conference_bridge.rb +108 -0
  14. data/examples/jwt.rb +32 -0
  15. data/examples/lookup.rb +24 -0
  16. data/examples/multi_party_call.rb +295 -0
  17. data/examples/phlos.rb +55 -0
  18. data/examples/regulatory_compliance.rb +167 -0
  19. data/lib/plivo/base/resource.rb +148 -0
  20. data/lib/plivo/base/resource_interface.rb +108 -0
  21. data/lib/plivo/base/response.rb +38 -0
  22. data/lib/plivo/base.rb +17 -0
  23. data/lib/plivo/base_client.rb +393 -0
  24. data/lib/plivo/exceptions.rb +50 -0
  25. data/lib/plivo/jwt.rb +120 -0
  26. data/lib/plivo/phlo_client.rb +29 -0
  27. data/lib/plivo/resources/accounts.rb +181 -0
  28. data/lib/plivo/resources/addresses.rb +302 -0
  29. data/lib/plivo/resources/applications.rb +258 -0
  30. data/lib/plivo/resources/call_feedback.rb +55 -0
  31. data/lib/plivo/resources/calls.rb +559 -0
  32. data/lib/plivo/resources/conferences.rb +367 -0
  33. data/lib/plivo/resources/endpoints.rb +132 -0
  34. data/lib/plivo/resources/identities.rb +319 -0
  35. data/lib/plivo/resources/lookup.rb +88 -0
  36. data/lib/plivo/resources/media.rb +97 -0
  37. data/lib/plivo/resources/messages.rb +215 -0
  38. data/lib/plivo/resources/multipartycalls.rb +554 -0
  39. data/lib/plivo/resources/nodes.rb +83 -0
  40. data/lib/plivo/resources/numbers.rb +319 -0
  41. data/lib/plivo/resources/phlo_member.rb +64 -0
  42. data/lib/plivo/resources/phlos.rb +55 -0
  43. data/lib/plivo/resources/powerpacks.rb +717 -0
  44. data/lib/plivo/resources/pricings.rb +43 -0
  45. data/lib/plivo/resources/recordings.rb +116 -0
  46. data/lib/plivo/resources/regulatory_compliance.rb +610 -0
  47. data/lib/plivo/resources.rb +25 -0
  48. data/lib/plivo/rest_client.rb +63 -0
  49. data/lib/plivo/utils.rb +294 -0
  50. data/lib/plivo/version.rb +3 -0
  51. data/lib/plivo/xml/break.rb +31 -0
  52. data/lib/plivo/xml/conference.rb +20 -0
  53. data/lib/plivo/xml/cont.rb +13 -0
  54. data/lib/plivo/xml/dial.rb +16 -0
  55. data/lib/plivo/xml/dtmf.rb +13 -0
  56. data/lib/plivo/xml/element.rb +106 -0
  57. data/lib/plivo/xml/emphasis.rb +17 -0
  58. data/lib/plivo/xml/get_digits.rb +15 -0
  59. data/lib/plivo/xml/get_input.rb +16 -0
  60. data/lib/plivo/xml/hangup.rb +12 -0
  61. data/lib/plivo/xml/lang.rb +29 -0
  62. data/lib/plivo/xml/message.rb +13 -0
  63. data/lib/plivo/xml/multipartycall.rb +188 -0
  64. data/lib/plivo/xml/number.rb +13 -0
  65. data/lib/plivo/xml/p.rb +12 -0
  66. data/lib/plivo/xml/phoneme.rb +20 -0
  67. data/lib/plivo/xml/play.rb +13 -0
  68. data/lib/plivo/xml/plivo_xml.rb +19 -0
  69. data/lib/plivo/xml/pre_answer.rb +12 -0
  70. data/lib/plivo/xml/prosody.rb +28 -0
  71. data/lib/plivo/xml/record.rb +17 -0
  72. data/lib/plivo/xml/redirect.rb +13 -0
  73. data/lib/plivo/xml/response.rb +21 -0
  74. data/lib/plivo/xml/s.rb +12 -0
  75. data/lib/plivo/xml/say_as.rb +24 -0
  76. data/lib/plivo/xml/speak.rb +28 -0
  77. data/lib/plivo/xml/sub.rb +16 -0
  78. data/lib/plivo/xml/user.rb +13 -0
  79. data/lib/plivo/xml/w.rb +17 -0
  80. data/lib/plivo/xml/wait.rb +12 -0
  81. data/lib/plivo/xml.rb +39 -0
  82. data/lib/plivo.rb +12 -815
  83. data/plivo.gemspec +44 -0
  84. metadata +181 -41
  85. data/ext/mkrf_conf.rb +0 -9
@@ -0,0 +1,188 @@
1
+ module Plivo
2
+ module XML
3
+ class MultiPartyCall < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[role maxDuration maxParticipants waitMusicUrl
6
+ waitMusicMethod agentHoldMusicUrl agentHoldMusicMethod
7
+ customerHoldMusicUrl customerHoldMusicMethod record
8
+ recordFileFormat recordingCallbackUrl recordingCallbackMethod
9
+ statusCallbackEvents statusCallbackUrl statusCallbackMethod
10
+ stayAlone coachMode mute hold startMpcOnEnter endMpcOnExit
11
+ enterSound enterSoundMethod exitSound exitSoundMethod
12
+ onExitActionUrl onExitActionMethod relayDTMFInputs]
13
+
14
+ VALID_ROLE_VALUES = %w[agent supervisor customer]
15
+ VALID_METHOD_VALUES = %w[GET POST]
16
+ VALID_BOOL_VALUES = [true, false]
17
+ VALID_RECORD_FILE_FORMAT_VALUES = %w[mp3 wav]
18
+
19
+ def initialize(body, attributes = {})
20
+ if attributes[:role] && !VALID_ROLE_VALUES.include?(attributes[:role].downcase)
21
+ raise PlivoXMLError, "invalid attribute value #{attributes[:role]} for role"
22
+ elsif !attributes[:role]
23
+ raise PlivoXMLError, "role not mentioned : possible values - Agent / Supervisor / Customer"
24
+ end
25
+
26
+ if attributes[:maxDuration] && (attributes[:maxDuration]<300 || attributes[:maxDuration]>28800)
27
+ raise PlivoXMLError, "invalid attribute value #{attributes[:maxDuration]} for maxDuration"
28
+ elsif !attributes[:maxDuration]
29
+ attributes[:maxDuration] = 14400
30
+ end
31
+
32
+ if attributes[:maxParticipants] && (attributes[:maxParticipants]<2 || attributes[:maxParticipants]>10)
33
+ raise PlivoXMLError, "invalid attribute value #{attributes[:maxParticipants]} for maxParticipants"
34
+ elsif !attributes[:maxParticipants]
35
+ attributes[:maxParticipants] = 10
36
+ end
37
+
38
+ if attributes[:waitMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:waitMusicMethod].upcase)
39
+ raise PlivoXMLError, "invalid attribute value #{attributes[:waitMusicMethod]} for waitMusicMethod"
40
+ elsif !attributes[:waitMusicMethod]
41
+ attributes[:waitMusicMethod] = 'GET'
42
+ end
43
+
44
+ if attributes[:agentHoldMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:agentHoldMusicMethod].upcase)
45
+ raise PlivoXMLError, "invalid attribute value #{attributes[:agentHoldMusicMethod]} for agentHoldMusicMethod"
46
+ elsif !attributes[:agentHoldMusicMethod]
47
+ attributes[:agentHoldMusicMethod] = 'GET'
48
+ end
49
+
50
+ if attributes[:customerHoldMusicMethod] && !VALID_METHOD_VALUES.include?(attributes[:customerHoldMusicMethod].upcase)
51
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicMethod]} for customerHoldMusicMethod"
52
+ elsif !attributes[:customerHoldMusicMethod]
53
+ attributes[:customerHoldMusicMethod] = 'GET'
54
+ end
55
+
56
+ if attributes[:record] && !VALID_BOOL_VALUES.include?(attributes[:record])
57
+ raise PlivoXMLError, "invalid attribute value #{attributes[:record]} for record"
58
+ elsif !attributes[:record]
59
+ attributes[:record] = false
60
+ end
61
+
62
+ if attributes[:recordFileFormat] && !VALID_RECORD_FILE_FORMAT_VALUES.include?(attributes[:recordFileFormat])
63
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordFileFormat]} for recordFileFormat"
64
+ elsif !attributes[:recordFileFormat]
65
+ attributes[:recordFileFormat] = 'mp3'
66
+ end
67
+
68
+ if attributes[:recordingCallbackMethod] && !VALID_METHOD_VALUES.include?(attributes[:recordingCallbackMethod].upcase)
69
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordingCallbackMethod]} for recordingCallbackMethod"
70
+ elsif !attributes[:recordingCallbackMethod]
71
+ attributes[:recordingCallbackMethod] = 'GET'
72
+ end
73
+
74
+ if attributes[:statusCallbackEvents] && !multi_valid_param?(:statusCallbackEvents, attributes[:statusCallbackEvents], String, false, %w[mpc-state-changes participant-state-changes participant-speak-events participant-digit-input-events add-participant-api-events], true, ',') == true
75
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackEvents]} for statusCallbackEvents"
76
+ elsif !attributes[:statusCallbackEvents]
77
+ attributes[:statusCallbackEvents] = 'mpc-state-changes,participant-state-changes'
78
+ end
79
+
80
+ if attributes[:statusCallbackMethod] && !VALID_METHOD_VALUES.include?(attributes[:statusCallbackMethod].upcase)
81
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackMethod]} for statusCallbackMethod"
82
+ elsif !attributes[:statusCallbackMethod]
83
+ attributes[:statusCallbackMethod] = 'POST'
84
+ end
85
+
86
+ if attributes[:stayAlone] && !VALID_BOOL_VALUES.include?(attributes[:stayAlone])
87
+ raise PlivoXMLError, "invalid attribute value #{attributes[:stayAlone]} for stayAlone"
88
+ elsif !attributes[:stayAlone]
89
+ attributes[:stayAlone] = false
90
+ end
91
+
92
+ if attributes[:coachMode] && !VALID_BOOL_VALUES.include?(attributes[:coachMode])
93
+ raise PlivoXMLError, "invalid attribute value #{attributes[:coachMode]} for coachMode"
94
+ elsif !attributes[:coachMode]
95
+ attributes[:coachMode] = true
96
+ end
97
+
98
+ if attributes[:mute] && !VALID_BOOL_VALUES.include?(attributes[:mute])
99
+ raise PlivoXMLError, "invalid attribute value #{attributes[:mute]} for mute"
100
+ elsif !attributes[:mute]
101
+ attributes[:mute] = false
102
+ end
103
+
104
+ if attributes[:hold] && !VALID_BOOL_VALUES.include?(attributes[:hold])
105
+ raise PlivoXMLError, "invalid attribute value #{attributes[:hold]} for hold"
106
+ elsif !attributes[:hold]
107
+ attributes[:hold] = false
108
+ end
109
+
110
+ if attributes[:startMpcOnEnter] && !VALID_BOOL_VALUES.include?(attributes[:startMpcOnEnter])
111
+ raise PlivoXMLError, "invalid attribute value #{attributes[:startMpcOnEnter]} for startMpcOnEnter"
112
+ elsif !attributes[:startMpcOnEnter]
113
+ attributes[:startMpcOnEnter] = true
114
+ end
115
+
116
+ if attributes[:endMpcOnExit] && !VALID_BOOL_VALUES.include?(attributes[:endMpcOnExit])
117
+ raise PlivoXMLError, "invalid attribute value #{attributes[:endMpcOnExit]} for endMpcOnExit"
118
+ elsif !attributes[:endMpcOnExit]
119
+ attributes[:endMpcOnExit] = false
120
+ end
121
+
122
+ if attributes[:enterSound] && !is_one_among_string_url?(:enterSound, attributes[:enterSound], false, %w[beep:1 beep:2 none])
123
+ raise PlivoXMLError, "invalid attribute value #{attributes[:enterSound]} for enterSound"
124
+ elsif !attributes[:enterSound]
125
+ attributes[:enterSound] = 'beep:1'
126
+ end
127
+
128
+ if attributes[:enterSoundMethod] && !VALID_METHOD_VALUES.include?(attributes[:enterSoundMethod].upcase)
129
+ raise PlivoXMLError, "invalid attribute value #{attributes[:enterSoundMethod]} for enterSoundMethod"
130
+ elsif !attributes[:enterSoundMethod]
131
+ attributes[:enterSoundMethod] = 'GET'
132
+ end
133
+
134
+ if attributes[:exitSound] && !is_one_among_string_url?(:exitSound, attributes[:exitSound], false, %w[beep:1 beep:2 none])
135
+ raise PlivoXMLError, "invalid attribute value #{attributes[:exitSound]} for exitSound"
136
+ elsif !attributes[:exitSound]
137
+ attributes[:exitSound] = 'beep:2'
138
+ end
139
+
140
+ if attributes[:exitSoundMethod] && !VALID_METHOD_VALUES.include?(attributes[:exitSoundMethod].upcase)
141
+ raise PlivoXMLError, "invalid attribute value #{attributes[:exitSoundMethod]} for exitSoundMethod"
142
+ elsif !attributes[:exitSoundMethod]
143
+ attributes[:exitSoundMethod] = 'GET'
144
+ end
145
+
146
+ if attributes[:onExitActionMethod] && !VALID_METHOD_VALUES.include?(attributes[:onExitActionMethod].upcase)
147
+ raise PlivoXMLError, "invalid attribute value #{attributes[:onExitActionMethod]} for onExitActionMethod"
148
+ elsif !attributes[:onExitActionMethod]
149
+ attributes[:onExitActionMethod] = 'POST'
150
+ end
151
+
152
+ if attributes[:relayDTMFInputs] && !VALID_BOOL_VALUES.include?(attributes[:relayDTMFInputs])
153
+ raise PlivoXMLError, "invalid attribute value #{attributes[:relayDTMFInputs]} for relayDTMFInputs"
154
+ elsif !attributes[:relayDTMFInputs]
155
+ attributes[:relayDTMFInputs] = false
156
+ end
157
+
158
+ if attributes[:waitMusicUrl] && !valid_url?(:waitMusicUrl, attributes[:waitMusicUrl], false)
159
+ raise PlivoXMLError, "invalid attribute value #{attributes[:waitMusicUrl]} for waitMusicUrl"
160
+ end
161
+
162
+ if attributes[:agentHoldMusicUrl] && !valid_url?(:agentHoldMusicUrl, attributes[:agentHoldMusicUrl], false)
163
+ raise PlivoXMLError, "invalid attribute value #{attributes[:agentHoldMusicUrl]} for agentHoldMusicUrl"
164
+ end
165
+
166
+ if attributes[:customerHoldMusicUrl] && !valid_url?(:customerHoldMusicUrl, attributes[:customerHoldMusicUrl], false)
167
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicUrl]} for customerHoldMusicUrl"
168
+ end
169
+
170
+ if attributes[:recordingCallbackUrl] && !valid_url?(:recordingCallbackUrl, attributes[:recordingCallbackUrl], false)
171
+ raise PlivoXMLError, "invalid attribute value #{attributes[:recordingCallbackUrl]} for recordingCallbackUrl"
172
+ end
173
+
174
+ if attributes[:statusCallbackUrl] && !valid_url?(:statusCallbackUrl, attributes[:statusCallbackUrl], false)
175
+ raise PlivoXMLError, "invalid attribute value #{attributes[:statusCallbackUrl]} for statusCallbackUrl"
176
+ end
177
+
178
+ if attributes[:customerHoldMusicUrl] && !valid_url?(:customerHoldMusicUrl, attributes[:customerHoldMusicUrl], false)
179
+ raise PlivoXMLError, "invalid attribute value #{attributes[:customerHoldMusicUrl]} for customerHoldMusicUrl"
180
+ end
181
+
182
+ raise PlivoXMLError, 'No MPC name set for the MPC' unless body
183
+ super(body, attributes)
184
+ end
185
+
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,13 @@
1
+ module Plivo
2
+ module XML
3
+ class Number < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[sendDigits sendOnPreanswer]
6
+
7
+ def initialize(body, attributes = {})
8
+ raise PlivoXMLError, 'No number set for Number' unless body
9
+ super(body, attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Plivo
2
+ module XML
3
+ class P < Element
4
+ @nestables = %w(Break Cont Emphasis Lang Phoneme Prosody SayAs Sub S W)
5
+ @valid_attributes = []
6
+
7
+ def initialize(body)
8
+ super(body)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Plivo
2
+ module XML
3
+ class Phoneme < Element
4
+ @nestables = []
5
+ @valid_attributes = %w(alphabet ph)
6
+
7
+ VALID_ALPHABET_ATTRIBUTE_VALUES=%w(ipa x-sampa x-amazon-pinyin)
8
+
9
+ def initialize(body, attributes = {})
10
+ unless attributes && attributes[:ph]
11
+ raise PlivoXMLError, 'ph attribute is required for Phoneme'
12
+ end
13
+ if attributes && attributes[:alphabet] && !VALID_ALPHABET_ATTRIBUTE_VALUES.include?(attributes[:alphabet])
14
+ raise PlivoXMLError, "invalid attribute value #{attributes[:alphabet]} for alphabet"
15
+ end
16
+ super(body, attributes)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module Plivo
2
+ module XML
3
+ class Play < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[loop]
6
+
7
+ def initialize(body, attributes = {})
8
+ raise PlivoXMLError 'No url set for Play' unless body
9
+ super(body, attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module Plivo
2
+ module XML
3
+ class PlivoXML
4
+ attr_accessor :response
5
+
6
+ def initialize(response = nil)
7
+ response.nil? ? @response = Plivo::XML::Response.new : @response = response
8
+ end
9
+
10
+ def to_xml
11
+ '<?xml version="1.0" encoding="utf-8" ?>' + @response.to_xml
12
+ end
13
+
14
+ def to_s
15
+ '<?xml version="1.0" encoding="utf-8" ?>' + @response.to_s
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Plivo
2
+ module XML
3
+ class PreAnswer < Element
4
+ @nestables = %w[Play Speak GetDigits Wait Redirect Message DTMF]
5
+ @valid_attributes = []
6
+
7
+ def initialize(attributes = {}, &block)
8
+ super(nil, attributes, &block)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module Plivo
2
+ module XML
3
+ class Prosody < Element
4
+ @nestables = %w(Break Cont Emphasis Lang P Phoneme Prosody S SayAs Sub W)
5
+ @valid_attributes = %w(volume rate pitch)
6
+
7
+ VALID_VOLUME_ATTRIBUTE_VALUES=%w(default silent x-soft soft medium loud x-loud)
8
+ VALID_RATE_ATTRIBUTE_VALUES=%w(x-slow slow medium fast x-fast)
9
+ VALID_PITCH_ATTRIBUTE_VALUES=%w(default x-low low medium high x-high)
10
+
11
+ def initialize(body, attributes = {})
12
+ if attributes.nil? || attributes.length == 0
13
+ raise PlivoXMLError, 'Specify at least one attribute for Prosody tag'
14
+ end
15
+ if attributes[:volume] && !VALID_VOLUME_ATTRIBUTE_VALUES.include?(attributes[:volume]) && !attributes[:volume].include?('dB')
16
+ raise PlivoXMLError, "invalid attribute value #{attributes[:volume]} for volume"
17
+ end
18
+ if attributes[:rate] && !VALID_RATE_ATTRIBUTE_VALUES.include?(attributes[:rate]) && (!attributes[:rate].include?('%') || attributes[:rate].split('%')[0].to_i < 0)
19
+ raise PlivoXMLError, "invalid attribute value #{attributes[:rate]} for rate"
20
+ end
21
+ if attributes[:pitch] && !VALID_PITCH_ATTRIBUTE_VALUES.include?(attributes[:pitch]) && !attributes[:pitch].include?('%')
22
+ raise PlivoXMLError, "invalid attribute value #{attributes[:pitch]} for pitch"
23
+ end
24
+ super(body, attributes)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module Plivo
2
+ module XML
3
+ class Record < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[action method timeout finishOnKey
6
+ maxLength playBeep recordSession
7
+ startOnDialAnswer redirect fileFormat
8
+ callbackUrl callbackMethod
9
+ transcriptionType transcriptionUrl
10
+ transcriptionMethod]
11
+
12
+ def initialize(attributes = {})
13
+ super(nil, attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ module Plivo
2
+ module XML
3
+ class Redirect < Element
4
+ @nestables = []
5
+ @valid_attributes = ['method']
6
+
7
+ def initialize(body, attributes = {})
8
+ raise PlivoError 'No url set for Redirect' unless body
9
+ super(body, attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module Plivo
2
+ module XML
3
+ class Response < Element
4
+ @nestables = %w[Speak Play GetDigits GetInput Record Dial Message
5
+ Redirect Wait Hangup PreAnswer Conference DTMF MultiPartyCall]
6
+ @valid_attributes = []
7
+
8
+ def initialize
9
+ super(nil, {})
10
+ end
11
+
12
+ def to_xml
13
+ super()
14
+ end
15
+
16
+ def to_s
17
+ super()
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Plivo
2
+ module XML
3
+ class S < Element
4
+ @nestables = %w(Break Cont Emphasis Lang Phoneme Prosody SayAs Sub W)
5
+ @valid_attributes = []
6
+
7
+ def initialize(body)
8
+ super(body)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ module Plivo
2
+ module XML
3
+ class SayAs < Element
4
+ @nestables = []
5
+ @valid_attributes = %w(interpret-as format)
6
+
7
+ VALID_INTERPRET_AS_ATTRIBUTE_VALUES=%w(characters spell-out cardinal number ordinal digits fraction unit date time address expletive telephone)
8
+ VALID_FORMAT_ATTRIBUTE_VALUES=%w(mdy dmy ymd md dm ym my d m y yyyymmdd)
9
+
10
+ def initialize(body, attributes = {})
11
+ unless attributes && attributes["interpret-as"]
12
+ raise PlivoXMLError, 'interpret-as is a required attribute for say-as element'
13
+ end
14
+ if !VALID_INTERPRET_AS_ATTRIBUTE_VALUES.include?(attributes["interpret-as"])
15
+ raise PlivoXMLError, "invalid attribute value #{attributes["interpret-as"]} for interpret-as"
16
+ end
17
+ if attributes["interpret-as"]=='date' && attributes[:format] && !VALID_FORMAT_ATTRIBUTE_VALUES.include?(attributes[:format])
18
+ raise PlivoXMLError, "invalid attribute value #{attributes[:format]} for format"
19
+ end
20
+ super(body, attributes)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module Plivo
2
+ module XML
3
+ class Speak < Element
4
+ @valid_attributes = %w[voice language loop]
5
+
6
+ SUPPORTED_ENGINES=%w(Polly)
7
+ SUPPORTED_VOICES=%w(Nicole Russell Vitoria Ricardo Chantal Naja Mads Lotte Ruben Lea Celine Mathieu Vicki Marlene Hans Aditi Dora Karl Raveena Aditi Carla Giorgio Mizuki Takumi Seoyeon Zhiyu Liv Ewa Maja Jacek Jan Ines Cristiano Carmen Tatyana Maxim Conchita Enrique Astrid Filiz Amy Emma Brian Joanna Matthew Salli Justin Kendra Joey Kimberly Ivy Penelope Miguel Gwyneth Geraint Zeina Mia)
8
+
9
+ def initialize(body, attributes = {})
10
+ if attributes.nil? || attributes[:voice].nil? || ['MAN', 'WOMAN'].include?(attributes[:voice])
11
+ @nestables = []
12
+ else
13
+ engine = attributes[:voice].split('.')[0]
14
+ voice = attributes[:voice].split('.')[1]
15
+ if SUPPORTED_ENGINES.include?(engine) && SUPPORTED_VOICES.include?(voice)
16
+ @nestables = %w(Break Cont Emphasis Lang P Phoneme Prosody S SayAs Sub W)
17
+ else
18
+ raise PlivoXMLError, "<Speak> voice #{attributes[:voice]} is not valid."
19
+ end
20
+ end
21
+ if !body
22
+ raise PlivoXMLError, 'No text set for Speak'
23
+ end
24
+ super(body, attributes, @nestables)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module Plivo
2
+ module XML
3
+ class Sub < Element
4
+ @nestables = []
5
+ @valid_attributes = %w(alias)
6
+
7
+ def initialize(body, attributes = {})
8
+ raise PlivoXMLError, 'No text set for sub element' unless body
9
+ unless attributes && attributes[:alias]
10
+ raise PlivoXMLError, 'alias is a required attribute for sub element'
11
+ end
12
+ super(body, attributes)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module Plivo
2
+ module XML
3
+ class User < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[sendDigits sendOnPreanswer sipHeaders]
6
+
7
+ def initialize(body, attributes = {})
8
+ raise PlivoXMLError, 'No user set for User' unless body
9
+ super(body, attributes)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Plivo
2
+ module XML
3
+ class W < Element
4
+ @nestables = %w(Break Cont Emphasis Phoneme Prosody SayAs Sub)
5
+ @valid_attributes = %w(role)
6
+
7
+ VALID_ROLE_ATTRIBUTE_VALUES=%w(amazon:VB amazon:VBD amazon:SENSE_1)
8
+
9
+ def initialize(body, attributes = {})
10
+ if attributes && attributes[:role] && !VALID_ROLE_ATTRIBUTE_VALUES.include?(attributes[:role])
11
+ raise PlivoXMLError, "invalid attribute value #{attributes[:role]} for role"
12
+ end
13
+ super(body, attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Plivo
2
+ module XML
3
+ class Wait < Element
4
+ @nestables = []
5
+ @valid_attributes = %w[length silence minSilence beep]
6
+
7
+ def initialize(attributes = {})
8
+ super(nil, attributes)
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/plivo/xml.rb ADDED
@@ -0,0 +1,39 @@
1
+ require 'rexml/document'
2
+ require 'htmlentities'
3
+
4
+ require_relative 'xml/element'
5
+ require_relative 'xml/response'
6
+ require_relative 'xml/conference'
7
+ require_relative 'xml/dial'
8
+ require_relative 'xml/dtmf'
9
+ require_relative 'xml/get_digits'
10
+ require_relative 'xml/get_input'
11
+ require_relative 'xml/hangup'
12
+ require_relative 'xml/message'
13
+ require_relative 'xml/number'
14
+ require_relative 'xml/play'
15
+ require_relative 'xml/pre_answer'
16
+ require_relative 'xml/record'
17
+ require_relative 'xml/redirect'
18
+ require_relative 'xml/speak'
19
+ require_relative 'xml/user'
20
+ require_relative 'xml/wait'
21
+ require_relative 'xml/break'
22
+ require_relative 'xml/emphasis'
23
+ require_relative 'xml/lang'
24
+ require_relative 'xml/p'
25
+ require_relative 'xml/phoneme'
26
+ require_relative 'xml/prosody'
27
+ require_relative 'xml/s'
28
+ require_relative 'xml/say_as'
29
+ require_relative 'xml/sub'
30
+ require_relative 'xml/w'
31
+ require_relative 'xml/plivo_xml'
32
+ require_relative 'xml/multipartycall'
33
+ require_relative 'xml/cont'
34
+ include Plivo::Exceptions
35
+
36
+ module Plivo
37
+ module XML
38
+ end
39
+ end