vonage 7.7.2 → 7.8.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
2
  SHA256:
3
- metadata.gz: 4d7253aa212d9f85a8dc7e53da784d9277d5c1ef56b554b558967d19e2358a6a
4
- data.tar.gz: 3c7882f459e88fcc1576c9c93e86908db09d405995f3d4908f5ba299c2558257
3
+ metadata.gz: 16cb2584a98415fd28d34ff48e122bba7e74dc3274f3ccbce54e573bb5639d75
4
+ data.tar.gz: 4dde646ce5357983ac61bd80981e758875f0289e535afdb1b961c230895489b8
5
5
  SHA512:
6
- metadata.gz: b97ccb9cbc712896509d5910074592c3a545049e94c4168b5b2a997f5ffcc760054e2ca9b3ef05c33a19e530fe1aec59694b5e741042076e7c6a3f1de51788b9
7
- data.tar.gz: c93e485c0410b15454c2c984d323f087efd2f3d28d768ba7e5e1e51aee89fefe3eaa635aaeea72a8acd9e90cf4fe2d207ecdf2a7ffa396b9345b20c580a6804c
6
+ metadata.gz: ce5cc6037fcc81f6ce5cd99ec6b61a0a237fd94502dd85bd5a7e98bbc768834b8108babc3d4f81ff1f85fc9668d41165b3464f20f1218295b3a462d5343d4482
7
+ data.tar.gz: 464c94d4e284b83c68796f6324ec54a8e0c70d93537b800f8b140d5425db14f575369b1a500e2595cce0559371d363033508cce9c49737bbb6a20be238b0a10e
data/lib/vonage/config.rb CHANGED
@@ -191,7 +191,7 @@ module Vonage
191
191
  #
192
192
  sig { returns(T.nilable(String)) }
193
193
  def token
194
- @token = T.let(nil, T.nilable(String))
194
+ @token = T.let(@token, T.nilable(String))
195
195
  @token || JWT.generate({application_id: application_id}, T.must(private_key))
196
196
  end
197
197
 
data/lib/vonage/jwt.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
  require 'securerandom'
4
4
  require 'openssl'
5
- require 'nexmo-jwt'
5
+ require 'vonage-jwt'
6
6
 
7
7
  module Vonage
8
8
  class JWT
@@ -15,7 +15,7 @@ module Vonage
15
15
  # attribute on the client object.
16
16
  #
17
17
  # Documentation for the Vonage Ruby JWT generator gem can be found at
18
- # https://www.rubydoc.info/github/Nexmo/nexmo-jwt-ruby
18
+ # https://www.rubydoc.info/github/Vonage/vonage-jwt-ruby
19
19
  #
20
20
  # @example
21
21
  # claims = {
@@ -37,7 +37,7 @@ module Vonage
37
37
  raise "Expecting 'private_key' in either the payload or as a separate parameter" if !payload[:private_key] && !private_key
38
38
 
39
39
  payload[:private_key] = private_key if private_key && !payload[:private_key]
40
- @token = Nexmo::JWTBuilder.new(payload).jwt.generate
40
+ @token = Vonage::JWTBuilder.new(payload).jwt.generate
41
41
  end
42
42
  end
43
43
  end
@@ -34,7 +34,6 @@ module Vonage
34
34
  raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
35
35
  raise Vonage::ClientError.new(":name is required in :template") unless message[:name]
36
36
  raise Vonage::ClientError.new(":whatsapp is required in :opts") unless opts[:whatsapp]
37
- raise Vonage::ClientError.new(":policy is required in :whatsapp") unless opts[:whatsapp][:policy]
38
37
  raise Vonage::ClientError.new(":locale is required in :whatsapp") unless opts[:whatsapp][:locale]
39
38
  when 'custom'
40
39
  raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = '7.7.2'
4
+ VERSION = '7.8.1'
5
5
  end
