vonage 7.7.2 → 7.8.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d7253aa212d9f85a8dc7e53da784d9277d5c1ef56b554b558967d19e2358a6a
4
- data.tar.gz: 3c7882f459e88fcc1576c9c93e86908db09d405995f3d4908f5ba299c2558257
3
+ metadata.gz: 4fa13bcb2f12e1915f331b21aea4646d673622ea2a623daa9ef7b97ef6d64b9a
4
+ data.tar.gz: c7a4129fe95ec0cd72d836f5b267e86429da90d86ba22f4a2b76b06f7a385798
5
5
  SHA512:
6
- metadata.gz: b97ccb9cbc712896509d5910074592c3a545049e94c4168b5b2a997f5ffcc760054e2ca9b3ef05c33a19e530fe1aec59694b5e741042076e7c6a3f1de51788b9
7
- data.tar.gz: c93e485c0410b15454c2c984d323f087efd2f3d28d768ba7e5e1e51aee89fefe3eaa635aaeea72a8acd9e90cf4fe2d207ecdf2a7ffa396b9345b20c580a6804c
6
+ metadata.gz: c7e5cfd257e7b4595c3c2929fc1657e764eed720d0bdff3fba12efd3c852b66eee0f21c3aa424b685412af2dddcf11dfef9d6a13aada0716c5dfa479383ee26c
7
+ data.tar.gz: 18b2657e9a2f371be7c5da6f299bf8e1c1d5e63e6a34fc6b72c468156bb2fb6b4cf93ca38630ce7ce85c41e20687c11980db00e9b1e7eecb0172b2c41b276afa
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
 
@@ -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.0'
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
metadata CHANGED
@@ -1,14 +1,14 @@
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.0
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-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nexmo-jwt
@@ -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.7
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