From e5882e3890bf7019ffaec1a3c930de6f5933d500 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 18 Oct 2024 11:07:14 +0100 Subject: [PATCH 1/8] Creating outline structure for Verify2 Templates --- lib/vonage/verify2/template_fragments.rb | 8 ++++++++ lib/vonage/verify2/templates.rb | 8 ++++++++ lib/vonage/verify2/templates/list_response.rb | 11 +++++++++++ .../verify2/templates_fragments/list_response.rb | 11 +++++++++++ 4 files changed, 38 insertions(+) create mode 100644 lib/vonage/verify2/template_fragments.rb create mode 100644 lib/vonage/verify2/templates.rb create mode 100644 lib/vonage/verify2/templates/list_response.rb create mode 100644 lib/vonage/verify2/templates_fragments/list_response.rb diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb new file mode 100644 index 00000000..e3eb9384 --- /dev/null +++ b/lib/vonage/verify2/template_fragments.rb @@ -0,0 +1,8 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2::TemplateFragments + + end +end diff --git a/lib/vonage/verify2/templates.rb b/lib/vonage/verify2/templates.rb new file mode 100644 index 00000000..5b151250 --- /dev/null +++ b/lib/vonage/verify2/templates.rb @@ -0,0 +1,8 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2::Templates + + end +end diff --git a/lib/vonage/verify2/templates/list_response.rb b/lib/vonage/verify2/templates/list_response.rb new file mode 100644 index 00000000..801cdc15 --- /dev/null +++ b/lib/vonage/verify2/templates/list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Verify2::Templates::ListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.templates.each { |item| yield item } + end +end diff --git a/lib/vonage/verify2/templates_fragments/list_response.rb b/lib/vonage/verify2/templates_fragments/list_response.rb new file mode 100644 index 00000000..13eac32a --- /dev/null +++ b/lib/vonage/verify2/templates_fragments/list_response.rb @@ -0,0 +1,11 @@ +# typed: true + +class Vonage::Verify2::TemplateFragments::ListResponse < Vonage::Response + include Enumerable + + def each + return enum_for(:each) unless block_given? + + @entity._embedded.template_fragments.each { |item| yield item } + end +end From 31615a122c31def52346804bad150dd619d944bf Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 18 Oct 2024 11:29:16 +0100 Subject: [PATCH 2/8] Implementing templatesand template_fragments getters --- lib/vonage/verify2.rb | 12 ++++++++++++ lib/vonage/verify2/template_fragments.rb | 2 +- lib/vonage/verify2/templates.rb | 2 +- test/vonage/verify2_test.rb | 8 ++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 9027b7d7..9dd373b9 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -96,5 +96,17 @@ def workflow def workflow_builder WorkflowBuilder.itself end + + # @return [Templates] + # Returns existing or instantiates a new Vonage::Verify2::Templates object + def templates + @templates ||= Templates.new(@config) + end + + # @return [TemplateFragments] + # Returns existing or instantiates a new Vonage::Verify2::Templates object + def template_fragments + @template_fragments ||= TemplateFragments.new(@config) + end end end diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb index e3eb9384..bd8b218c 100644 --- a/lib/vonage/verify2/template_fragments.rb +++ b/lib/vonage/verify2/template_fragments.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true module Vonage - class Verify2::TemplateFragments + class Verify2::TemplateFragments < Namespace end end diff --git a/lib/vonage/verify2/templates.rb b/lib/vonage/verify2/templates.rb index 5b151250..ba017bd3 100644 --- a/lib/vonage/verify2/templates.rb +++ b/lib/vonage/verify2/templates.rb @@ -2,7 +2,7 @@ # frozen_string_literal: true module Vonage - class Verify2::Templates + class Verify2::Templates < Namespace end end diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index f2aa08e3..722b6e8c 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -215,4 +215,12 @@ def test_workflow_method def test_workflow_builder_method assert_equal Vonage::Verify2::WorkflowBuilder, verify2.workflow_builder end + + def test_templates_method + assert_instance_of Vonage::Verify2::Templates, verify2.templates + end + + def test_template_fragments_method + assert_instance_of Vonage::Verify2::TemplateFragments, verify2.template_fragments + end end From fb96878c4a213656b96d560846c71f7ae53b1fbb Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 18 Oct 2024 12:56:20 +0100 Subject: [PATCH 3/8] Implementing Verify2 Templates methods --- lib/vonage/verify2/template_fragments.rb | 4 ++ lib/vonage/verify2/templates.rb | 24 ++++++- test/vonage/verify2/templates_test.rb | 81 ++++++++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 test/vonage/verify2/templates_test.rb diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb index bd8b218c..a1861ada 100644 --- a/lib/vonage/verify2/template_fragments.rb +++ b/lib/vonage/verify2/template_fragments.rb @@ -3,6 +3,10 @@ module Vonage class Verify2::TemplateFragments < Namespace + self.authentication = BearerToken + + self.request_body = JSON + end end diff --git a/lib/vonage/verify2/templates.rb b/lib/vonage/verify2/templates.rb index ba017bd3..5af4c8c6 100644 --- a/lib/vonage/verify2/templates.rb +++ b/lib/vonage/verify2/templates.rb @@ -3,6 +3,28 @@ module Vonage class Verify2::Templates < Namespace - + self.authentication = BearerToken + + self.request_body = JSON + + def list(**params) + request('/v2/verify/templates', params: params, response_class: ListResponse) + end + + def info(template_id:) + request('/v2/verify/templates/' + template_id) + end + + def create(name:) + request('/v2/verify/templates', params: { name: name }, type: Post) + end + + def update(template_id:, **params) + request('/v2/verify/templates/' + template_id, params: params, type: Patch) + end + + def delete(template_id:) + request('/v2/verify/templates/' + template_id, type: Delete) + end end end diff --git a/test/vonage/verify2/templates_test.rb b/test/vonage/verify2/templates_test.rb new file mode 100644 index 00000000..dc31aa04 --- /dev/null +++ b/test/vonage/verify2/templates_test.rb @@ -0,0 +1,81 @@ +# typed: false + +class Vonage::Verify2::TemplatesTest < Vonage::Test + def templates + Vonage::Verify2::Templates.new(config) + end + + def template_id + '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9' + end + + def templates_uri + 'https://api.nexmo.com/v2/verify/templates' + end + + def template_uri + 'https://api.nexmo.com/v2/verify/templates/' + template_id + end + + def templates_list_response + { body: '{"_embedded": {"templates":[{"key":"value"}]}}', headers: response_headers } + end + + def test_list_method + stub_request(:get, templates_uri).to_return(templates_list_response) + + templates_list = templates.list + + assert_kind_of Vonage::Verify2::Templates::ListResponse, templates_list + templates_list.each { |template| assert_kind_of Vonage::Entity, template } + end + + def test_list_method_with_optional_params + stub_request(:get, templates_uri + '?page_size=10&page=2').to_return(templates_list_response) + + templates_list = templates.list(page_size: 10, page: 2) + + assert_kind_of Vonage::Verify2::Templates::ListResponse, templates_list + templates_list.each { |template| assert_kind_of Vonage::Entity, template } + end + + def test_info_method + stub_request(:get, template_uri).to_return(response) + + assert_kind_of Vonage::Response, templates.info(template_id: template_id) + end + + def test_info_method_without_template_id + assert_raises(ArgumentError) { templates.info } + end + + def test_create_method + stub_request(:post, templates_uri).with(body: { name: 'My Template' }).to_return(response) + + assert_kind_of Vonage::Response, templates.create(name: 'My Template') + end + + def test_create_method_without_name + assert_raises(ArgumentError) { templates.create } + end + + def test_update_method + stub_request(:patch, template_uri).with(body: { name: 'My Updated Template', is_default: false }).to_return(response) + + assert_kind_of Vonage::Response, templates.update(template_id: template_id, name: 'My Updated Template', is_default: false) + end + + def test_update_method_without_template_id + assert_raises(ArgumentError) { templates.update(name: 'My Updated Template', is_default: false) } + end + + def test_delete_method + stub_request(:delete, template_uri).to_return(response) + + assert_kind_of Vonage::Response, templates.delete(template_id: template_id) + end + + def test_delete_method_without_template_id + assert_raises(ArgumentError) { templates.delete } + end +end From c22303f5c9412f16229ec69886500045489b38db Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 21 Oct 2024 16:19:53 +0100 Subject: [PATCH 4/8] Implementing Verify2 Template Fragments Methods --- lib/vonage/verify2/template_fragments.rb | 30 ++++- .../list_response.rb | 0 .../vonage/verify2/template_fragments_test.rb | 121 ++++++++++++++++++ 3 files changed, 150 insertions(+), 1 deletion(-) rename lib/vonage/verify2/{templates_fragments => template_fragments}/list_response.rb (100%) create mode 100644 test/vonage/verify2/template_fragments_test.rb diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb index a1861ada..f1688579 100644 --- a/lib/vonage/verify2/template_fragments.rb +++ b/lib/vonage/verify2/template_fragments.rb @@ -3,10 +3,38 @@ module Vonage class Verify2::TemplateFragments < Namespace + CHANNELS = ['sms', 'voice'].freeze + self.authentication = BearerToken self.request_body = JSON - + def list(template_id:, **params) + request("/v2/verify/templates/#{template_id}/template_fragments", params: params, response_class: ListResponse) + end + + def info(template_id:, template_fragment_id:) + request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}") + end + + def create(template_id:, channel:, locale:, text:) + raise ArgumentError, "Invalid 'channel' #{channel}. Must be one of #{CHANNELS.join(', ')}" unless CHANNELS.include?(channel) + request( + "/v2/verify/templates/#{template_id}/template_fragments", + params: { + channel: channel, + locale: locale, + text: text + }, + type: Post) + end + + def update(template_id:, template_fragment_id:, text:) + request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", params: {text: text}, type: Patch) + end + + def delete(template_id:, template_fragment_id:) + request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", type: Delete) + end end end diff --git a/lib/vonage/verify2/templates_fragments/list_response.rb b/lib/vonage/verify2/template_fragments/list_response.rb similarity index 100% rename from lib/vonage/verify2/templates_fragments/list_response.rb rename to lib/vonage/verify2/template_fragments/list_response.rb diff --git a/test/vonage/verify2/template_fragments_test.rb b/test/vonage/verify2/template_fragments_test.rb new file mode 100644 index 00000000..4fa102c6 --- /dev/null +++ b/test/vonage/verify2/template_fragments_test.rb @@ -0,0 +1,121 @@ +# typed: false + +class Vonage::Verify2::TemplateFragmentsTest < Vonage::Test + def template_fragments + Vonage::Verify2::TemplateFragments.new(config) + end + + def template_id + '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9' + end + + def template_fragment_id + 'c70f446e-997a-4313-a081-60a02a31dc19' + end + + def template_fragments_uri + 'https://api.nexmo.com/v2/verify/templates/' + template_id + '/template_fragments' + end + + def template_fragment_uri + 'https://api.nexmo.com/v2/verify/templates/' + template_id + '/template_fragments/' + template_fragment_id + end + + def template_fragments_list_response + { body: '{"_embedded": {"template_fragments":[{"key":"value"}]}}', headers: response_headers } + end + + def test_list_method + stub_request(:get, template_fragments_uri).to_return(template_fragments_list_response) + + template_fragments_list = template_fragments.list(template_id: template_id) + + assert_kind_of Vonage::Verify2::TemplateFragments::ListResponse, template_fragments_list + template_fragments_list.each { |template_fragment| assert_kind_of Vonage::Entity, template_fragment } + end + + def test_list_method_with_optional_params + stub_request(:get, template_fragments_uri + '?page_size=10&page=2').to_return(template_fragments_list_response) + + template_fragments_list = template_fragments.list(template_id: template_id, page_size: 10, page: 2) + + assert_kind_of Vonage::Verify2::TemplateFragments::ListResponse, template_fragments_list + template_fragments_list.each { |template_fragment| assert_kind_of Vonage::Entity, template_fragment } + end + + def test_list_method_without_template_id + assert_raises(ArgumentError) { template_fragments.list } + end + + def test_info_method + stub_request(:get, template_fragment_uri).to_return(response) + + assert_kind_of Vonage::Response, template_fragments.info(template_id: template_id, template_fragment_id: template_fragment_id) + end + + def test_info_method_without_template_id + assert_raises(ArgumentError) { template_fragments.info(template_fragment_id: template_fragment_id) } + end + + def test_info_method_without_template_fragment_id + assert_raises(ArgumentError) { template_fragments.info(template_id: template_id) } + end + + def test_create_method + stub_request(:post, template_fragments_uri).with(body: { channel: 'sms', locale: 'en-gb', text: 'Code: ${code}' }).to_return(response) + + assert_kind_of Vonage::Response, template_fragments.create(template_id: template_id, channel: 'sms', locale: 'en-gb', text: 'Code: ${code}') + end + + def test_create_method_without_template_id + assert_raises(ArgumentError) { template_fragments.create(channel: 'sms', locale: 'en-gb', text: 'Code: ${code}') } + end + + def test_create_method_without_channel + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, locale: 'en-gb', text: 'Code: ${code}') } + end + + def test_create_method_without_locale + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'sms', text: 'Code: ${code}') } + end + + def test_create_method_without_text + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'sms', locale: 'en-gb') } + end + + def test_create_method_with_invalid_channel + assert_raises(ArgumentError) { template_fragments.create(template_id: template_id, channel: 'foo', locale: 'en-gb', text: 'Code: ${code}') } + end + + def test_update_method + stub_request(:patch, template_fragment_uri).with(body: { text: 'Your code is: ${code}' }).to_return(response) + + assert_kind_of Vonage::Response, template_fragments.update(template_id: template_id, template_fragment_id: template_fragment_id, text: 'Your code is: ${code}') + end + + def test_update_method_without_template_id + assert_raises(ArgumentError) { template_fragments.update(template_fragment_id: template_fragment_id, text: 'Your code is: ${code}') } + end + + def test_update_method_without_template_fragment_id + assert_raises(ArgumentError) { template_fragments.update(template_id: template_id, text: 'Your code is: ${code}') } + end + + def test_update_method_without_text + assert_raises(ArgumentError) { template_fragments.update(template_id: template_id, template_fragment_id: template_fragment_id) } + end + + def test_delete_method + stub_request(:delete, template_fragment_uri).to_return(response) + + assert_kind_of Vonage::Response, template_fragments.delete(template_id: template_id, template_fragment_id: template_fragment_id) + end + + def test_delete_method_without_template_id + assert_raises(ArgumentError) { template_fragments.delete(template_fragment_id: template_fragment_id) } + end + + def test_delete_method_without_template_fragment_id + assert_raises(ArgumentError) { template_fragments.delete(template_id: template_id) } + end +end From cea815871e12e22349c08e383213fdd7d724b3d3 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 23 Oct 2024 12:00:47 +0100 Subject: [PATCH 5/8] Adding code comments for templates and template fragments --- lib/vonage/verify2/template_fragments.rb | 85 ++++++++++++++++++++++++ lib/vonage/verify2/templates.rb | 56 ++++++++++++++++ 2 files changed, 141 insertions(+) diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb index f1688579..c27e809b 100644 --- a/lib/vonage/verify2/template_fragments.rb +++ b/lib/vonage/verify2/template_fragments.rb @@ -9,14 +9,65 @@ class Verify2::TemplateFragments < Namespace self.request_body = JSON + # Get a list of of template fragments for a specific template. + # + # @example + # template_fragment_list = client.verify2.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') + # + # @param [required, String] :template_id. The ID of the template for which to retreive the fragments + # + # @param [optional, Integer] :page_size. The amount of template fragments to list per page + # + # @param [optional, Integer] :page. The page number to retrieve + # + # @return [ListResponse] + # + # @see https://developer.vonage.com/en/api/verify.v2#listTemplateFragments def list(template_id:, **params) request("/v2/verify/templates/#{template_id}/template_fragments", params: params, response_class: ListResponse) end + # Get details of a specific template fragment. + # + # @example + # template_fragment = client.verify2.template_fragments.info( + # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19' + # ) + # + # @param [required, String] :template_id. The ID of the template for which to retreive the fragment + # + # @param [required, String] :template_fragment_id. The ID of the fragment to be retreived + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#getTemplateFragment def info(template_id:, template_fragment_id:) request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}") end + # Create a new template fragment. + # + # @example + # client.verify2.template_fragments.create( + # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + # channel: 'sms', + # locale: 'en-gb', + # text: 'Your code is: ${code}' + # ) + # + # @param [required, String] :template_id. The ID of the template for which to create the fragment + # + # @param [required, String] :channel. The verification channel for which to create the fragment. Must be one of 'sms' or 'voice' + # + # @param [required, String] :locale. The locale for which to create the fragment. + # + # @param [required, String] :text. The text to be used in the template fragment. + # There are 4 reserved variables available to use as part of the text: ${code}, ${brand}, ${time-limit} and ${time-limit-unit} + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#addTemplateFragmentToTemplate def create(template_id:, channel:, locale:, text:) raise ArgumentError, "Invalid 'channel' #{channel}. Must be one of #{CHANNELS.join(', ')}" unless CHANNELS.include?(channel) request( @@ -29,10 +80,44 @@ def create(template_id:, channel:, locale:, text:) type: Post) end + # Update an existing template fragment. + # + # @example + # client.verify2.template_fragments.update( + # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19, + # text: 'Your one-time code is: ${code}' + # ) + # + # @param [required, String] :template_id. The ID of the template with which the fragment to be updated is associated + # + # @param [required, String] :template_fragment_id. The ID of the fragment to be updated + # + # @param [required, String] :text. The text to be used in the template fragment. + # There are 4 reserved variables available to use as part of the text: ${code}, ${brand}, ${time-limit} and ${time-limit-unit} + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#updateTemplateFragment def update(template_id:, template_fragment_id:, text:) request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", params: {text: text}, type: Patch) end + # Delete a template fragment. + # + # @example + # client.verify2.template_fragments.delete( + # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19' + # ) + # + # @param [required, String] :template_id. The ID of the template with which the fragment to be deleted is associated + # + # @param [required, String] :template_fragment_id. The ID of the fragment to be deleted + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#deleteTemplateFragment def delete(template_id:, template_fragment_id:) request("/v2/verify/templates/#{template_id}/template_fragments/#{template_fragment_id}", type: Delete) end diff --git a/lib/vonage/verify2/templates.rb b/lib/vonage/verify2/templates.rb index 5af4c8c6..13b3af1e 100644 --- a/lib/vonage/verify2/templates.rb +++ b/lib/vonage/verify2/templates.rb @@ -7,22 +7,78 @@ class Verify2::Templates < Namespace self.request_body = JSON + # Get a list of all templates. + # + # @example + # template_list = client.verify2.templates.list + # + # @param [optional, Integer] :page_size. The amount of templates to list per page + # + # @param [optional, Integer] :page. The page number to retrieve + # + # @return [ListResponse] + # + # @see https://developer.vonage.com/en/api/verify.v2#listTemplates def list(**params) request('/v2/verify/templates', params: params, response_class: ListResponse) end + # Get details of a specific template. + # + # @example + # template = client.verify2.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') + # + # @param [required, String] :template_id. The ID of the template to be retreived + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#getTemplate def info(template_id:) request('/v2/verify/templates/' + template_id) end + # Create a new template. + # + # @example + # client.verify2.templates.create(name: 'my-template') + # + # @param [required, String] :name. The name of the template. The following characters are permitted: [A-Z a-z 0-9 _ -] + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#createTemplate def create(name:) request('/v2/verify/templates', params: { name: name }, type: Post) end + # Update an existing template. + # + # @example + # client.verify2.templates.update(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', name: 'my-updated-template') + # + # @param [required, String] :template_id. The ID of the template to be updated + # + # @param [optional, String] :name. The name of the template. The following characters are permitted: [A-Z a-z 0-9 _ -] + # + # @param [optional, Boolean] :is_default. Whether the template is the default template for a specific locale/channel combination + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#updateTemplate def update(template_id:, **params) request('/v2/verify/templates/' + template_id, params: params, type: Patch) end + # Delete a template. + # + # @example + # client.verify2.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') + # + # @param [required, String] :template_id. The ID of the template to be deleted + # + # @return [Response] + # + # @see https://developer.vonage.com/en/api/verify.v2#deleteTemplate def delete(template_id:) request('/v2/verify/templates/' + template_id, type: Delete) end From ec61ae4a69d186dbacdf0fbb95d19c6b401dd828 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 23 Oct 2024 12:16:15 +0100 Subject: [PATCH 6/8] Updating README with details of Verify templates --- README.md | 60 ++++++++++++++++++++++++ lib/vonage/verify2/template_fragments.rb | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2657ff01..bfe9aca1 100644 --- a/README.md +++ b/README.md @@ -488,6 +488,66 @@ if code_check.http_response.code == '200' end ``` +### Working with Verify Custom Templates and Template Fragments + +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. + +#### Templates + +```ruby +# Get a list of all templates +template_list = verify.templates.list + +# Get details of a specific template +template = verify.templates.info(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') + +# Create a new template +verify.templates.create(name: 'my-template') + +# Update an existing template +verify.templates.update( + template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + name: 'my-updated-template' +) + +# Delete a template +verify.templates.delete(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') +``` + +#### Template Fragments + +```ruby +# Get a list of template fragments for a specific template +template_fragment_list = verify.template_fragments.list(template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9') + +# Get details of a specific template fragment +template_fragment = verify.template_fragments.info( + template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19' +) + +# Create a new template fragement +verify.template_fragments.create( + template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + channel: 'sms', + locale: 'en-gb', + text: 'Your code is: ${code}' +) + +# Update an existing template fragment +verify.template_fragments.update( + template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc1', + text: 'Your one-time code is: ${code}' +) + +# Delete a template fragment +verify.template_fragments.delete( + template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', + template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19' +) +``` + ## Voice API 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. diff --git a/lib/vonage/verify2/template_fragments.rb b/lib/vonage/verify2/template_fragments.rb index c27e809b..84e246a0 100644 --- a/lib/vonage/verify2/template_fragments.rb +++ b/lib/vonage/verify2/template_fragments.rb @@ -85,7 +85,7 @@ def create(template_id:, channel:, locale:, text:) # @example # client.verify2.template_fragments.update( # template_id: '8f35a1a7-eb2f-4552-8fdf-fffdaee41bc9', - # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19, + # template_fragment_id: 'c70f446e-997a-4313-a081-60a02a31dc19', # text: 'Your one-time code is: ${code}' # ) # From 0b488705c4d892d67c26c62ef1287c5495e13bf5 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 23 Oct 2024 12:22:28 +0100 Subject: [PATCH 7/8] Bumping minor version --- lib/vonage/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vonage/version.rb b/lib/vonage/version.rb index ff1363bf..64ae1873 100644 --- a/lib/vonage/version.rb +++ b/lib/vonage/version.rb @@ -1,5 +1,5 @@ # typed: strong module Vonage - VERSION = '7.27.1' + VERSION = '7.28.0' end From 8fff2a8c8ee6d3a8f17c0c5d00438107ec7644e0 Mon Sep 17 00:00:00 2001 From: superchilled Date: Wed, 23 Oct 2024 12:24:00 +0100 Subject: [PATCH 8/8] Update Changelog --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 95625f0f..545abe1a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +# 7.28.0 + +* Adds templates and template fragments to the Verify v2 implementation. [#318](https://github.com/Vonage/vonage-ruby-sdk/pull/318) + # 7.27.1 * Fixes a bug with setting options on the HTTP client. [#319](https://github.com/Vonage/vonage-ruby-sdk/pull/319)