plivo 4.3.0 → 4.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 20e60eae3b619e892f6e4dd181a0756611f1869049b6c76ee281c1a3422be9c0
4
- data.tar.gz: 126529c60e9c738b3421f286a7a4c836fa94b5269c31db185b44b4b5fbd3186e
2
+ SHA1:
3
+ metadata.gz: a6eff6ff164e91f98639704c53c4a20d9e68357a
4
+ data.tar.gz: b101bbc03a5276a24bde4d488d73abbbd2fa748a
5
5
  SHA512:
6
- metadata.gz: '0804aa44814f59c59a3d4b7336fc7dc1477b59038917b4697b15ce9354ad6f9dcdaaf36a7d37674e746e401721b5f103b517c7bdef8d44bb054bdace0f7bc984'
7
- data.tar.gz: 8d9a9763408b9eefb3fd88384e59f4824148eb8ce472568ad1569b19169b928d67e6eb51b64320acf4e03a7b33525f6284b4e20ad846f9e4b51fe2c116ed06f5
6
+ metadata.gz: 1022252f290644d4fd32dd0deca29332a2ccf292b360d645c1d853c3ca8162a0101116d332b4530123e9ccad9fdcb4de753da22f9fa9a7ed12429487b3b22f44
7
+ data.tar.gz: 2427aafbfe52987e671fbdc8642daeb4a96cdabe8be7ebfad9c2c05c050b5e52a624f29b78d78a435e2071d79b874b67a1d9241538631edacb21d1464ba1ac2e
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ ## [4.3.1](https://github.com/plivo/plivo-ruby/releases/tag/v4.3.1) (2019-10-16)
4
+ - Add SSML support
5
+
3
6
  ## [4.3.0](https://github.com/plivo/plivo-ruby/releases/tag/v4.3.0) (2019-03-12)
4
7
  - Add PHLO support
5
8
  - Add Multi-Party Call triggers
@@ -0,0 +1,7 @@
1
+ #!groovy
2
+
3
+ @Library('plivo_standard_libs@sdks') _
4
+
5
+ sdksPipeline ([
6
+ buildContainer: 'plivo/jenkins-ci/plivo-rubysdk:master'
7
+ ])
data/README.md CHANGED
@@ -8,7 +8,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'plivo', '>= 4.1.6'
11
+ gem 'plivo', '>= 4.3.1'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -19,6 +19,10 @@ Or install it yourself as:
19
19
 
20
20
  $ gem install plivo
21
21
 
22
+ For features in beta, use the beta branch:
23
+
24
+ $ gem install plivo --pre
25
+
22
26
  If you have the `0.3.19` version (a.k.a legacy) already installed, you may have to first uninstall it before installing the new version.
23
27
 
24
28
  ## Getting started
@@ -125,6 +129,37 @@ This generates the following XML:
125
129
  </Response>