@@ -0,0 +1,107 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+ module Vonage
4
+ class Voice::Actions::Pay
5
+ attr_accessor :amount, :currency, :eventUrl, :prompts, :voice
6
+
7
+ def initialize(attributes= {})
8
+ @amount = attributes.fetch(:amount)
9
+ @currency = attributes.fetch(:currency, nil)
10
+ @eventUrl = attributes.fetch(:eventUrl, nil)
11
+ @prompts = attributes.fetch(:prompts, nil)
12
+ @voice = attributes.fetch(:voice, nil)
13
+
14
+ after_initialize!
15
+ end
16
+
17
+ def action
18
+ create_pay!(self)
19
+ end
20
+
21
+ def create_pay!(builder)
22
+ ncco = [
23
+ {
24
+ action: 'pay',
25
+ amount: builder.amount
26
+ }
27
+ ]
28
+
29
+ ncco[0].merge!(currency: builder.currency) if builder.currency
30
+ ncco[0].merge!(eventUrl: builder.eventUrl) if builder.eventUrl
31
+ ncco[0].merge!(prompts: builder.prompts) if builder.prompts
32
+ ncco[0].merge!(voice: builder.voice) if builder.voice
33
+
34
+ ncco
35
+ end
36
+
37
+ private
38
+
39
+ def after_initialize!
40
+ verify_amount
41
+
42
+ if self.eventUrl
43
+ verify_event_url
44
+ end
45
+
46
+ if self.prompts
47
+ verify_prompts
48
+ end
49
+
50
+ if self.voice
51
+ verify_voice
52
+ end
53
+ end
54
+
55
+ def verify_amount
56
+ verify_amount_class
57
+ verify_amount_value
58
+ end
59
+
60
+ def verify_event_url
61
+ raise ClientError.new("Expected 'eventUrl' parameter to be an Array containing a single string item") unless self.eventUrl.is_a?(Array)
62
+
63
+ uri = URI.parse(self.eventUrl[0])
64
+
65
+ raise ClientError.new("Invalid 'eventUrl' value, must be a valid URL") unless uri.kind_of?(URI::HTTP) || uri.kind_of?(URI::HTTPS)
66
+ end
67
+
68
+ def verify_prompts
69
+ verify_prompts_structure
70
+ verify_prompts_values
71
+ end
72
+
73
+ def verify_voice
74
+ verify_voice_structure
75
+ verify_voice_style if self.voice[:style]
76
+ end
77
+
78
+ def verify_amount_class
79
+ raise ClientError.new("Invalid 'amount' value, must be a float") unless self.amount.is_a?(Float)
80
+ end
81
+
82
+ def verify_amount_value
83
+ raise ClientError.new("Invalid 'amount' value, must be greater than 0") unless self.amount > 0
84
+ end
85
+
86
+ def verify_prompts_structure
87
+ raise ClientError.new("Invalid 'prompt', must be an array of at least one hash") unless self.prompts.is_a?(Array) && !self.prompts.empty? && self.prompts.all?(Hash)
88
+ end
89
+
90
+ def verify_prompts_values
91
+ self.prompts.each do |prompt|
92
+ prompt_keys = prompt.keys
93
+ [:type, :text, :errors].each do |key|
94
+ raise ClientError.new("Invalid 'prompt', '#{key}' is required") unless prompt_keys.include?(key)
95
+ end
96
+ end
97
+ end
98
+
99
+ def verify_voice_structure
100
+ raise ClientError.new("Expected 'voice' value to be a Hash") unless self.voice.is_a?(Hash)
101
+ end
102
+
103
+ def verify_voice_style
104
+ raise ClientError.new("Expected 'style' value to be an Integer") unless self.voice[:style].is_a?(Integer)
105
+ end
106
+ end
107
+ end
data/vonage.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
12
12
  s.summary = 'This is the Ruby Server SDK for Vonage APIs. To use it you\'ll need a Vonage account. Sign up for free at https://www.vonage.com'
13
13
  s.files = Dir.glob('lib/**/*.rb') + %w(LICENSE.txt README.md vonage.gemspec)
14
14
  s.required_ruby_version = '>= 2.5.0'
15
- s.add_dependency('nexmo-jwt', '~> 0.1.2')
15
+ s.add_dependency('vonage-jwt', '~> 0.1.0')
16
16
  s.add_dependency('zeitwerk', '~> 2', '>= 2.2')
17
17
  s.add_dependency('sorbet-runtime', '~> 0.5')
18
18
  s.add_runtime_dependency('rexml')
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vonage
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.7.2
4
+ version: 7.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vonage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: nexmo-jwt
14
+ name: vonage-jwt
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: zeitwerk
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +158,7 @@ files:
158
158
  - lib/vonage/voice/actions/conversation.rb
159
159
  - lib/vonage/voice/actions/input.rb
160
160
  - lib/vonage/voice/actions/notify.rb
161
+ - lib/vonage/voice/actions/pay.rb
161
162
  - lib/vonage/voice/actions/record.rb
162
163
  - lib/vonage/voice/actions/stream.rb
163
164
  - lib/vonage/voice/actions/talk.rb
@@ -191,7 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
192
  - !ruby/object:Gem::Version
192
193
  version: '0'
193
194
  requirements: []
194
- rubygems_version: 3.2.3
195
+ rubygems_version: 3.3.26
195
196
  signing_key:
196
197
  specification_version: 4
197
198
  summary: This is the Ruby Server SDK for Vonage APIs. To use it you'll need a Vonage