vonage 7.27.0 → 7.28.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: 1ef29adae44fffb9754118333b6a82cac7172cb536eb2b4ec31644694c6388ef
4
- data.tar.gz: 43496b6bcf0db687cdef8bdd4506db140fea685f48a306abc1aac4325f8300f5
3
+ metadata.gz: cf9fa1d6af062f6e7d75fb963409c9a0f040baed06cddba83bd6fa6898d81277
4
+ data.tar.gz: 5962037b1656b38a3805bbea7a7b166e99377408700b93d23a268739f2b67b09
5
5
  SHA512:
6
- metadata.gz: 055f8c7f7e0bcdc9eb8c59f0110b6bbfb850a1d725468f0e23d1e5bf736b5acdf3a9dfdbf0e17e0f4e5b54fabe6415173c2d8f39106b73ca336389f4f8483baa
7
- data.tar.gz: 72ad26a1bf8696cd465ea2f89f7ab190803a29ee13dcb3680238504b9c81c6264dc444e2e12c0e078a19dd2042ea8fe31e8988e32162413325fa7be5a56444d4
6
+ metadata.gz: ed10b77ccd84032ac6aed5a06b4dc0978e49cfcc966b1e2208ee382bfacbd7ee507319470ac8b3e12758fac8571b1d979a25b4231e6ee11c0d1f6ca928bc917f
7
+ data.tar.gz: 971e7f19c8e151891001e2101cee4ad756e2109c70df5a2c9bee272470909a7f25cb287a09ac10b138c4fff73f930ddde187612aae42f3103bba1df88506c0c9
data/README.md CHANGED
@@ -14,6 +14,7 @@ need a Vonage account. Sign up [for free at vonage.com][signup].
14
14
  * [Logging](#logging)
15
15
  * [Exceptions](#exceptions)
16
16
  * [Overriding the default hosts](#overriding-the-default-hosts)
17
+ * [HTTP Client Configuration](#http-client-configuration)
17
18
  * [JWT authentication](#jwt-authentication)
18
19
  * [Webhook signatures](#webhook-signatures)
19
20
  * [Pagination](#pagination)
@@ -179,6 +180,33 @@ client = Vonage::Client.new(
179
180
 
180
181
  By default the hosts are set to `api.nexmo.com` and `rest.nexmo.com`, respectively.
181
182
 
183
+ ### HTTP Client Configuration
184
+
185
+ It is possible to set configuration options on the HTTP client. This can be don in a couple of ways.
186
+
187
+ 1. Using an `:http` key during `Vonage::Client` instantiation, for example:
188
+ ```ruby
189
+ client = Vonage::Client.new(
190
+ api_key: 'YOUR-API-KEY',
191
+ api_secret: 'YOUR-API-SECRET',
192
+ http: {
193
+ max_retries: 1
194
+ }
195
+ )
196
+ ```
197
+
198
+ 2. By using the `http=` setter on the `Vonage::Config` object, for example:
199
+ ```ruby
200
+ client = Vonage::Client.new(
201
+ api_key: 'YOUR-API-KEY',
202
+ api_secret: 'YOUR-API-SECRET'
203
+ )
204
+
205
+ client.config.http = { max_retries: 1 }
206
+ ```
207
+
208
+ The Vonage Ruby SDK uses the [`Net::HTTP::Persistent` library](https://github.com/drbrain/net-http-persistent) as an HTTP client. For available configuration options see [the documentation for that library](https://www.rubydoc.info/gems/net-http-persistent/3.0.0/Net/HTTP/Persistent).
209
+
182
210
  ### Webhook signatures
183
211
 
184
212
  Certain Vonage APIs provide signed [webhooks](https://developer.vonage.com/en/getting-started/concepts/webhooks) as a means of verifying the origin of the webhooks. The exact signing mechanism varies depending on the API.
@@ -460,6 +488,66 @@ if code_check.http_response.code == '200'
460
488
  end
461
489
  ```
462
490
 
491
+ ### Working with Verify Custom Templates and Template Fragments
492
+
493
+ Verify custom templates allow you to customize the message sent to deliver an OTP to your users, rather than using the default Vonage templates. See the [Template Management Guide document](https://developer.vonage.com/en/verify/guides/custom-templates) for more information.
494
+
495
+ #### Templates
496
+
497
+ ```ruby
498
+ # Get a list of all templates
499
+ template_list = verify.templates.list
500
+
501
+ # Get details of a specific template
502
+ template = verify.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
503
+
504
+ # Create a new template
505
+ verify.templates.create(name: 'my-template')
506
+
507
+ # Update an existing template
508
+ verify.templates.update(
509
+ template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
510
+ name: 'my-updated-template'
511
+ )
512
+
513
+ # Delete a template
514
+ verify.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
515
+ ```
516
+
517
+ #### Template Fragments
518
+
519
+ ```ruby
520
+ # Get a list of template fragments for a specific template
521
+ template_fragment_list = verify.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
522
+
523
+ # Get details of a specific template fragment
524
+ template_fragment = verify.template_fragments.info(
525
+ template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
526
+ template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
527
+ )
528
+
529
+ # Create a new template fragement
530
+ verify.template_fragments.create(
531
+ template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
532
+ channel: 'sms',
533
+ locale: 'en-gb',
534
+ text: 'Your code is: ${code}'
535
+ )
536
+
537
+ # Update an existing template fragment
538
+ verify.template_fragments.update(
539
+ template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
540
+ template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc1',
541
+ text: 'Your one-time code is: ${code}'
542
+ )
543
+
544
+ # Delete a template fragment
545
+ verify.template_fragments.delete(
546
+ template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
547
+ template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
548
+ )
549
+ ```
550
+
463
551
  ## Voice API
464
552
 
465
553
  The [Vonage Voice API](The [Vonage Verify API v2](https://developer.vonage.com/en/verify/verify-v2/overview) allows you to automate voice interactions by creating calls, streaming audio, playing text to speech, playing DTMF tones, and other actions. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/voice) listing all the Voice API capabilities.
data/lib/vonage/http.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
- require 'net/http'
3
+ require 'net/http/persistent'
4
4
 
5
5
  module Vonage
6
6
  module HTTP
@@ -21,7 +21,7 @@ module Vonage
21
21
  end
22
22
  end
23
23
 
24
- sig { params(http: Net::HTTP).returns(T::Hash[Symbol, T.untyped]) }
24
+ sig { params(http: Net::HTTP::Persistent).returns(T::Hash[Symbol, T.untyped]) }
25
25
  def set(http)
26
26
  @hash.each do |name, value|
27
27
  http.public_send(defined_options.fetch(name), value)
@@ -34,7 +34,7 @@ module Vonage
34
34
  def defined_options
35
35
  @defined_options = T.let(@defined_options, T.nilable(T::Hash[Symbol, T.untyped]))
36
36
 
37
- @defined_options ||= Net::HTTP.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash|
37
+ @defined_options ||= Net::HTTP::Persistent.instance_methods.grep(/\w=\z/).each_with_object({}) do |name, hash|
38
38
  hash[name.to_s.chomp('=').to_sym] = name
39
39
  end
40
40
  end
@@ -0,0 +1,11 @@
1
+ # typed: true
2
+
3
+ class Vonage::Verify2::TemplateFragments::ListResponse < Vonage::Response
4
+ include Enumerable
5
+
6
+ def each
7
+ return enum_for(:each) unless block_given?
8
+
9
+ @entity._embedded.template_fragments.each { |item| yield item }
10
+ end
11
+ end
@@ -0,0 +1,125 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Verify2::TemplateFragments < Namespace
6
+ CHANNELS = ['sms', 'voice'].freeze
7
+
8
+ self.authentication = BearerToken
9
+
10
+ self.request_body = JSON
11
+
12
+ # Get a list of of template fragments for a specific template.
13
+ #
14
+ # @example
15
+ # template_fragment_list = client.verify2.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
16
+ #
17
+ # @param [required, String] :template_id. The ID of the template for which to retreive the fragments
18
+ #
19
+ # @param [optional, Integer] :page_size. The amount of template fragments to list per page
20
+ #
21
+ # @param [optional, Integer] :page. The page number to retrieve
22
+ #
23
+ # @return [ListResponse]
24
+ #
25
+ # @see https://developer.vonage.com/en/api/verify.v2#listTemplateFragments
26
+ def list(template_id:, **params)
27
+ request("/v2/verify/templates/#{template_id}/template_fragments", params: params, response_class: ListResponse)
28
+ end
29
+
30
+ # Get details of a specific template fragment.
31
+ #
32
+ # @example
33
+ # template_fragment = client.verify2.template_fragments.info(
34
+ # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
35
+ # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
36
+ # )
37
+ #
38
+ # @param [required, String] :template_id. The ID of the template for which to retreive the fragment
39
+ #
40
+ # @param [required, String] :template_fragment_id. The ID of the fragment to be retreived
41
+ #
42
+ # @return [Response]
43
+ #
44
+ # @see https://developer.vonage.com/en/api/verify.v2#getTemplateFragment
45
+ def info(template_id:, template_fragment_id:)
46
+ request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}")
47
+ end
48
+
49
+ # Create a new template fragment.
50
+ #
51
+ # @example
52
+ # client.verify2.template_fragments.create(
53
+ # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
54
+ # channel: 'sms',
55
+ # locale: 'en-gb',
56
+ # text: 'Your code is: ${code}'
57
+ # )
58
+ #
59
+ # @param [required, String] :template_id. The ID of the template for which to create the fragment
60
+ #
61
+ # @param [required, String] :channel. The verification channel for which to create the fragment. Must be one of 'sms' or 'voice'
62
+ #
63
+ # @param [required, String] :locale. The locale for which to create the fragment.
64
+ #
65
+ # @param [required, String] :text. The text to be used in the template fragment.
66
+ # There are 4 reserved variables available to use as part of the text: ${code}, ${brand}, ${time-limit} and ${time-limit-unit}
67
+ #
68
+ # @return [Response]
69
+ #
70
+ # @see https://developer.vonage.com/en/api/verify.v2#addTemplateFragmentToTemplate
71
+ def create(template_id:, channel:, locale:, text:)
72
+ raise ArgumentError, "Invalid 'channel' #{channel}. Must be one of #{CHANNELS.join(', ')}" unless CHANNELS.include?(channel)
73
+ request(
74
+ "/v2/verify/templates/#{template_id}/template_fragments",
75
+ params: {
76
+ channel: channel,
77
+ locale: locale,
78
+ text: text
79
+ },
80
+ type: Post)
81
+ end
82
+
83
+ # Update an existing template fragment.
84
+ #
85
+ # @example
86
+ # client.verify2.template_fragments.update(
87
+ # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
88
+ # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19',
89
+ # text: 'Your one-time code is: ${code}'
90
+ # )
91
+ #
92
+ # @param [required, String] :template_id. The ID of the template with which the fragment to be updated is associated
93
+ #
94
+ # @param [required, String] :template_fragment_id. The ID of the fragment to be updated
95
+ #
96
+ # @param [required, String] :text. The text to be used in the template fragment.
97
+ # There are 4 reserved variables available to use as part of the text: ${code}, ${brand}, ${time-limit} and ${time-limit-unit}
98
+ #
99
+ # @return [Response]
100
+ #
101
+ # @see https://developer.vonage.com/en/api/verify.v2#updateTemplateFragment
102
+ def update(template_id:, template_fragment_id:, text:)
103
+ request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", params: {text: text}, type: Patch)
104
+ end
105
+
106
+ # Delete a template fragment.
107
+ #
108
+ # @example
109
+ # client.verify2.template_fragments.delete(
110
+ # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9',
111
+ # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19'
112
+ # )
113
+ #
114
+ # @param [required, String] :template_id. The ID of the template with which the fragment to be deleted is associated
115
+ #
116
+ # @param [required, String] :template_fragment_id. The ID of the fragment to be deleted
117
+ #
118
+ # @return [Response]
119
+ #
120
+ # @see https://developer.vonage.com/en/api/verify.v2#deleteTemplateFragment
121
+ def delete(template_id:, template_fragment_id:)
122
+ request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", type: Delete)
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,11 @@
1
+ # typed: true
2
+
3
+ class Vonage::Verify2::Templates::ListResponse < Vonage::Response
4
+ include Enumerable
5
+
6
+ def each
7
+ return enum_for(:each) unless block_given?
8
+
9
+ @entity._embedded.templates.each { |item| yield item }
10
+ end
11
+ end
@@ -0,0 +1,86 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ module Vonage
5
+ class Verify2::Templates < Namespace
6
+ self.authentication = BearerToken
7
+
8
+ self.request_body = JSON
9
+
10
+ # Get a list of all templates.
11
+ #
12
+ # @example
13
+ # template_list = client.verify2.templates.list
14
+ #
15
+ # @param [optional, Integer] :page_size. The amount of templates to list per page
16
+ #
17
+ # @param [optional, Integer] :page. The page number to retrieve
18
+ #
19
+ # @return [ListResponse]
20
+ #
21
+ # @see https://developer.vonage.com/en/api/verify.v2#listTemplates
22
+ def list(**params)
23
+ request('/v2/verify/templates', params: params, response_class: ListResponse)
24
+ end
25
+
26
+ # Get details of a specific template.
27
+ #
28
+ # @example
29
+ # template = client.verify2.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
30
+ #
31
+ # @param [required, String] :template_id. The ID of the template to be retreived
32
+ #
33
+ # @return [Response]
34
+ #
35
+ # @see https://developer.vonage.com/en/api/verify.v2#getTemplate
36
+ def info(template_id:)
37
+ request('/v2/verify/templates/' + template_id)
38
+ end
39
+
40
+ # Create a new template.
41
+ #
42
+ # @example
43
+ # client.verify2.templates.create(name: 'my-template')
44
+ #
45
+ # @param [required, String] :name. The name of the template. The following characters are permitted: [A-Z a-z 0-9 _ -]
46
+ #
47
+ # @return [Response]
48
+ #
49
+ # @see https://developer.vonage.com/en/api/verify.v2#createTemplate
50
+ def create(name:)
51
+ request('/v2/verify/templates', params: { name: name }, type: Post)
52
+ end
53
+
54
+ # Update an existing template.
55
+ #
56
+ # @example
57
+ # client.verify2.templates.update(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', name: 'my-updated-template')
58
+ #
59
+ # @param [required, String] :template_id. The ID of the template to be updated
60
+ #
61
+ # @param [optional, String] :name. The name of the template. The following characters are permitted: [A-Z a-z 0-9 _ -]
62
+ #
63
+ # @param [optional, Boolean] :is_default. Whether the template is the default template for a specific locale/channel combination
64
+ #
65
+ # @return [Response]
66
+ #
67
+ # @see https://developer.vonage.com/en/api/verify.v2#updateTemplate
68
+ def update(template_id:, **params)
69
+ request('/v2/verify/templates/' + template_id, params: params, type: Patch)
70
+ end
71
+
72
+ # Delete a template.
73
+ #
74
+ # @example
75
+ # client.verify2.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9')
76
+ #
77
+ # @param [required, String] :template_id. The ID of the template to be deleted
78
+ #
79
+ # @return [Response]
80
+ #
81
+ # @see https://developer.vonage.com/en/api/verify.v2#deleteTemplate
82
+ def delete(template_id:)
83
+ request('/v2/verify/templates/' + template_id, type: Delete)
84
+ end
85
+ end
86
+ end
@@ -96,5 +96,17 @@ module Vonage
96
96
  def workflow_builder
97
97
  WorkflowBuilder.itself
98
98
  end
99
+
100
+ # @return [Templates]
101
+ # Returns existing or instantiates a new Vonage::Verify2::Templates object
102
+ def templates
103
+ @templates ||= Templates.new(@config)
104
+ end
105
+
106
+ # @return [TemplateFragments]
107
+ # Returns existing or instantiates a new Vonage::Verify2::Templates object
108
+ def template_fragments
109
+ @template_fragments ||= TemplateFragments.new(@config)
110
+ end
99
111
  end
100
112
  end
@@ -1,5 +1,5 @@
1
1
  # typed: strong
2
2
 
3
3
  module Vonage
4
- VERSION = '7.27.0'
4
+ VERSION = '7.28.0'
5
5
  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.27.0
4
+ version: 7.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vonage
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-28 00:00:00.000000000 Z
11
+ date: 2024-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vonage-jwt
@@ -238,6 +238,10 @@ files:
238
238
  - lib/vonage/verify2/channels/whats_app.rb
239
239
  - lib/vonage/verify2/channels/whats_app_interactive.rb
240
240
  - lib/vonage/verify2/start_verification_options.rb
241
+ - lib/vonage/verify2/template_fragments.rb
242
+ - lib/vonage/verify2/template_fragments/list_response.rb
243
+ - lib/vonage/verify2/templates.rb
244
+ - lib/vonage/verify2/templates/list_response.rb
241
245
  - lib/vonage/verify2/workflow.rb
242
246
  - lib/vonage/verify2/workflow_builder.rb
243
247
  - lib/vonage/version.rb
@@ -293,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
297
  - !ruby/object:Gem::Version
294
298
  version: '0'
295
299
  requirements: []
296
- rubygems_version: 3.5.11
300
+ rubygems_version: 3.5.16
297
301
  signing_key:
298
302
  specification_version: 4
299
303
  summary: This is the Ruby Server SDK for Vonage APIs. To use it you'll need a Vonage