126
130
  ```
127
131
 
132
+ ### Run a PHLO
133
+
134
+ ```ruby
135
+ require 'rubygems'
136
+ require 'plivo'
137
+
138
+ include Plivo
139
+
140
+ AUTH_ID = 'AUTH_ID'
141
+ AUTH_TOKEN = 'AUTH_TOKEN'
142
+
143
+ client = Phlo.new(AUTH_ID, AUTH_TOKEN)
144
+
145
+ # if credentials are stored in the PLIVO_AUTH_ID and the PLIVO_AUTH_TOKEN environment variables
146
+ # then initialize client as:
147
+ # client = Phlo.new
148
+
149
+ # run a phlo:
150
+ begin
151
+ #parameters set in PHLO - params
152
+ params = {
153
+ from: '9999999999',
154
+ to: '0000000000'
155
+ }
156
+ response = phlo.run(params)
157
+ puts response
158
+ rescue PlivoRESTError => e
159
+ puts 'Exception: ' + e.message
160
+ end
161
+ ```
162
+
128
163
  ### More examples
129
164
  Refer to the [Ruby API Reference](https://api-reference.plivo.com/latest/ruby/introduction/overview) for more examples. Also refer to the [guide to setting up dev environment](https://developers.plivo.com/getting-started/setting-up-dev-environment/) on [Plivo Developers Portal](https://developers.plivo.com) to setup a Sinatra server & use it to test out your integration in under 5 minutes.
130
165
 
@@ -0,0 +1,7 @@
1
+ ---
2
+ parent: central
3
+ serviceName: plivo-ruby
4
+ language: ruby-sdk
5
+ build:
6
+ command: |
7
+ gem build plivo.gemspec
@@ -1,3 +1,3 @@
1
1
  module Plivo
2
- VERSION = '4.3.0'.freeze
2
+ VERSION = '4.3.1'.freeze
3
3
  end
@@ -17,6 +17,16 @@ require_relative 'xml/redirect'
17
17
  require_relative 'xml/speak'
18
18
  require_relative 'xml/user'
19
19
  require_relative 'xml/wait'
20
+ require_relative 'xml/break'
21
+ require_relative 'xml/emphasis'
22
+ require_relative 'xml/lang'
23
+ require_relative 'xml/p'
24
+ require_relative 'xml/phoneme'
25
+ require_relative 'xml/prosody'
26
+ require_relative 'xml/s'
27
+ require_relative 'xml/say_as'
28
+ require_relative 'xml/sub'
29
+ require_relative 'xml/w'
20
30
  require_relative 'xml/plivo_xml'
21
31
 
22
32
  include Plivo::Exceptions
@@ -0,0 +1,31 @@
1
+ module Plivo
2
+ module XML
3
+ class Break < Element
4
+ @nestables = []
5
+ @valid_attributes = %w(strength time)
6
+ VALID_STRENGTH_VALUES= %w(none x-weak weak medium strong x-strong)
7
+
8
+ def initialize(attributes = {})
9
+ if attributes && attributes[:strength] && !VALID_STRENGTH_VALUES.include?(attributes[:strength])
10
+ raise PlivoXMLError, "invalid attribute value #{attributes[:strength]} for strength"
11
+ end
12
+ if attributes && attributes[:time]
13
+ if attributes[:time].downcase().include?('ms')
14
+ time = attributes[:time].split('ms')[0].to_i
15
+ if time<= 0 || time >10000
16
+ raise PlivoXMLError, "invalid attribute value #{attributes[:time]} for time attribute. Value for time in milliseconds should be > 0 or < 10000"
17
+ end
18
+ elsif attributes[:time].downcase().include?('s')
19
+ time = attributes[:time].split('s')[0].to_i
20
+ if time<= 0 || time >10
21
+ raise PlivoXMLError, "invalid attribute value #{attributes[:time]} for time attribute. Value for time in seconds should be > 0 or < 10"
22
+ end
23
+ else
24
+ raise PlivoXMLError, "invalid attribute value #{attributes[:time]} for time attribute"
25
+ end
26
+ end
27
+ super(nil, attributes)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -6,13 +6,25 @@ module Plivo
6
6
  end
7
7
  @nestables = []
8
8
  @valid_attributes = []
9
+ SSML_TAGS=%w[Break Emphasis Lang P Phoneme Prosody S SayAs Sub W]
9
10
 
10
11
  attr_accessor :node, :name
11
12
 
12
- def initialize(body = nil, attributes = {})
13
+ def hyphenate(pascal_cased_word)
14
+ pascal_cased_word.to_s.gsub(/::/, '/').
15
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1-\2').
16
+ gsub(/([a-z\d])([A-Z])/,'\1-\2').
17
+ downcase
18
+ end
19
+
20
+ def initialize(body = nil, attributes = {}, nestables=self.class.nestables)
13
21
  @name = self.class.name.split('::')[2]
14
22
  @body = body
15
- @node = REXML::Element.new @name
23
+ tagname = @name
24
+ if SSML_TAGS.include?(@name)
25
+ tagname = hyphenate(@name)
26
+ end
27
+ @node = REXML::Element.new tagname
16
28
  attributes.each do |k, v|
17
29
  if self.class.valid_attributes.include?(k.to_s)
18
30
  @node.attributes[k.to_s] = convert_value(v)
@@ -20,7 +32,7 @@ module Plivo
20
32
  raise PlivoXMLError, "invalid attribute #{k} for #{@name}"
21
33
  end
22
34
  end
23
-
35
+ @nestables = nestables
24
36
  @node.text = @body if @body
25
37
 
26
38
  # Allow for nested "nestable" elements using a code block
@@ -33,6 +45,10 @@ module Plivo
33
45
  yield(self) if block_given?
34
46
  end
35
47
 
48
+ def add_attribute(attribute, value)
49
+ @node.add_attribute(attribute, value)
50
+ end
51
+
36
52
  def method_missing(method, *args, &block)
37
53
  # Handle the addElement methods
38
54
  method = Regexp.last_match(1).to_sym if method.to_s =~ /^add(.*)/
@@ -63,7 +79,7 @@ module Plivo
63
79
 
64
80
  def add(element)
65
81
  raise PlivoXMLError, 'invalid element' unless element
66
- if self.class.nestables.include?(element.name)
82
+ if @nestables.include?(element.name)
67
83
  @node.elements << element.node
68
84
  element
69
85
  else
@@ -0,0 +1,17 @@
1
+ module Plivo
2
+ module XML
3
+ class Emphasis < Element
4
+ @nestables = %w(Break Emphasis Lang Phoneme Prosody SayAs Sub W)
5
+ @valid_attributes = %w(level)
6
+
7
+ VALID_LEVEL_ATTRIBUTE_VALUE=%w(strong moderate reduced)
8
+
9
+ def initialize(body, attributes = {})
10
+ if attributes && attributes[:level] && !VALID_LEVEL_ATTRIBUTE_VALUE.include?(attributes[:level])
11
+ raise PlivoXMLError, "invalid attribute value #{attributes[:level]} for level"
12
+ end
13
+ super(body, attributes)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ module Plivo
2
+ module XML
3
+ class Lang < Element
4
+ @nestables = %w(Break Emphasis Lang P Phoneme Prosody S SayAs Sub W)
5
+ @valid_attributes = %w(xmllang)
6
+
7
+ VALID_LANG_ATTRIBUTE_VALUES = [
8
+ 'arb', 'cmn-CN','da-DK','nl-NL','en-AU',
9
+ 'en-GB', 'en-IN','en-US','en-GB-WLS','fr-FR',
10
+ 'fr-CA','de-DE','hi-IN','is-IS','it-IT',
11
+ 'ja-JP','ko-KR','nb-NO','pl-PL','pt-BR',
12
+ 'pt-PT','ro-RO','ru-RU','es-ES','es-MX',
13
+ 'es-US','sv-SE','tr-TR','cy-GB']
14
+
15
+
16
+ def initialize(body, attributes = {})
17
+ if attributes && attributes[:xmllang]
18
+ unless VALID_LANG_ATTRIBUTE_VALUES.include?(attributes[:xmllang])
19
+ raise PlivoXMLError, "invalid attribute value #{attributes[:xmllang]} for xmllang"
20
+ end
21
+ super(body, {})
22
+ add_attribute("xml:lang", attributes[:xmllang])
23
+ else
24
+ raise PlivoXMLError, 'xmllang attribute is a required attribute for lang'
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module Plivo
2
+ module XML
3
+ class P < Element
4
+ @nestables = %w(Break 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,28 @@
1
+ module Plivo
2
+ module XML
3
+ class Prosody < Element
4
+ @nestables = %w(Break 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,12 @@
1
+ module Plivo
2
+ module XML
3
+ class S < Element
4
+ @nestables = %w(Break 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
@@ -1,16 +1,27 @@
1
1
  module Plivo
2
2
  module XML
3
3
  class Speak < Element
4
- @nestables = []
5
4
  @valid_attributes = %w[voice language loop]
6
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
+
7
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 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
8
21
  if !body
9
22
  raise PlivoXMLError, 'No text set for Speak'
10
- else
11
- body = HTMLEntities.new(:html4).encode(body, :decimal)
12
23
  end
13
- super(body, attributes)
24
+ super(body, attributes, @nestables)
14
25
  end
15
26
  end
16
27
  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,17 @@
1
+ module Plivo
2
+ module XML
3
+ class W < Element
4
+ @nestables = %w(Break 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
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plivo
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Plivo SDKs Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -144,9 +144,11 @@ files:
144
144
  - AUTHORS.md
145
145
  - CHANGELOG.md
146
146
  - Gemfile
147
+ - Jenkinsfile
147
148
  - LICENSE.txt
148
149
  - README.md
149
150
  - Rakefile
151
+ - ci/config.yml
150
152
  - examples/conference_bridge.rb
151
153
  - examples/multi_party_call.rb
152
154
  - examples/phlos.rb
@@ -177,22 +179,32 @@ files:
177
179
  - lib/plivo/utils.rb
178
180
  - lib/plivo/version.rb
179
181
  - lib/plivo/xml.rb
182
+ - lib/plivo/xml/break.rb
180
183
  - lib/plivo/xml/conference.rb
181
184
  - lib/plivo/xml/dial.rb
182
185
  - lib/plivo/xml/dtmf.rb
183
186
  - lib/plivo/xml/element.rb
187
+ - lib/plivo/xml/emphasis.rb
184
188
  - lib/plivo/xml/get_digits.rb
185
189
  - lib/plivo/xml/hangup.rb
190
+ - lib/plivo/xml/lang.rb
186
191
  - lib/plivo/xml/message.rb
187
192
  - lib/plivo/xml/number.rb
193
+ - lib/plivo/xml/p.rb
194
+ - lib/plivo/xml/phoneme.rb
188
195
  - lib/plivo/xml/play.rb
189
196
  - lib/plivo/xml/plivo_xml.rb
190
197
  - lib/plivo/xml/pre_answer.rb
198
+ - lib/plivo/xml/prosody.rb
191
199
  - lib/plivo/xml/record.rb
192
200
  - lib/plivo/xml/redirect.rb
193
201
  - lib/plivo/xml/response.rb
202
+ - lib/plivo/xml/s.rb
203
+ - lib/plivo/xml/say_as.rb
194
204
  - lib/plivo/xml/speak.rb
205
+ - lib/plivo/xml/sub.rb
195
206
  - lib/plivo/xml/user.rb
207
+ - lib/plivo/xml/w.rb
196
208
  - lib/plivo/xml/wait.rb
197
209
  - plivo.gemspec
198
210
  homepage: https://github.com/plivo/plivo-ruby
@@ -215,7 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
227
  version: '0'
216
228
  requirements: []
217
229
  rubyforge_project:
218
- rubygems_version: 2.7.8
230
+ rubygems_version: 2.6.14.4
219
231
  signing_key:
220
232
  specification_version: 4
221
233
  summary: A Ruby SDK to make voice calls & send SMS using Plivo and to generate Plivo