From 8371bf3f75a4fc6cb66e9c7941c6355e8479eb3c Mon Sep 17 00:00:00 2001 From: superchilled Date: Thu, 16 Mar 2023 17:30:48 +0000 Subject: [PATCH 01/35] Defining Verify2 class and stubbing methods --- lib/vonage/verify2.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/vonage/verify2.rb diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb new file mode 100644 index 00000000..40c08376 --- /dev/null +++ b/lib/vonage/verify2.rb @@ -0,0 +1,20 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2 < Namespace + self.authentication = BearerToken + + self.request_body = JSON + + # Request a verification be sent to a user . + # + # @see https://developer.vonage.com/en/api/verify.v2#newRequest + # + def start_verfication(workflow:, **opts) + end + + def check_code(request_id:, code:) + end + end +end From 7529cf4ce752bd3ee43f3bba24917b07a2a56339 Mon Sep 17 00:00:00 2001 From: superchilled Date: Thu, 16 Mar 2023 18:46:07 +0000 Subject: [PATCH 02/35] Adding initial Verify2 tests --- lib/vonage/verify2.rb | 6 ++- test/vonage/verify2_test.rb | 96 +++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 test/vonage/verify2_test.rb diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 40c08376..6f19fe6a 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -7,13 +7,17 @@ class Verify2 < Namespace self.request_body = JSON - # Request a verification be sent to a user . + # Request a verification be sent to a user. # # @see https://developer.vonage.com/en/api/verify.v2#newRequest # def start_verfication(workflow:, **opts) end + # Check a supplied code against a request to see if it is valid. + # + # @see https://developer.vonage.com/en/api/verify.v2#checkCode + # def check_code(request_id:, code:) end end diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb new file mode 100644 index 00000000..d6cb8f34 --- /dev/null +++ b/test/vonage/verify2_test.rb @@ -0,0 +1,96 @@ +# typed: false +require_relative './test' + +class Vonage::Verify2Test < Vonage::Test + def verify2 + Vonage::Verify2.new(config) + end + + def request_id + 'c11236f4-00bf-4b89-84ba-88b25df97315' + end + + def response + { + headers: response_headers, + body: '{"request_id":"c11236f4-00bf-4b89-84ba-88b25df97315"}' + } + end + + def uri + 'https://api.nexmo.com/v2/verify/' + end + + def check_request_uri + uri + request_id + end + + def to_number + '447700900000' + end + + def test_start_verfication_method + workflow = [{channel: 'sms', to: to_number}] + + stub_request(:post, uri).with(headers: headers, body: {workflow: workflow}).to_return(response) + + assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) + end + + def test_start_verfication_method_with_opts + workflow = [{channel: 'sms', to: to_number}] + params = {workflow: workflow, brand: 'Example Brand'} + + stub_request(:post, uri).with(headers: headers, body: params).to_return(response) + + assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow, brand: 'Example Brand') + end + + def test_start_verfication_method_without_workflow + assert_raises ArgumentError do + verify.start_verfication + end + end + + def test_start_verfication_method_with_workflow_that_isnt_array + workflow = {channel: 'sms', to: to_number} + + assert_raises ArgumentError do + verify.start_verfication(workflow: workflow) + end + end + + def test_start_verfication_method_with_empty_workflow + assert_raises ArgumentError do + verify.start_verfication(workflow: []) + end + end + + def test_start_verfication_method_with_multiple_workflows + workflow = [{channel: 'sms', to: to_number}, {channel: 'voice', to: to_number}] + + stub_request(:post, uri).with(headers: headers, body: {workflow: workflow}).to_return(response) + + assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) + end + + def test_check_code_method + code = '1234' + + stub_request(:post, check_request_uri).with(headers: headers, body: {code: code}).to_return(status: 200) + + assert_kind_of Vonage::Response, verify2.check_code(request_id: request_id, code: code) + end + + def test_check_code_method_without_request_id + assert_raises ArgumentError do + verify.check_code(code: '1234') + end + end + + def test_check_code_method_without_code + assert_raises ArgumentError do + verify.check_code(request_id: request_id) + end + end +end From 9c01501ddaf77dc4f6105624c368c405e3b691f8 Mon Sep 17 00:00:00 2001 From: superchilled Date: Thu, 16 Mar 2023 19:57:38 +0000 Subject: [PATCH 03/35] Adding initial Verify2 implementation --- lib/vonage/namespace.rb | 2 +- lib/vonage/verify2.rb | 5 +++++ test/vonage/verify2_test.rb | 18 +++++++++--------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/vonage/namespace.rb b/lib/vonage/namespace.rb index 369f200a..deeb2e94 100644 --- a/lib/vonage/namespace.rb +++ b/lib/vonage/namespace.rb @@ -202,7 +202,7 @@ def parse(response, response_class) when Net::HTTPNoContent response_class.new(nil, response) when Net::HTTPSuccess - if response['Content-Type'].split(';').first == 'application/json' + if response['Content-Type'] && response['Content-Type'].split(';').first == 'application/json' entity = ::JSON.parse(response.body, object_class: Vonage::Entity) response_class.new(entity, response) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 6f19fe6a..2076ccae 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -12,6 +12,10 @@ class Verify2 < Namespace # @see https://developer.vonage.com/en/api/verify.v2#newRequest # def start_verfication(workflow:, **opts) + raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array) + raise ArgumentError, ':workflow must not be empty' if workflow.empty? + + request('/v2/verify/', params: opts.merge(workflow: workflow), type: Post) end # Check a supplied code against a request to see if it is valid. @@ -19,6 +23,7 @@ def start_verfication(workflow:, **opts) # @see https://developer.vonage.com/en/api/verify.v2#checkCode # def check_code(request_id:, code:) + request('/v2/verify/' + request_id, params: {code: code}, type: Post) end end end diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index d6cb8f34..42381b0f 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -32,7 +32,7 @@ def to_number def test_start_verfication_method workflow = [{channel: 'sms', to: to_number}] - stub_request(:post, uri).with(headers: headers, body: {workflow: workflow}).to_return(response) + stub_request(:post, uri).with(body: {workflow: workflow}).to_return(response) assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) end @@ -41,14 +41,14 @@ def test_start_verfication_method_with_opts workflow = [{channel: 'sms', to: to_number}] params = {workflow: workflow, brand: 'Example Brand'} - stub_request(:post, uri).with(headers: headers, body: params).to_return(response) + stub_request(:post, uri).with(body: params).to_return(response) assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow, brand: 'Example Brand') end def test_start_verfication_method_without_workflow assert_raises ArgumentError do - verify.start_verfication + verify2.start_verfication end end @@ -56,20 +56,20 @@ def test_start_verfication_method_with_workflow_that_isnt_array workflow = {channel: 'sms', to: to_number} assert_raises ArgumentError do - verify.start_verfication(workflow: workflow) + verify2.start_verfication(workflow: workflow) end end def test_start_verfication_method_with_empty_workflow assert_raises ArgumentError do - verify.start_verfication(workflow: []) + verify2.start_verfication(workflow: []) end end def test_start_verfication_method_with_multiple_workflows workflow = [{channel: 'sms', to: to_number}, {channel: 'voice', to: to_number}] - stub_request(:post, uri).with(headers: headers, body: {workflow: workflow}).to_return(response) + stub_request(:post, uri).with(body: {workflow: workflow}).to_return(response) assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) end @@ -77,20 +77,20 @@ def test_start_verfication_method_with_multiple_workflows def test_check_code_method code = '1234' - stub_request(:post, check_request_uri).with(headers: headers, body: {code: code}).to_return(status: 200) + stub_request(:post, check_request_uri).with(body: {code: code}).to_return(status: 200, headers: {}) assert_kind_of Vonage::Response, verify2.check_code(request_id: request_id, code: code) end def test_check_code_method_without_request_id assert_raises ArgumentError do - verify.check_code(code: '1234') + verify2.check_code(code: '1234') end end def test_check_code_method_without_code assert_raises ArgumentError do - verify.check_code(request_id: request_id) + verify2.check_code(request_id: request_id) end end end From 967a1e09df1bfbf44965a5351369c346d74bd10a Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 17 Mar 2023 15:41:19 +0000 Subject: [PATCH 04/35] Making brand a required param of start_verfication --- lib/vonage/verify2.rb | 4 ++-- test/vonage/verify2_test.rb | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 2076ccae..976d4f86 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -11,11 +11,11 @@ class Verify2 < Namespace # # @see https://developer.vonage.com/en/api/verify.v2#newRequest # - def start_verfication(workflow:, **opts) + def start_verfication(brand:, workflow:, **opts) raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array) raise ArgumentError, ':workflow must not be empty' if workflow.empty? - request('/v2/verify/', params: opts.merge(workflow: workflow), type: Post) + request('/v2/verify/', params: opts.merge(brand: brand, workflow: workflow), type: Post) end # Check a supplied code against a request to see if it is valid. diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index 42381b0f..0df989e2 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -29,26 +29,39 @@ def to_number '447700900000' end + def brand + 'Example Brand' + end + def test_start_verfication_method workflow = [{channel: 'sms', to: to_number}] - stub_request(:post, uri).with(body: {workflow: workflow}).to_return(response) + stub_request(:post, uri).with(body: {brand: brand, workflow: workflow}).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) + assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand, workflow: workflow) end def test_start_verfication_method_with_opts workflow = [{channel: 'sms', to: to_number}] - params = {workflow: workflow, brand: 'Example Brand'} + opts = {locale: 'en-gb', channel_timeout: 200, client_ref: 'test-reference', code_length: 8} + params = {brand: brand, workflow: workflow}.merge(opts) stub_request(:post, uri).with(body: params).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow, brand: 'Example Brand') + assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand, workflow: workflow, **opts) + end + + def test_start_verfication_method_without_brand + workflow = [{channel: 'sms', to: to_number}] + + assert_raises ArgumentError do + verify2.start_verfication(workflow: workflow) + end end def test_start_verfication_method_without_workflow assert_raises ArgumentError do - verify2.start_verfication + verify2.start_verfication(brand: brand) end end @@ -56,22 +69,22 @@ def test_start_verfication_method_with_workflow_that_isnt_array workflow = {channel: 'sms', to: to_number} assert_raises ArgumentError do - verify2.start_verfication(workflow: workflow) + verify2.start_verfication(brand: brand, workflow: workflow) end end def test_start_verfication_method_with_empty_workflow assert_raises ArgumentError do - verify2.start_verfication(workflow: []) + verify2.start_verfication(brand: brand, workflow: []) end end def test_start_verfication_method_with_multiple_workflows workflow = [{channel: 'sms', to: to_number}, {channel: 'voice', to: to_number}] - stub_request(:post, uri).with(body: {workflow: workflow}).to_return(response) + stub_request(:post, uri).with(body: {brand: brand, workflow: workflow}).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(workflow: workflow) + assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand,workflow: workflow) end def test_check_code_method From 7a11af1dafefa0196613029f73cfc3c030914d5e Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 15:51:35 +0000 Subject: [PATCH 05/35] Adding verify2 client test --- test/vonage/client_test.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/vonage/client_test.rb b/test/vonage/client_test.rb index 11baeb91..ea8fd65b 100644 --- a/test/vonage/client_test.rb +++ b/test/vonage/client_test.rb @@ -78,6 +78,10 @@ def test_verify_method assert_kind_of Vonage::Verify, client.verify end + def test_verify2_method + assert_kind_of Vonage::Verify2, client.verify2 + end + def test_raises_client_error_for_4xx_responses client = Vonage::Client.new(api_key: api_key, api_secret: api_secret) From 76afc26c1c867cc2665ddaf2a400eba9c793f970 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 15:53:02 +0000 Subject: [PATCH 06/35] Implementing CLient#verify2 method --- lib/vonage/client.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/vonage/client.rb b/lib/vonage/client.rb index e8c43d89..9d182df7 100644 --- a/lib/vonage/client.rb +++ b/lib/vonage/client.rb @@ -131,6 +131,13 @@ def verify @verify ||= T.let(Verify.new(config), T.nilable(Vonage::Verify)) end + # @return [Verify2] + # + sig { returns(T.nilable(Vonage::Verify2)) } + def verify2 + @verify2 ||= T.let(Verify2.new(config), T.nilable(Vonage::Verify2)) + end + # @return [Voice] # sig { returns(T.nilable(Vonage::Voice)) } From 739d319a31cafc2fc05ae94b29b3416d2a84a1ce Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 18:57:02 +0000 Subject: [PATCH 07/35] Adding Verify2::Options tests --- test/vonage/verify2/options_test.rb | 88 +++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 test/vonage/verify2/options_test.rb diff --git a/test/vonage/verify2/options_test.rb b/test/vonage/verify2/options_test.rb new file mode 100644 index 00000000..569c4a66 --- /dev/null +++ b/test/vonage/verify2/options_test.rb @@ -0,0 +1,88 @@ +# typed: false + +class Vonage::Verify2::OptionsTest < Vonage::Test + def options + Vonage::Verify2::Options.new + end + + def test_locale_getter_method + assert_nil options.locale + end + + def test_locale_setter_method + opts = options + opts.locale = 'en-gb' + + assert_equal 'en-gb', opts.instance_variable_get(:@locale) + end + + def test_locale_setter_method_with_invalid_arg + opts = options + assert_raises ArgumentError do + opts.locale = 'foo-bar' + end + end + + def test_channel_timeout_getter_method + assert_nil options.channel_timeout + end + + def test_channel_timeout_setter_method + opts = options + opts.channel_timeout = 90 + + assert_equal 90, opts.instance_variable_get(:@channel_timeout) + end + + def test_channel_timeout_setter_method_with_invalid_arg + opts = options + assert_raises ArgumentError do + opts.channel_timeout = 0 + end + end + + def test_client_ref_getter_method + assert_nil options.client_ref + end + + def test_client_ref_setter_method + opts = options + opts.client_ref = 'foo' + + assert_equal 'foo', opts.instance_variable_get(:@client_ref) + end + + + def test_code_length_getter_method + assert_nil options.code_length + end + + def test_code_length_setter_method + opts = options + opts.code_length = 6 + + assert_equal 6, opts.instance_variable_get(:@code_length) + end + + def test_code_length_setter_method_with_invalid_arg + opts = options + assert_raises ArgumentError do + opts.code_length = 1000 + end + end + + def test_to_h_method + opts_hash = Vonage::Verify2::Options.new( + locale: 'en-gb', + channel_timeout: 90, + client_ref: 'foo', + code_length: 6 + ).to_h + + assert_kind_of Hash, opts_hash + assert_equal 'en-gb', opts_hash[:locale] + assert_equal 90, opts_hash[:channel_timeout] + assert_equal 'foo', opts_hash[:client_ref] + assert_equal 6, opts_hash[:code_length] + end +end From 9338fc51c431e5533af9a23343fd58030f424a0a Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:01:22 +0000 Subject: [PATCH 08/35] Renaming Verify2::Options class to StartVerificationOptions --- test/vonage/verify2/options_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/vonage/verify2/options_test.rb b/test/vonage/verify2/options_test.rb index 569c4a66..9b8bceb3 100644 --- a/test/vonage/verify2/options_test.rb +++ b/test/vonage/verify2/options_test.rb @@ -1,8 +1,8 @@ # typed: false -class Vonage::Verify2::OptionsTest < Vonage::Test +class Vonage::Verify2::StartVerificationOptionsTest < Vonage::Test def options - Vonage::Verify2::Options.new + Vonage::Verify2::StartVerificationOptions.new end def test_locale_getter_method @@ -72,7 +72,7 @@ def test_code_length_setter_method_with_invalid_arg end def test_to_h_method - opts_hash = Vonage::Verify2::Options.new( + opts_hash = Vonage::Verify2::StartVerificationOptions.new( locale: 'en-gb', channel_timeout: 90, client_ref: 'foo', From c3661363617250f21c1f0664aa67b54d12e07450 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:03:03 +0000 Subject: [PATCH 09/35] Renaming options test file in line with Zeitwerk conventions --- .../{options_test.rb => start_verfication_options_test.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/vonage/verify2/{options_test.rb => start_verfication_options_test.rb} (100%) diff --git a/test/vonage/verify2/options_test.rb b/test/vonage/verify2/start_verfication_options_test.rb similarity index 100% rename from test/vonage/verify2/options_test.rb rename to test/vonage/verify2/start_verfication_options_test.rb From 27a9940d8e3a214679b32e49fc782eaf0c0333ed Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:05:15 +0000 Subject: [PATCH 10/35] Fixing typo in Verify2#start_verification method name --- lib/vonage/verify2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 976d4f86..47cf7ad2 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -11,7 +11,7 @@ class Verify2 < Namespace # # @see https://developer.vonage.com/en/api/verify.v2#newRequest # - def start_verfication(brand:, workflow:, **opts) + def start_verification(brand:, workflow:, **opts) raise ArgumentError, ':workflow must be an Array' unless workflow.is_a?(Array) raise ArgumentError, ':workflow must not be empty' if workflow.empty? From a9ce83e81ce08e2fd734e43eca54bfd053d46c56 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:06:50 +0000 Subject: [PATCH 11/35] Fixing typo in Verify2 options test filename --- ...ication_options_test.rb => start_verification_options_test.rb} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/vonage/verify2/{start_verfication_options_test.rb => start_verification_options_test.rb} (100%) diff --git a/test/vonage/verify2/start_verfication_options_test.rb b/test/vonage/verify2/start_verification_options_test.rb similarity index 100% rename from test/vonage/verify2/start_verfication_options_test.rb rename to test/vonage/verify2/start_verification_options_test.rb From 5cbc1e4716932b82dc0b270a08740128499715e9 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:08:34 +0000 Subject: [PATCH 12/35] Fixing all the method name typos --- test/vonage/verify2_test.rb | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index 0df989e2..b9eb9535 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -33,58 +33,58 @@ def brand 'Example Brand' end - def test_start_verfication_method + def test_start_verification_method workflow = [{channel: 'sms', to: to_number}] stub_request(:post, uri).with(body: {brand: brand, workflow: workflow}).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand, workflow: workflow) + assert_kind_of Vonage::Response, verify2.start_verification(brand: brand, workflow: workflow) end - def test_start_verfication_method_with_opts + def test_start_verification_method_with_opts workflow = [{channel: 'sms', to: to_number}] opts = {locale: 'en-gb', channel_timeout: 200, client_ref: 'test-reference', code_length: 8} params = {brand: brand, workflow: workflow}.merge(opts) stub_request(:post, uri).with(body: params).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand, workflow: workflow, **opts) + assert_kind_of Vonage::Response, verify2.start_verification(brand: brand, workflow: workflow, **opts) end - def test_start_verfication_method_without_brand + def test_start_verification_method_without_brand workflow = [{channel: 'sms', to: to_number}] assert_raises ArgumentError do - verify2.start_verfication(workflow: workflow) + verify2.start_verification(workflow: workflow) end end - def test_start_verfication_method_without_workflow + def test_start_verification_method_without_workflow assert_raises ArgumentError do - verify2.start_verfication(brand: brand) + verify2.start_verification(brand: brand) end end - def test_start_verfication_method_with_workflow_that_isnt_array + def test_start_verification_method_with_workflow_that_isnt_array workflow = {channel: 'sms', to: to_number} assert_raises ArgumentError do - verify2.start_verfication(brand: brand, workflow: workflow) + verify2.start_verification(brand: brand, workflow: workflow) end end - def test_start_verfication_method_with_empty_workflow + def test_start_verification_method_with_empty_workflow assert_raises ArgumentError do - verify2.start_verfication(brand: brand, workflow: []) + verify2.start_verification(brand: brand, workflow: []) end end - def test_start_verfication_method_with_multiple_workflows + def test_start_verification_method_with_multiple_workflows workflow = [{channel: 'sms', to: to_number}, {channel: 'voice', to: to_number}] stub_request(:post, uri).with(body: {brand: brand, workflow: workflow}).to_return(response) - assert_kind_of Vonage::Response, verify2.start_verfication(brand: brand,workflow: workflow) + assert_kind_of Vonage::Response, verify2.start_verification(brand: brand,workflow: workflow) end def test_check_code_method From 9c9efbf8f0fb690e120844822a12c31a478dd946 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sat, 18 Mar 2023 19:27:59 +0000 Subject: [PATCH 13/35] Implementing Verify2::StartVerificationOptions class --- .../verify2/start_verification_options.rb | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/vonage/verify2/start_verification_options.rb diff --git a/lib/vonage/verify2/start_verification_options.rb b/lib/vonage/verify2/start_verification_options.rb new file mode 100644 index 00000000..31c4f144 --- /dev/null +++ b/lib/vonage/verify2/start_verification_options.rb @@ -0,0 +1,61 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2::StartVerificationOptions + VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length].freeze + + VALID_LOCALES = [ + 'en-us', 'en-gb', 'es-es', 'es-mx', 'es-us', 'it-it', 'fr-fr', + 'de-de', 'ru-ru', 'hi-in', 'pt-br', 'pt-pt', 'id-id' + ].freeze + + MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT = [60, 900] + + MIN_CODE_LENGTH, MAX_CODE_LENGTH = [4, 10] + + attr_reader(*VALID_OPTS) + + def initialize(**opts) + VALID_OPTS.each do |opt| + send("#{opt}=", opts[opt]) unless opts[opt].nil? + end + end + + def locale=(locale) + unless VALID_LOCALES.include?(locale) + raise ArgumentError, "Invalid :locale. Please choose from the following #{VALID_LOCALES}" + end + + @locale = locale + end + + def channel_timeout=(channel_timeout) + unless channel_timeout.between?(MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT) + raise ArgumentError, "Invalid :channel_timeout #{channel_timeout}. Must be between #{MIN_CHANNEL_TIMEOUT} and #{MAX_CHANNEL_TIMEOUT} (inclusive)" + end + + @channel_timeout = channel_timeout + end + + def client_ref=(client_ref) + @client_ref = client_ref + end + + def code_length=(code_length) + unless code_length.between?(MIN_CODE_LENGTH, MAX_CODE_LENGTH) + raise ArgumentError, "Invalid :code_length #{code_length}. Must be between #{MIN_CODE_LENGTH} and #{MAX_CODE_LENGTH} (inclusive)" + end + + @code_length = code_length + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + end +end From d6b9974ec92858767081a04db4de8d7cdeb460ab Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 16:33:45 +0000 Subject: [PATCH 14/35] Adding Verify2 workflow tests --- test/vonage/test.rb | 8 +++ test/vonage/verify2/workflows/email_test.rb | 49 +++++++++++++++ .../verify2/workflows/silent_auth_test.rb | 36 +++++++++++ test/vonage/verify2/workflows/sms_test.rb | 61 +++++++++++++++++++ test/vonage/verify2/workflows/voice_test.rb | 36 +++++++++++ .../workflows/whats_app_interactive_test.rb | 36 +++++++++++ .../verify2/workflows/whats_app_test.rb | 57 +++++++++++++++++ 7 files changed, 283 insertions(+) create mode 100644 test/vonage/verify2/workflows/email_test.rb create mode 100644 test/vonage/verify2/workflows/silent_auth_test.rb create mode 100644 test/vonage/verify2/workflows/sms_test.rb create mode 100644 test/vonage/verify2/workflows/voice_test.rb create mode 100644 test/vonage/verify2/workflows/whats_app_interactive_test.rb create mode 100644 test/vonage/verify2/workflows/whats_app_test.rb diff --git a/test/vonage/test.rb b/test/vonage/test.rb index dc3f0663..0bf7e133 100644 --- a/test/vonage/test.rb +++ b/test/vonage/test.rb @@ -334,6 +334,14 @@ def member_id 'MEM-xxxxxx' end + def e164_compliant_number + '447000000000' + end + + def invalid_number + 'abcdefg' + end + alias_method :call_uuid, :call_id end end diff --git a/test/vonage/verify2/workflows/email_test.rb b/test/vonage/verify2/workflows/email_test.rb new file mode 100644 index 00000000..33609c92 --- /dev/null +++ b/test/vonage/verify2/workflows/email_test.rb @@ -0,0 +1,49 @@ +# typed: false + +class Vonage::Verify2::Workflows::EmailTest < Vonage::Test + def email_workflow + Vonage::Verify2::Workflows::Email.new(to: valid_email) + end + + def valid_email + 'alice@example.com' + end + + def channel_getter_method + assert_equal 'whatsapp', email_workflow.channel + end + + def test_to_getter_method + assert_equal valid_email, email_workflow.to + end + + def test_to_setter_method + workflow = email_workflow + new_email = 'bob@example.com' + workflow.to = new_email + + assert_equal new_email, workflow.instance_variable_get(:@to) + end + + def test_from_getter_method + assert_nil email_workflow.from + end + + def test_from_setter_method + workflow = email_workflow + workflow.from = valid_email + + assert_equal valid_email, workflow.instance_variable_get(:@from) + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::Email.new( + to: valid_email, + from: valid_email + ).to_h + + assert_kind_of Hash, workflow_hash + assert_equal valid_email, workflow_hash[:to] + assert_equal valid_email, workflow_hash[:from] + end +end diff --git a/test/vonage/verify2/workflows/silent_auth_test.rb b/test/vonage/verify2/workflows/silent_auth_test.rb new file mode 100644 index 00000000..7e89e244 --- /dev/null +++ b/test/vonage/verify2/workflows/silent_auth_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Workflows::SilentAuthTest < Vonage::Test + def silent_auth_workflow + Vonage::Verify2::Workflows::SilentAuth.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'silent_auth', silent_auth_workflow.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, silent_auth_workflow.to + end + + def test_to_setter_method + workflow = silent_auth_workflow + new_number = '447000000001' + workflow.to = new_number + + assert_equal new_number, workflow.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + silent_auth_workflow.to = invalid_number + end + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::SilentAuth.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, workflow_hash + assert_equal e164_compliant_number, workflow_hash[:to] + end +end diff --git a/test/vonage/verify2/workflows/sms_test.rb b/test/vonage/verify2/workflows/sms_test.rb new file mode 100644 index 00000000..357e2029 --- /dev/null +++ b/test/vonage/verify2/workflows/sms_test.rb @@ -0,0 +1,61 @@ +# typed: false + +class Vonage::Verify2::Workflows::SMSTest < Vonage::Test + def sms_workflow + Vonage::Verify2::Workflows::SMS.new(to: e164_compliant_number) + end + + def valid_android_app_hash + 'FA+9qCX9VSu' + end + + def channel_getter_method + assert_equal 'sms', sms_workflow.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, sms_workflow.to + end + + def test_to_setter_method + workflow = sms_workflow + new_number = '447000000001' + workflow.to = new_number + + assert_equal new_number, workflow.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + sms_workflow.to = invalid_number + end + end + + def test_app_hash_getter_method + assert_nil sms_workflow.app_hash + end + + def test_app_hash_setter_method + workflow = sms_workflow + workflow.app_hash = valid_android_app_hash + + assert_equal valid_android_app_hash, workflow.instance_variable_get(:@app_hash) + end + + def test_app_hash_setter_method_with_invalid_arg + assert_raises ArgumentError do + sms_workflow.app_hash = valid_android_app_hash[0..8] + end + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::SMS.new( + to: e164_compliant_number, + app_hash: valid_android_app_hash + ).to_h + + assert_kind_of Hash, workflow_hash + assert_equal e164_compliant_number, workflow_hash[:to] + assert_equal valid_android_app_hash, workflow_hash[:app_hash] + end +end diff --git a/test/vonage/verify2/workflows/voice_test.rb b/test/vonage/verify2/workflows/voice_test.rb new file mode 100644 index 00000000..1116af97 --- /dev/null +++ b/test/vonage/verify2/workflows/voice_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Workflows::VoiceTest < Vonage::Test + def voice_workflow + Vonage::Verify2::Workflows::Voice.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'voice', voice_workflow.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, voice_workflow.to + end + + def test_to_setter_method + workflow = voice_workflow + new_number = '447000000001' + workflow.to = new_number + + assert_equal new_number, workflow.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + voice_workflow.to = invalid_number + end + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::Voice.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, workflow_hash + assert_equal e164_compliant_number, workflow_hash[:to] + end +end diff --git a/test/vonage/verify2/workflows/whats_app_interactive_test.rb b/test/vonage/verify2/workflows/whats_app_interactive_test.rb new file mode 100644 index 00000000..3ba3b4b9 --- /dev/null +++ b/test/vonage/verify2/workflows/whats_app_interactive_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Workflows::WhatsAppInteractiveTest < Vonage::Test + def whatsapp_interactive_workflow + Vonage::Verify2::Workflows::WhatsAppInteractive.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'whatsapp_interactive', whatsapp_interactive_workflow.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, whatsapp_interactive_workflow.to + end + + def test_to_setter_method + workflow = whatsapp_interactive_workflow + new_number = '447000000001' + workflow.to = new_number + + assert_equal new_number, workflow.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + whatsapp_interactive_workflow.to = invalid_number + end + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::WhatsAppInteractive.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, workflow_hash + assert_equal e164_compliant_number, workflow_hash[:to] + end +end diff --git a/test/vonage/verify2/workflows/whats_app_test.rb b/test/vonage/verify2/workflows/whats_app_test.rb new file mode 100644 index 00000000..9b864277 --- /dev/null +++ b/test/vonage/verify2/workflows/whats_app_test.rb @@ -0,0 +1,57 @@ +# typed: false + +class Vonage::Verify2::Workflows::WhatsAppTest < Vonage::Test + def whatsapp_workflow + Vonage::Verify2::Workflows::WhatsApp.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'whatsapp', whatsapp_workflow.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, whatsapp_workflow.to + end + + def test_to_setter_method + workflow = whatsapp_workflow + new_number = '447000000001' + workflow.to = new_number + + assert_equal new_number, workflow.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + whatsapp_workflow.to = invalid_number + end + end + + def test_from_getter_method + assert_nil whatsapp_workflow.from + end + + def test_from_setter_method + workflow = whatsapp_workflow + workflow.from = e164_compliant_number + + assert_equal e164_compliant_number, workflow.instance_variable_get(:@from) + end + + def test_from_setter_method_with_invalid_arg + assert_raises ArgumentError do + whatsapp_workflow.from = invalid_number + end + end + + def test_to_h_method + workflow_hash = Vonage::Verify2::Workflows::WhatsApp.new( + to: e164_compliant_number, + from: e164_compliant_number + ).to_h + + assert_kind_of Hash, workflow_hash + assert_equal e164_compliant_number, workflow_hash[:to] + assert_equal e164_compliant_number, workflow_hash[:from] + end +end From d14d658d933d594b7b134f1ddba5513a56ca1965 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 16:43:15 +0000 Subject: [PATCH 15/35] Implementing Verify2 workflow classes --- .../verify2/start_verification_options.rb | 6 +-- lib/vonage/verify2/workflows/email.rb | 38 ++++++++++++++++++ lib/vonage/verify2/workflows/silent_auth.rb | 32 +++++++++++++++ lib/vonage/verify2/workflows/sms.rb | 39 +++++++++++++++++++ lib/vonage/verify2/workflows/voice.rb | 32 +++++++++++++++ lib/vonage/verify2/workflows/whats_app.rb | 38 ++++++++++++++++++ .../workflows/whats_app_interactive.rb | 32 +++++++++++++++ 7 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 lib/vonage/verify2/workflows/email.rb create mode 100644 lib/vonage/verify2/workflows/silent_auth.rb create mode 100644 lib/vonage/verify2/workflows/sms.rb create mode 100644 lib/vonage/verify2/workflows/voice.rb create mode 100644 lib/vonage/verify2/workflows/whats_app.rb create mode 100644 lib/vonage/verify2/workflows/whats_app_interactive.rb diff --git a/lib/vonage/verify2/start_verification_options.rb b/lib/vonage/verify2/start_verification_options.rb index 31c4f144..477956d5 100644 --- a/lib/vonage/verify2/start_verification_options.rb +++ b/lib/vonage/verify2/start_verification_options.rb @@ -24,7 +24,7 @@ def initialize(**opts) def locale=(locale) unless VALID_LOCALES.include?(locale) - raise ArgumentError, "Invalid :locale. Please choose from the following #{VALID_LOCALES}" + raise ArgumentError, "Invalid 'locale' #{locale}. Please choose from the following #{VALID_LOCALES}" end @locale = locale @@ -32,7 +32,7 @@ def locale=(locale) def channel_timeout=(channel_timeout) unless channel_timeout.between?(MIN_CHANNEL_TIMEOUT, MAX_CHANNEL_TIMEOUT) - raise ArgumentError, "Invalid :channel_timeout #{channel_timeout}. Must be between #{MIN_CHANNEL_TIMEOUT} and #{MAX_CHANNEL_TIMEOUT} (inclusive)" + raise ArgumentError, "Invalid 'channel_timeout' #{channel_timeout}. Must be between #{MIN_CHANNEL_TIMEOUT} and #{MAX_CHANNEL_TIMEOUT} (inclusive)" end @channel_timeout = channel_timeout @@ -44,7 +44,7 @@ def client_ref=(client_ref) def code_length=(code_length) unless code_length.between?(MIN_CODE_LENGTH, MAX_CODE_LENGTH) - raise ArgumentError, "Invalid :code_length #{code_length}. Must be between #{MIN_CODE_LENGTH} and #{MAX_CODE_LENGTH} (inclusive)" + raise ArgumentError, "Invalid 'code_length' #{code_length}. Must be between #{MIN_CODE_LENGTH} and #{MAX_CODE_LENGTH} (inclusive)" end @code_length = code_length diff --git a/lib/vonage/verify2/workflows/email.rb b/lib/vonage/verify2/workflows/email.rb new file mode 100644 index 00000000..09ec3803 --- /dev/null +++ b/lib/vonage/verify2/workflows/email.rb @@ -0,0 +1,38 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::Email + + attr_reader :channel, :to, :from + + def initialize(to:, from: nil) + self.channel = 'email' + self.to = to + self.from = from if from + end + + def to=(to) + # TODO: add validation + @to = to + end + + def from=(from) + # TODO: add validation + @from = from + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end diff --git a/lib/vonage/verify2/workflows/silent_auth.rb b/lib/vonage/verify2/workflows/silent_auth.rb new file mode 100644 index 00000000..f14d954b --- /dev/null +++ b/lib/vonage/verify2/workflows/silent_auth.rb @@ -0,0 +1,32 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::SilentAuth + + attr_reader :channel, :to + + def initialize(to:) + self.channel = 'silent_auth' + self.to = to + end + + def to=(to) + raise ArgumentError, "Invalid 'to' value #{to}. Expected to be in E.164 format" unless Phonelib.parse(to.to_i).valid? + @to = to + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end diff --git a/lib/vonage/verify2/workflows/sms.rb b/lib/vonage/verify2/workflows/sms.rb new file mode 100644 index 00000000..fdab6107 --- /dev/null +++ b/lib/vonage/verify2/workflows/sms.rb @@ -0,0 +1,39 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::SMS + APP_HASH_LENGTH = 11 + + attr_reader :channel, :to, :app_hash + + def initialize(to:, app_hash: nil) + self.channel = 'sms' + self.to = to + self.app_hash = app_hash if app_hash + end + + def to=(to) + raise ArgumentError, "Invalid 'to' value #{to}. Expected to be in E.164 format" unless Phonelib.parse(to).valid? + @to = to + end + + def app_hash=(app_hash) + raise ArgumentError, "Invalid 'app_hash' value #{app_hash}. Length must be #{APP_HASH_LENGTH}" unless app_hash.length == APP_HASH_LENGTH + @app_hash = app_hash + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end diff --git a/lib/vonage/verify2/workflows/voice.rb b/lib/vonage/verify2/workflows/voice.rb new file mode 100644 index 00000000..51f0d117 --- /dev/null +++ b/lib/vonage/verify2/workflows/voice.rb @@ -0,0 +1,32 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::Voice + + attr_reader :channel, :to + + def initialize(to:) + self.channel = 'voice' + self.to = to + end + + def to=(to) + raise ArgumentError, "Invalid 'to' value #{to}. Expected to be in E.164 format" unless Phonelib.parse(to.to_i).valid? + @to = to + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end diff --git a/lib/vonage/verify2/workflows/whats_app.rb b/lib/vonage/verify2/workflows/whats_app.rb new file mode 100644 index 00000000..238c58b3 --- /dev/null +++ b/lib/vonage/verify2/workflows/whats_app.rb @@ -0,0 +1,38 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::WhatsApp + + attr_reader :channel, :to, :from + + def initialize(to:, from: nil) + self.channel = 'whatsapp' + self.to = to + self.from = from if from + end + + def to=(to) + raise ArgumentError, "Invalid 'to' value #{to}. Expected to be in E.164 format" unless Phonelib.parse(to.to_i).valid? + @to = to + end + + def from=(from) + raise ArgumentError, "Invalid 'from' value #{from}. Expected to be in E.164 format" unless Phonelib.parse(from.to_i).valid? + @from = from + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end diff --git a/lib/vonage/verify2/workflows/whats_app_interactive.rb b/lib/vonage/verify2/workflows/whats_app_interactive.rb new file mode 100644 index 00000000..b1eb5727 --- /dev/null +++ b/lib/vonage/verify2/workflows/whats_app_interactive.rb @@ -0,0 +1,32 @@ +# typed: true +# frozen_string_literal: true +require 'phonelib' + +module Vonage + class Verify2::Workflows::WhatsAppInteractive + + attr_reader :channel, :to + + def initialize(to:) + self.channel = 'whatsapp_interactive' + self.to = to + end + + def to=(to) + raise ArgumentError, "Invalid 'to' value #{to}. Expected to be in E.164 format" unless Phonelib.parse(to.to_i).valid? + @to = to + end + + def to_h + hash = Hash.new + self.instance_variables.each do |ivar| + hash[ivar.to_s.delete("@").to_sym] = self.instance_variable_get(ivar) + end + hash + end + + private + + attr_writer :channel + end +end From 68d202e193b141999974198ca14a9f907dbabe59 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 18:06:04 +0000 Subject: [PATCH 16/35] Adding workflow tests --- test/vonage/verify2/workflow_test.rb | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/vonage/verify2/workflow_test.rb diff --git a/test/vonage/verify2/workflow_test.rb b/test/vonage/verify2/workflow_test.rb new file mode 100644 index 00000000..d6ff9d20 --- /dev/null +++ b/test/vonage/verify2/workflow_test.rb @@ -0,0 +1,61 @@ +# typed: false + +class Vonage::Verify2::WorkflowTest < Vonage::Test + def workflow + Vonage::Verify2::Workflow.new + end + + def test_workflow_with_valid_channel + channel = workflow.sms(to: e164_compliant_number) + + assert_instance_of Vonage::Verify2::Workflows::SMS, channel + assert_equal 'sms', channel.channel + assert_equal({channel: 'sms', to: e164_compliant_number}, channel.to_h) + end + + def test_workflow_with_valid_channel_and_optional_parameters + channel = workflow.whatsapp(to: e164_compliant_number, from: e164_compliant_number) + + assert_instance_of Vonage::Verify2::Workflows::WhatsApp, channel + assert_equal 'whatsapp', channel.channel + assert_equal({channel: 'whatsapp', to: e164_compliant_number, from: e164_compliant_number}, channel.to_h) + end + + def test_workflow_with_invalid_channel + assert_raises { workflow.magic } + end + + Vonage::Verify2::Workflow::CHANNELS.keys.each do |method_name| + define_method "test_#{method_name}_workflow_method" do + assert_respond_to workflow, method_name + end + end + + def test_list_getter_method + flow = workflow + + assert_equal flow.instance_variable_get(:@list).object_id, flow.list.object_id + end + + def test_shovel_method + flow = workflow + channel1 = flow.sms(to: e164_compliant_number) + channel2 = flow.whatsapp(to: e164_compliant_number) + flow << channel1 + flow << channel2 + + assert_equal channel1.object_id, flow.list.first.object_id + assert_equal channel2.object_id, flow.list.last.object_id + end + + def test_hashified_list_method + flow = workflow + flow << flow.sms(to: e164_compliant_number) + flow << flow.whatsapp(to: e164_compliant_number) + + hashified_list = flow.hashified_list + assert hashified_list.all?(Hash) + assert_equal 'sms', hashified_list.first[:channel] + assert_equal 'whatsapp', hashified_list.last[:channel] + end +end From af8223a126dd3bb76402e8b0038e558787e0c18e Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 18:15:15 +0000 Subject: [PATCH 17/35] Implementing Workflow class --- lib/vonage/verify2/workflow.rb | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/vonage/verify2/workflow.rb diff --git a/lib/vonage/verify2/workflow.rb b/lib/vonage/verify2/workflow.rb new file mode 100644 index 00000000..6066ac33 --- /dev/null +++ b/lib/vonage/verify2/workflow.rb @@ -0,0 +1,39 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2::Workflow + CHANNELS = { + sms: Verify2::Workflows::SMS, + whatsapp: Verify2::Workflows::WhatsApp, + whatsapp_interactive: Verify2::Workflows::WhatsAppInteractive, + voice: Verify2::Workflows::Voice, + email: Verify2::Workflows::Email, + silent_auth: Verify2::Workflows::SilentAuth + } + + CHANNELS.keys.each do |method| + define_method method do |attributes| + CHANNELS[method].new(**attributes) + end + end + + def self.method_missing(method) + raise ClientError.new("Workflow channel must be one of the valid options. Please refer to https://developer.vonage.com/en/api/verify.v2#newRequest for a complete list.") + end + + attr_reader :list + + def initialize + @list = [] + end + + def <<(workflow) + list << workflow + end + + def hashified_list + list.map(&:to_h) + end + end +end From 6081779345155492e3facbadb3acfd4d982feda8 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 19:10:55 +0000 Subject: [PATCH 18/35] Adding WorkflowBuilder tests --- test/vonage/verify2/workflow_builder_test.rb | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/vonage/verify2/workflow_builder_test.rb diff --git a/test/vonage/verify2/workflow_builder_test.rb b/test/vonage/verify2/workflow_builder_test.rb new file mode 100644 index 00000000..9b7ce578 --- /dev/null +++ b/test/vonage/verify2/workflow_builder_test.rb @@ -0,0 +1,35 @@ +# typed: false + +class Vonage::Verify2::WorkflowTest < Vonage::Test + def workflow_bulder + Vonage::Verify2::WorkflowBuilder.new + end + + Vonage::Verify2::Workflow::CHANNELS.keys.each do |channel| + define_method "test_add_#{channel}_channel_method" do + assert_respond_to workflow_bulder, "add_#{channel}" + end + end + + def test_build_method + workflow = Vonage::Verify2::WorkflowBuilder.build do |builder| + builder.add_sms(to: e164_compliant_number) + end + + assert_instance_of Vonage::Verify2::Workflow, workflow + assert_instance_of Vonage::Verify2::Workflows::SMS, workflow.list.first + assert_equal({channel: 'sms', to: e164_compliant_number}, workflow.list.first.to_h) + end + + def test_build_method_adding_multiple_channels + workflow = Vonage::Verify2::WorkflowBuilder.build do |builder| + builder.add_sms(to: e164_compliant_number) + builder.add_whatsapp(to: e164_compliant_number) + end + + assert_instance_of Vonage::Verify2::Workflow, workflow + assert_instance_of Vonage::Verify2::Workflows::SMS, workflow.list.first + assert_instance_of Vonage::Verify2::Workflows::WhatsApp, workflow.list.last + assert_equal({channel: 'whatsapp', to: e164_compliant_number}, workflow.list.last.to_h) + end +end From 0f1f99ae094e7cbe02d963dd1a608213d360f497 Mon Sep 17 00:00:00 2001 From: superchilled Date: Sun, 19 Mar 2023 19:21:14 +0000 Subject: [PATCH 19/35] Implement WorkflowBuilder --- lib/vonage/verify2/workflow_builder.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/vonage/verify2/workflow_builder.rb diff --git a/lib/vonage/verify2/workflow_builder.rb b/lib/vonage/verify2/workflow_builder.rb new file mode 100644 index 00000000..7c7202e6 --- /dev/null +++ b/lib/vonage/verify2/workflow_builder.rb @@ -0,0 +1,25 @@ +# typed: true +# frozen_string_literal: true + +module Vonage + class Verify2::WorkflowBuilder + + def self.build + builder = self.new + yield builder if block_given? + builder.workflow + end + + attr_reader :workflow + + def initialize + @workflow = Vonage::Verify2::Workflow.new + end + + Vonage::Verify2::Workflow::CHANNELS.keys.each do |channel| + define_method "add_#{channel.to_s}" do |args| + workflow << workflow.send(channel, **args) + end + end + end +end From e27df55fe316c134d38933fdb0aa58c12b592ae3 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 20 Mar 2023 11:14:22 +0000 Subject: [PATCH 20/35] Adding tests for Verify2 options, workflow, and workflow_builder methods --- test/vonage/verify2_test.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index b9eb9535..a272509c 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -106,4 +106,33 @@ def test_check_code_method_without_code verify2.check_code(request_id: request_id) end end + + def test_start_verification_options_method + assert_instance_of Vonage::Verify2::StartVerificationOptions, verify2.start_verification_options + end + + def test_start_verification_options_method_with_opts + opts = { + locale: 'en-gb', + channel_timeout: 300, + client_ref: 'foo', + code_length: 6 + } + + verification_opts = verify2.start_verification_options(**opts) + + assert_instance_of Vonage::Verify2::StartVerificationOptions, verification_opts + assert_equal opts[:locale], verification_opts.locale + assert_equal opts[:channel_timeout], verification_opts.channel_timeout + assert_equal opts[:client_ref], verification_opts.client_ref + assert_equal opts[:code_length], verification_opts.code_length + end + + def test_workflow_method + assert_instance_of Vonage::Verify2::Workflow, verify2.workflow + end + + def test_workflow_builder_method + assert_equal Vonage::Verify2::WorkflowBuilder, verify2.workflow_builder + end end From b0dcad4f1cb3d6d0c283d5f60a45f9c3c39359b0 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 20 Mar 2023 11:21:29 +0000 Subject: [PATCH 21/35] Implementing Verify2 options, workflow, and workflow_builder methods --- lib/vonage/verify2.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 47cf7ad2..645dc393 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -25,5 +25,20 @@ def start_verification(brand:, workflow:, **opts) def check_code(request_id:, code:) request('/v2/verify/' + request_id, params: {code: code}, type: Post) end + + # Instantiate a new Vonage::Verify2::StartVerificationOptions object + def start_verification_options(**opts) + StartVerificationOptions.new(**opts) + end + + # Instantiate a new Vonage::Verify2::Workflow object + def workflow + Workflow.new + end + + # Returns the Vonage::Verify2::WorkflowBuilder class + def workflow_builder + WorkflowBuilder.itself + end end end From 89c39d5dd7a25cde17425d7c8bf5b59d88a20419 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 20 Mar 2023 12:58:28 +0000 Subject: [PATCH 22/35] Renaming Workflows to Channels --- .../verify2/{workflows => channels}/email.rb | 2 +- .../{workflows => channels}/silent_auth.rb | 2 +- .../verify2/{workflows => channels}/sms.rb | 2 +- .../verify2/{workflows => channels}/voice.rb | 2 +- .../{workflows => channels}/whats_app.rb | 2 +- .../whats_app_interactive.rb | 2 +- lib/vonage/verify2/workflow.rb | 12 ++-- test/vonage/verify2/channels/email_test.rb | 49 +++++++++++++++ .../verify2/channels/silent_auth_test.rb | 36 +++++++++++ test/vonage/verify2/channels/sms_test.rb | 61 +++++++++++++++++++ test/vonage/verify2/channels/voice_test.rb | 36 +++++++++++ .../channels/whats_app_interactive_test.rb | 36 +++++++++++ .../vonage/verify2/channels/whats_app_test.rb | 57 +++++++++++++++++ test/vonage/verify2/workflow_builder_test.rb | 6 +- test/vonage/verify2/workflow_test.rb | 4 +- test/vonage/verify2/workflows/email_test.rb | 49 --------------- .../verify2/workflows/silent_auth_test.rb | 36 ----------- test/vonage/verify2/workflows/sms_test.rb | 61 ------------------- test/vonage/verify2/workflows/voice_test.rb | 36 ----------- .../workflows/whats_app_interactive_test.rb | 36 ----------- .../verify2/workflows/whats_app_test.rb | 57 ----------------- 21 files changed, 292 insertions(+), 292 deletions(-) rename lib/vonage/verify2/{workflows => channels}/email.rb (94%) rename lib/vonage/verify2/{workflows => channels}/silent_auth.rb (93%) rename lib/vonage/verify2/{workflows => channels}/sms.rb (96%) rename lib/vonage/verify2/{workflows => channels}/voice.rb (94%) rename lib/vonage/verify2/{workflows => channels}/whats_app.rb (95%) rename lib/vonage/verify2/{workflows => channels}/whats_app_interactive.rb (92%) create mode 100644 test/vonage/verify2/channels/email_test.rb create mode 100644 test/vonage/verify2/channels/silent_auth_test.rb create mode 100644 test/vonage/verify2/channels/sms_test.rb create mode 100644 test/vonage/verify2/channels/voice_test.rb create mode 100644 test/vonage/verify2/channels/whats_app_interactive_test.rb create mode 100644 test/vonage/verify2/channels/whats_app_test.rb delete mode 100644 test/vonage/verify2/workflows/email_test.rb delete mode 100644 test/vonage/verify2/workflows/silent_auth_test.rb delete mode 100644 test/vonage/verify2/workflows/sms_test.rb delete mode 100644 test/vonage/verify2/workflows/voice_test.rb delete mode 100644 test/vonage/verify2/workflows/whats_app_interactive_test.rb delete mode 100644 test/vonage/verify2/workflows/whats_app_test.rb diff --git a/lib/vonage/verify2/workflows/email.rb b/lib/vonage/verify2/channels/email.rb similarity index 94% rename from lib/vonage/verify2/workflows/email.rb rename to lib/vonage/verify2/channels/email.rb index 09ec3803..0ecf02bb 100644 --- a/lib/vonage/verify2/workflows/email.rb +++ b/lib/vonage/verify2/channels/email.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::Email + class Verify2::Channels::Email attr_reader :channel, :to, :from diff --git a/lib/vonage/verify2/workflows/silent_auth.rb b/lib/vonage/verify2/channels/silent_auth.rb similarity index 93% rename from lib/vonage/verify2/workflows/silent_auth.rb rename to lib/vonage/verify2/channels/silent_auth.rb index f14d954b..55de4972 100644 --- a/lib/vonage/verify2/workflows/silent_auth.rb +++ b/lib/vonage/verify2/channels/silent_auth.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::SilentAuth + class Verify2::Channels::SilentAuth attr_reader :channel, :to diff --git a/lib/vonage/verify2/workflows/sms.rb b/lib/vonage/verify2/channels/sms.rb similarity index 96% rename from lib/vonage/verify2/workflows/sms.rb rename to lib/vonage/verify2/channels/sms.rb index fdab6107..770610e3 100644 --- a/lib/vonage/verify2/workflows/sms.rb +++ b/lib/vonage/verify2/channels/sms.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::SMS + class Verify2::Channels::SMS APP_HASH_LENGTH = 11 attr_reader :channel, :to, :app_hash diff --git a/lib/vonage/verify2/workflows/voice.rb b/lib/vonage/verify2/channels/voice.rb similarity index 94% rename from lib/vonage/verify2/workflows/voice.rb rename to lib/vonage/verify2/channels/voice.rb index 51f0d117..a0f4450a 100644 --- a/lib/vonage/verify2/workflows/voice.rb +++ b/lib/vonage/verify2/channels/voice.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::Voice + class Verify2::Channels::Voice attr_reader :channel, :to diff --git a/lib/vonage/verify2/workflows/whats_app.rb b/lib/vonage/verify2/channels/whats_app.rb similarity index 95% rename from lib/vonage/verify2/workflows/whats_app.rb rename to lib/vonage/verify2/channels/whats_app.rb index 238c58b3..e5eaeafa 100644 --- a/lib/vonage/verify2/workflows/whats_app.rb +++ b/lib/vonage/verify2/channels/whats_app.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::WhatsApp + class Verify2::Channels::WhatsApp attr_reader :channel, :to, :from diff --git a/lib/vonage/verify2/workflows/whats_app_interactive.rb b/lib/vonage/verify2/channels/whats_app_interactive.rb similarity index 92% rename from lib/vonage/verify2/workflows/whats_app_interactive.rb rename to lib/vonage/verify2/channels/whats_app_interactive.rb index b1eb5727..99c09523 100644 --- a/lib/vonage/verify2/workflows/whats_app_interactive.rb +++ b/lib/vonage/verify2/channels/whats_app_interactive.rb @@ -3,7 +3,7 @@ require 'phonelib' module Vonage - class Verify2::Workflows::WhatsAppInteractive + class Verify2::Channels::WhatsAppInteractive attr_reader :channel, :to diff --git a/lib/vonage/verify2/workflow.rb b/lib/vonage/verify2/workflow.rb index 6066ac33..54415660 100644 --- a/lib/vonage/verify2/workflow.rb +++ b/lib/vonage/verify2/workflow.rb @@ -4,12 +4,12 @@ module Vonage class Verify2::Workflow CHANNELS = { - sms: Verify2::Workflows::SMS, - whatsapp: Verify2::Workflows::WhatsApp, - whatsapp_interactive: Verify2::Workflows::WhatsAppInteractive, - voice: Verify2::Workflows::Voice, - email: Verify2::Workflows::Email, - silent_auth: Verify2::Workflows::SilentAuth + sms: Verify2::Channels::SMS, + whatsapp: Verify2::Channels::WhatsApp, + whatsapp_interactive: Verify2::Channels::WhatsAppInteractive, + voice: Verify2::Channels::Voice, + email: Verify2::Channels::Email, + silent_auth: Verify2::Channels::SilentAuth } CHANNELS.keys.each do |method| diff --git a/test/vonage/verify2/channels/email_test.rb b/test/vonage/verify2/channels/email_test.rb new file mode 100644 index 00000000..4a46adfc --- /dev/null +++ b/test/vonage/verify2/channels/email_test.rb @@ -0,0 +1,49 @@ +# typed: false + +class Vonage::Verify2::Channels::EmailTest < Vonage::Test + def email_channel + Vonage::Verify2::Channels::Email.new(to: valid_email) + end + + def valid_email + 'alice@example.com' + end + + def channel_getter_method + assert_equal 'whatsapp', email_channel.channel + end + + def test_to_getter_method + assert_equal valid_email, email_channel.to + end + + def test_to_setter_method + channel = email_channel + new_email = 'bob@example.com' + channel.to = new_email + + assert_equal new_email, channel.instance_variable_get(:@to) + end + + def test_from_getter_method + assert_nil email_channel.from + end + + def test_from_setter_method + channel = email_channel + channel.from = valid_email + + assert_equal valid_email, channel.instance_variable_get(:@from) + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::Email.new( + to: valid_email, + from: valid_email + ).to_h + + assert_kind_of Hash, channel_hash + assert_equal valid_email, channel_hash[:to] + assert_equal valid_email, channel_hash[:from] + end +end diff --git a/test/vonage/verify2/channels/silent_auth_test.rb b/test/vonage/verify2/channels/silent_auth_test.rb new file mode 100644 index 00000000..9f326158 --- /dev/null +++ b/test/vonage/verify2/channels/silent_auth_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Channels::SilentAuthTest < Vonage::Test + def silent_auth_channel + Vonage::Verify2::Channels::SilentAuth.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'silent_auth', silent_auth_channel.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, silent_auth_channel.to + end + + def test_to_setter_method + channel = silent_auth_channel + new_number = '447000000001' + channel.to = new_number + + assert_equal new_number, channel.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + silent_auth_channel.to = invalid_number + end + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::SilentAuth.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, channel_hash + assert_equal e164_compliant_number, channel_hash[:to] + end +end diff --git a/test/vonage/verify2/channels/sms_test.rb b/test/vonage/verify2/channels/sms_test.rb new file mode 100644 index 00000000..7f0168d6 --- /dev/null +++ b/test/vonage/verify2/channels/sms_test.rb @@ -0,0 +1,61 @@ +# typed: false + +class Vonage::Verify2::Channels::SMSTest < Vonage::Test + def sms_channel + Vonage::Verify2::Channels::SMS.new(to: e164_compliant_number) + end + + def valid_android_app_hash + 'FA+9qCX9VSu' + end + + def channel_getter_method + assert_equal 'sms', sms_channel.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, sms_channel.to + end + + def test_to_setter_method + channel = sms_channel + new_number = '447000000001' + channel.to = new_number + + assert_equal new_number, channel.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + sms_channel.to = invalid_number + end + end + + def test_app_hash_getter_method + assert_nil sms_channel.app_hash + end + + def test_app_hash_setter_method + channel = sms_channel + channel.app_hash = valid_android_app_hash + + assert_equal valid_android_app_hash, channel.instance_variable_get(:@app_hash) + end + + def test_app_hash_setter_method_with_invalid_arg + assert_raises ArgumentError do + sms_channel.app_hash = valid_android_app_hash[0..8] + end + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::SMS.new( + to: e164_compliant_number, + app_hash: valid_android_app_hash + ).to_h + + assert_kind_of Hash, channel_hash + assert_equal e164_compliant_number, channel_hash[:to] + assert_equal valid_android_app_hash, channel_hash[:app_hash] + end +end diff --git a/test/vonage/verify2/channels/voice_test.rb b/test/vonage/verify2/channels/voice_test.rb new file mode 100644 index 00000000..02c71f6f --- /dev/null +++ b/test/vonage/verify2/channels/voice_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Channels::VoiceTest < Vonage::Test + def voice_channel + Vonage::Verify2::Channels::Voice.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'voice', voice_channel.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, voice_channel.to + end + + def test_to_setter_method + channel = voice_channel + new_number = '447000000001' + channel.to = new_number + + assert_equal new_number, channel.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + voice_channel.to = invalid_number + end + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::Voice.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, channel_hash + assert_equal e164_compliant_number, channel_hash[:to] + end +end diff --git a/test/vonage/verify2/channels/whats_app_interactive_test.rb b/test/vonage/verify2/channels/whats_app_interactive_test.rb new file mode 100644 index 00000000..e46cad74 --- /dev/null +++ b/test/vonage/verify2/channels/whats_app_interactive_test.rb @@ -0,0 +1,36 @@ +# typed: false + +class Vonage::Verify2::Channels::WhatsAppInteractiveTest < Vonage::Test + def whatsapp_interactive_channel + Vonage::Verify2::Channels::WhatsAppInteractive.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'whatsapp_interactive', whatsapp_interactive_channel.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, whatsapp_interactive_channel.to + end + + def test_to_setter_method + channel = whatsapp_interactive_channel + new_number = '447000000001' + channel.to = new_number + + assert_equal new_number, channel.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + whatsapp_interactive_channel.to = invalid_number + end + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::WhatsAppInteractive.new(to: e164_compliant_number).to_h + + assert_kind_of Hash, channel_hash + assert_equal e164_compliant_number, channel_hash[:to] + end +end diff --git a/test/vonage/verify2/channels/whats_app_test.rb b/test/vonage/verify2/channels/whats_app_test.rb new file mode 100644 index 00000000..37729f0a --- /dev/null +++ b/test/vonage/verify2/channels/whats_app_test.rb @@ -0,0 +1,57 @@ +# typed: false + +class Vonage::Verify2::Channels::WhatsAppTest < Vonage::Test + def whatsapp_channel + Vonage::Verify2::Channels::WhatsApp.new(to: e164_compliant_number) + end + + def channel_getter_method + assert_equal 'whatsapp', whatsapp_channel.channel + end + + def test_to_getter_method + assert_equal e164_compliant_number, whatsapp_channel.to + end + + def test_to_setter_method + channel = whatsapp_channel + new_number = '447000000001' + channel.to = new_number + + assert_equal new_number, channel.instance_variable_get(:@to) + end + + def test_to_setter_method_with_invalid_number + assert_raises ArgumentError do + whatsapp_channel.to = invalid_number + end + end + + def test_from_getter_method + assert_nil whatsapp_channel.from + end + + def test_from_setter_method + channel = whatsapp_channel + channel.from = e164_compliant_number + + assert_equal e164_compliant_number, channel.instance_variable_get(:@from) + end + + def test_from_setter_method_with_invalid_arg + assert_raises ArgumentError do + whatsapp_channel.from = invalid_number + end + end + + def test_to_h_method + channel_hash = Vonage::Verify2::Channels::WhatsApp.new( + to: e164_compliant_number, + from: e164_compliant_number + ).to_h + + assert_kind_of Hash, channel_hash + assert_equal e164_compliant_number, channel_hash[:to] + assert_equal e164_compliant_number, channel_hash[:from] + end +end diff --git a/test/vonage/verify2/workflow_builder_test.rb b/test/vonage/verify2/workflow_builder_test.rb index 9b7ce578..e4ef3535 100644 --- a/test/vonage/verify2/workflow_builder_test.rb +++ b/test/vonage/verify2/workflow_builder_test.rb @@ -17,7 +17,7 @@ def test_build_method end assert_instance_of Vonage::Verify2::Workflow, workflow - assert_instance_of Vonage::Verify2::Workflows::SMS, workflow.list.first + assert_instance_of Vonage::Verify2::Channels::SMS, workflow.list.first assert_equal({channel: 'sms', to: e164_compliant_number}, workflow.list.first.to_h) end @@ -28,8 +28,8 @@ def test_build_method_adding_multiple_channels end assert_instance_of Vonage::Verify2::Workflow, workflow - assert_instance_of Vonage::Verify2::Workflows::SMS, workflow.list.first - assert_instance_of Vonage::Verify2::Workflows::WhatsApp, workflow.list.last + assert_instance_of Vonage::Verify2::Channels::SMS, workflow.list.first + assert_instance_of Vonage::Verify2::Channels::WhatsApp, workflow.list.last assert_equal({channel: 'whatsapp', to: e164_compliant_number}, workflow.list.last.to_h) end end diff --git a/test/vonage/verify2/workflow_test.rb b/test/vonage/verify2/workflow_test.rb index d6ff9d20..47cf7c22 100644 --- a/test/vonage/verify2/workflow_test.rb +++ b/test/vonage/verify2/workflow_test.rb @@ -8,7 +8,7 @@ def workflow def test_workflow_with_valid_channel channel = workflow.sms(to: e164_compliant_number) - assert_instance_of Vonage::Verify2::Workflows::SMS, channel + assert_instance_of Vonage::Verify2::Channels::SMS, channel assert_equal 'sms', channel.channel assert_equal({channel: 'sms', to: e164_compliant_number}, channel.to_h) end @@ -16,7 +16,7 @@ def test_workflow_with_valid_channel def test_workflow_with_valid_channel_and_optional_parameters channel = workflow.whatsapp(to: e164_compliant_number, from: e164_compliant_number) - assert_instance_of Vonage::Verify2::Workflows::WhatsApp, channel + assert_instance_of Vonage::Verify2::Channels::WhatsApp, channel assert_equal 'whatsapp', channel.channel assert_equal({channel: 'whatsapp', to: e164_compliant_number, from: e164_compliant_number}, channel.to_h) end diff --git a/test/vonage/verify2/workflows/email_test.rb b/test/vonage/verify2/workflows/email_test.rb deleted file mode 100644 index 33609c92..00000000 --- a/test/vonage/verify2/workflows/email_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::EmailTest < Vonage::Test - def email_workflow - Vonage::Verify2::Workflows::Email.new(to: valid_email) - end - - def valid_email - 'alice@example.com' - end - - def channel_getter_method - assert_equal 'whatsapp', email_workflow.channel - end - - def test_to_getter_method - assert_equal valid_email, email_workflow.to - end - - def test_to_setter_method - workflow = email_workflow - new_email = 'bob@example.com' - workflow.to = new_email - - assert_equal new_email, workflow.instance_variable_get(:@to) - end - - def test_from_getter_method - assert_nil email_workflow.from - end - - def test_from_setter_method - workflow = email_workflow - workflow.from = valid_email - - assert_equal valid_email, workflow.instance_variable_get(:@from) - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::Email.new( - to: valid_email, - from: valid_email - ).to_h - - assert_kind_of Hash, workflow_hash - assert_equal valid_email, workflow_hash[:to] - assert_equal valid_email, workflow_hash[:from] - end -end diff --git a/test/vonage/verify2/workflows/silent_auth_test.rb b/test/vonage/verify2/workflows/silent_auth_test.rb deleted file mode 100644 index 7e89e244..00000000 --- a/test/vonage/verify2/workflows/silent_auth_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::SilentAuthTest < Vonage::Test - def silent_auth_workflow - Vonage::Verify2::Workflows::SilentAuth.new(to: e164_compliant_number) - end - - def channel_getter_method - assert_equal 'silent_auth', silent_auth_workflow.channel - end - - def test_to_getter_method - assert_equal e164_compliant_number, silent_auth_workflow.to - end - - def test_to_setter_method - workflow = silent_auth_workflow - new_number = '447000000001' - workflow.to = new_number - - assert_equal new_number, workflow.instance_variable_get(:@to) - end - - def test_to_setter_method_with_invalid_number - assert_raises ArgumentError do - silent_auth_workflow.to = invalid_number - end - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::SilentAuth.new(to: e164_compliant_number).to_h - - assert_kind_of Hash, workflow_hash - assert_equal e164_compliant_number, workflow_hash[:to] - end -end diff --git a/test/vonage/verify2/workflows/sms_test.rb b/test/vonage/verify2/workflows/sms_test.rb deleted file mode 100644 index 357e2029..00000000 --- a/test/vonage/verify2/workflows/sms_test.rb +++ /dev/null @@ -1,61 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::SMSTest < Vonage::Test - def sms_workflow - Vonage::Verify2::Workflows::SMS.new(to: e164_compliant_number) - end - - def valid_android_app_hash - 'FA+9qCX9VSu' - end - - def channel_getter_method - assert_equal 'sms', sms_workflow.channel - end - - def test_to_getter_method - assert_equal e164_compliant_number, sms_workflow.to - end - - def test_to_setter_method - workflow = sms_workflow - new_number = '447000000001' - workflow.to = new_number - - assert_equal new_number, workflow.instance_variable_get(:@to) - end - - def test_to_setter_method_with_invalid_number - assert_raises ArgumentError do - sms_workflow.to = invalid_number - end - end - - def test_app_hash_getter_method - assert_nil sms_workflow.app_hash - end - - def test_app_hash_setter_method - workflow = sms_workflow - workflow.app_hash = valid_android_app_hash - - assert_equal valid_android_app_hash, workflow.instance_variable_get(:@app_hash) - end - - def test_app_hash_setter_method_with_invalid_arg - assert_raises ArgumentError do - sms_workflow.app_hash = valid_android_app_hash[0..8] - end - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::SMS.new( - to: e164_compliant_number, - app_hash: valid_android_app_hash - ).to_h - - assert_kind_of Hash, workflow_hash - assert_equal e164_compliant_number, workflow_hash[:to] - assert_equal valid_android_app_hash, workflow_hash[:app_hash] - end -end diff --git a/test/vonage/verify2/workflows/voice_test.rb b/test/vonage/verify2/workflows/voice_test.rb deleted file mode 100644 index 1116af97..00000000 --- a/test/vonage/verify2/workflows/voice_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::VoiceTest < Vonage::Test - def voice_workflow - Vonage::Verify2::Workflows::Voice.new(to: e164_compliant_number) - end - - def channel_getter_method - assert_equal 'voice', voice_workflow.channel - end - - def test_to_getter_method - assert_equal e164_compliant_number, voice_workflow.to - end - - def test_to_setter_method - workflow = voice_workflow - new_number = '447000000001' - workflow.to = new_number - - assert_equal new_number, workflow.instance_variable_get(:@to) - end - - def test_to_setter_method_with_invalid_number - assert_raises ArgumentError do - voice_workflow.to = invalid_number - end - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::Voice.new(to: e164_compliant_number).to_h - - assert_kind_of Hash, workflow_hash - assert_equal e164_compliant_number, workflow_hash[:to] - end -end diff --git a/test/vonage/verify2/workflows/whats_app_interactive_test.rb b/test/vonage/verify2/workflows/whats_app_interactive_test.rb deleted file mode 100644 index 3ba3b4b9..00000000 --- a/test/vonage/verify2/workflows/whats_app_interactive_test.rb +++ /dev/null @@ -1,36 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::WhatsAppInteractiveTest < Vonage::Test - def whatsapp_interactive_workflow - Vonage::Verify2::Workflows::WhatsAppInteractive.new(to: e164_compliant_number) - end - - def channel_getter_method - assert_equal 'whatsapp_interactive', whatsapp_interactive_workflow.channel - end - - def test_to_getter_method - assert_equal e164_compliant_number, whatsapp_interactive_workflow.to - end - - def test_to_setter_method - workflow = whatsapp_interactive_workflow - new_number = '447000000001' - workflow.to = new_number - - assert_equal new_number, workflow.instance_variable_get(:@to) - end - - def test_to_setter_method_with_invalid_number - assert_raises ArgumentError do - whatsapp_interactive_workflow.to = invalid_number - end - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::WhatsAppInteractive.new(to: e164_compliant_number).to_h - - assert_kind_of Hash, workflow_hash - assert_equal e164_compliant_number, workflow_hash[:to] - end -end diff --git a/test/vonage/verify2/workflows/whats_app_test.rb b/test/vonage/verify2/workflows/whats_app_test.rb deleted file mode 100644 index 9b864277..00000000 --- a/test/vonage/verify2/workflows/whats_app_test.rb +++ /dev/null @@ -1,57 +0,0 @@ -# typed: false - -class Vonage::Verify2::Workflows::WhatsAppTest < Vonage::Test - def whatsapp_workflow - Vonage::Verify2::Workflows::WhatsApp.new(to: e164_compliant_number) - end - - def channel_getter_method - assert_equal 'whatsapp', whatsapp_workflow.channel - end - - def test_to_getter_method - assert_equal e164_compliant_number, whatsapp_workflow.to - end - - def test_to_setter_method - workflow = whatsapp_workflow - new_number = '447000000001' - workflow.to = new_number - - assert_equal new_number, workflow.instance_variable_get(:@to) - end - - def test_to_setter_method_with_invalid_number - assert_raises ArgumentError do - whatsapp_workflow.to = invalid_number - end - end - - def test_from_getter_method - assert_nil whatsapp_workflow.from - end - - def test_from_setter_method - workflow = whatsapp_workflow - workflow.from = e164_compliant_number - - assert_equal e164_compliant_number, workflow.instance_variable_get(:@from) - end - - def test_from_setter_method_with_invalid_arg - assert_raises ArgumentError do - whatsapp_workflow.from = invalid_number - end - end - - def test_to_h_method - workflow_hash = Vonage::Verify2::Workflows::WhatsApp.new( - to: e164_compliant_number, - from: e164_compliant_number - ).to_h - - assert_kind_of Hash, workflow_hash - assert_equal e164_compliant_number, workflow_hash[:to] - assert_equal e164_compliant_number, workflow_hash[:from] - end -end From 433659c2a3e978601e1e38e4b757896cb26ac6d7 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 21 Mar 2023 12:13:26 +0000 Subject: [PATCH 23/35] Updating README to add Verify2 --- README.md | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/README.md b/README.md index 3f4d6376..2721dbe4 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ need a Vonage account. Sign up [for free at vonage.com][signup]. * [Webhook signatures](#webhook-signatures) * [Pagination](#pagination) * [NCCO Builder](#ncco-builder) + * [Messages API](#messages-api) + * [Verify API v2](#verify-api-v2) * [Documentation](#documentation) * [Frequently Asked Questions](#frequently-asked-questions) * [Supported APIs](#supported-apis) @@ -220,6 +222,120 @@ Once the message data is created, you can then send the message. response = client.messaging.send(to: "447700900000", from: "447700900001", **message) ``` +## Verify API v2 + +The [Vonage Verify API v2](https://developer.vonage.com/en/verify/verify-v2/overview) allows you to manage 2FA verification workflows over a number of different channels such as SMS, WhatsApp, WhatsApp Interactive, Voice, Email, and Silent Authentication, either individually or in combination with each other. See the Vonage Developer Documentation for a [complete API reference](https://developer.vonage.com/en/api/verify.v2) listing all the channels, verification options, and callback types. + +The Ruby SDK provides two methods for interacting with the Verify v2 API: + +- `Verify2#start_verification`: starts a new verification request. Here you can specify options for the request and the workflow to be used. +- `Verify2#check_code`: for channels where the end-user is sent a one-time code, this method is used to verify the code against the `request_id` of the verification request created by the `start_verification` method. + +### Creating a Verify2 Object + +```ruby +verify = client.verify2 +``` + +### Making a verification request + +For simple requests, you may prefer to manually set the value for `workflow` (an array of one or more hashes containing the settings for a particular channel) and any optional params. + +Example with the required `:brand` and `:workflow` arguments: + +```ruby +verification_request = verify.start_verification( + brand: 'Acme', + workflow: [{channel: 'sms', to: '447000000000'}] +) +``` + +Example with the required `:brand` and `:workflow` arguments, and an optional `code_length`: + +```ruby +verification_request = verify.start_verification( + brand: 'Acme', + workflow: [{channel: 'sms', to: '447000000000'}], + code_length: 6 +) +``` + +For more complex requests (e.g. with mutliple workflow channels or addtional options), or to take advantage of built-in input validation, you can use the `StartVerificationOptions` object and the `Workflow` and various channel objects or the `WorkflowBuilder`: + +#### Create options using StartVerificationOptions object + +```ruby +opts = verify.start_verification_options( + locale: 'fr-fr', + code_length: 6, + client_ref: 'abc-123' +).to_h + +verification_request = verify.start_verification( + brand: 'Acme', + workflow: [{channel: 'email', to: 'alice.example.com'}], + **opts +) +``` + +#### Create workflow using Workflow and Channel objects + +```ruby +# Instantiate a Workflow object +workflow = verify.workflow + +# Add channels to the workflow +workflow << workflow.sms(to: '447000000000') +workflow << workflow.email(to: 'alice.example.com') + +# Channel data is encpsulated in channel objects stored in the Workflow list array +workflow.list +# => [ #, + #] + +# To use the list as the value for `:workflow` in a `start_verification` request call, +# the objects must be hashified +workflow_list = workflow.hashified_list +# => [{:channel=>"sms", :to=>"447000000000"}, {:channel=>"email", :to=>"alice.example.com"}] + +verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list) +``` + +#### Create a workflow using the WorkflowBuilder + +```ruby +workflow = verify.workflow_builder.build do |builder| + builder.add_voice(to: '447000000001') + builder.add_whatsapp(to: '447000000000') +end + +workflow_list = workflow.hashified_list +# => [{:channel=>"voice", :to=>"447000000001"}, {:channel=>"whatsapp", :to=>"447000000000"}] + +verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list) +``` + +### Checking a code + +```ruby +# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call +request_id = verification_request.request_id + +# Get the one-time code via user input +# e.g. from params in a route handler or controller action for a form input +code = params[:code] + +begin + code_check = verify.check_code(request_id: request_id, code: code) +rescue => error + # an invalid code will raise an exception of type Vonage::ClientError +end + +if code_check.http_response.code == '200' + # code is valid +end +``` + ## Documentation Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk @@ -252,6 +368,7 @@ The following is a list of Vonage APIs and whether the Ruby SDK provides support | Reports API | Beta |❌| | SMS API | General Availability |✅| | Verify API | General Availability |✅| +| Verify API v2 | General Availability |✅| | Voice API | General Availability |✅| ## License From 8e6514c84c41b85e1c3fbbddaab122b7cf9d6fb5 Mon Sep 17 00:00:00 2001 From: superchilled Date: Tue, 21 Mar 2023 12:56:35 +0000 Subject: [PATCH 24/35] Adding code comments for Verify2 methods --- lib/vonage/verify2.rb | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 645dc393..cd3b66f3 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -9,6 +9,24 @@ class Verify2 < Namespace # Request a verification be sent to a user. # + # @example + # verification_request = verify.start_verification( + # brand: 'Acme', + # workflow: [{channel: 'sms', to: '447000000000'}], + # code_length: 6 + # ) + # + # @param [required, String] :brand The brand that is sending the verification request + # + # @param [required, Array] :workflow An array of hashes for channels in the workflow + # + # @param [optional, Hash] opts the options for the verification request. + # @option opts [Integer] :code_length The length of the one-time code provided to the end-user + # @option opts [String] :locale The language to use for the verification message (where applicable) + # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow + # @option opts [String] :client_ref Reference to be included in callbacks + # + # @return Vomage::Response # @see https://developer.vonage.com/en/api/verify.v2#newRequest # def start_verification(brand:, workflow:, **opts) @@ -20,6 +38,13 @@ def start_verification(brand:, workflow:, **opts) # Check a supplied code against a request to see if it is valid. # + # @example + # code_check = verify.check_code(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2', code: '1234') + # + # @param [required, String] :request_id The request_id of the verification request being checked + # + # @param [required, String] :code The code supplied to the end-user by the verification request + # # @see https://developer.vonage.com/en/api/verify.v2#checkCode # def check_code(request_id:, code:) @@ -27,6 +52,13 @@ def check_code(request_id:, code:) end # Instantiate a new Vonage::Verify2::StartVerificationOptions object + # + # @param [optional, Hash] opts the options for the verification request. + # @option opts [Integer] :code_length The length of the one-time code provided to the end-user + # @option opts [String] :locale The language to use for the verification message (where applicable) + # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow + # @option opts [String] :client_ref Reference to be included in callbacks + # def start_verification_options(**opts) StartVerificationOptions.new(**opts) end @@ -36,7 +68,7 @@ def workflow Workflow.new end - # Returns the Vonage::Verify2::WorkflowBuilder class + # Return the Vonage::Verify2::WorkflowBuilder class def workflow_builder WorkflowBuilder.itself end From 0c784da28a5e5e90bbbdcd38785acbfd3c75c324 Mon Sep 17 00:00:00 2001 From: Raphael Nestler Date: Thu, 4 May 2023 15:31:58 +0200 Subject: [PATCH 25/35] Update link to code snippets in README.md The old link is archived and points to the updated link. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f4d6376..9882ac46 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ response = client.messaging.send(to: "447700900000", from: "447700900001", **mes Vonage Ruby documentation: https://www.rubydoc.info/github/Vonage/vonage-ruby-sdk -Vonage Ruby code examples: https://github.com/Nexmo/nexmo-ruby-code-snippets +Vonage Ruby code examples: https://github.com/Vonage/vonage-ruby-code-snippets Vonage APIs API reference: https://developer.nexmo.com/api From 58bdebee3dca640f65e8032687a882a7b507020a Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 12:45:48 +0900 Subject: [PATCH 26/35] DEVX-7298: add tests for cancel verification --- test/vonage/verify2_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index a272509c..2d1d8109 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -25,6 +25,10 @@ def check_request_uri uri + request_id end + def cancel_request_uri + uri + request_id + end + def to_number '447700900000' end @@ -128,6 +132,18 @@ def test_start_verification_options_method_with_opts assert_equal opts[:code_length], verification_opts.code_length end + def test_cancel_verification_request_method + stub_request(:delete, cancel_request_uri).to_return(status: 204, headers: {}) + + assert_kind_of Vonage::Response, verify2.cancel_verification_request(request_id: request_id) + end + + def test_cancel_verification_request_method_without_request_id + assert_raises ArgumentError do + verify2.cancel_verification_request + end + end + def test_workflow_method assert_instance_of Vonage::Verify2::Workflow, verify2.workflow end From 99b32935277e9db0f10d4f1096ff477c2c207c96 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 12:54:19 +0900 Subject: [PATCH 27/35] DEVX-7298: implementing cancel verification method --- lib/vonage/verify2.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index cd3b66f3..eff908c8 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -51,6 +51,19 @@ def check_code(request_id:, code:) request('/v2/verify/' + request_id, params: {code: code}, type: Post) end + # Cancel a verifiction. If a verification request is still active, calling this method aborts the workflow. + # + # @example + # verify.cancel_verification_request(request_id: '7e8c5965-0a3f-44df-8a14-f1486209d8a2') + # + # @param [required, String] :request_id The request_id of the verification request to be cancelled + # + # @see https://developer.vonage.com/en/api/verify.v2#cancelRequest + # + def cancel_verification_request(request_id:) + request('/v2/verify/' + request_id, type: Delete) + end + # Instantiate a new Vonage::Verify2::StartVerificationOptions object # # @param [optional, Hash] opts the options for the verification request. From 9eb768f292a9f0994e9d5f4ef2de99cb6a75da09 Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 14:47:41 +0900 Subject: [PATCH 28/35] DEVX-7205: adding tests for BYOP functionality --- .../vonage/verify2/start_verification_options_test.rb | 11 +++++++++++ test/vonage/verify2_test.rb | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/vonage/verify2/start_verification_options_test.rb b/test/vonage/verify2/start_verification_options_test.rb index 9b8bceb3..057a8e6c 100644 --- a/test/vonage/verify2/start_verification_options_test.rb +++ b/test/vonage/verify2/start_verification_options_test.rb @@ -71,6 +71,17 @@ def test_code_length_setter_method_with_invalid_arg end end + def test_code_getter_method + assert_nil options.code + end + + def test_code_setter_method + opts = options + opts.code = 'abc123' + + assert_equal 'abc123', opts.instance_variable_get(:@code) + end + def test_to_h_method opts_hash = Vonage::Verify2::StartVerificationOptions.new( locale: 'en-gb', diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index 2d1d8109..46793e29 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -120,7 +120,8 @@ def test_start_verification_options_method_with_opts locale: 'en-gb', channel_timeout: 300, client_ref: 'foo', - code_length: 6 + code_length: 6, + code: 'abc123' } verification_opts = verify2.start_verification_options(**opts) @@ -130,6 +131,7 @@ def test_start_verification_options_method_with_opts assert_equal opts[:channel_timeout], verification_opts.channel_timeout assert_equal opts[:client_ref], verification_opts.client_ref assert_equal opts[:code_length], verification_opts.code_length + assert_equal opts[:code], verification_opts.code end def test_cancel_verification_request_method From 4179e12e705ccbae88b01dd2d67b9a138c67321f Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 15:01:47 +0900 Subject: [PATCH 29/35] DEVX-7205: Implementing BYOP functionality --- lib/vonage/verify2.rb | 2 ++ lib/vonage/verify2/start_verification_options.rb | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index eff908c8..d2c4f0bf 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -22,6 +22,7 @@ class Verify2 < Namespace # # @param [optional, Hash] opts the options for the verification request. # @option opts [Integer] :code_length The length of the one-time code provided to the end-user + # @option opts [String] :code An optional alphanumeric custom code to use instead of an auto-generated code # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks @@ -68,6 +69,7 @@ def cancel_verification_request(request_id:) # # @param [optional, Hash] opts the options for the verification request. # @option opts [Integer] :code_length The length of the one-time code provided to the end-user + # @option opts [String] :code An optional alphanumeric custom code to use instead of an auto-generated code # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks diff --git a/lib/vonage/verify2/start_verification_options.rb b/lib/vonage/verify2/start_verification_options.rb index 477956d5..daa226e4 100644 --- a/lib/vonage/verify2/start_verification_options.rb +++ b/lib/vonage/verify2/start_verification_options.rb @@ -3,7 +3,7 @@ module Vonage class Verify2::StartVerificationOptions - VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length].freeze + VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length, :code].freeze VALID_LOCALES = [ 'en-us', 'en-gb', 'es-es', 'es-mx', 'es-us', 'it-it', 'fr-fr', @@ -50,6 +50,10 @@ def code_length=(code_length) @code_length = code_length end + def code=(code) + @code = code + end + def to_h hash = Hash.new self.instance_variables.each do |ivar| From e963d97e7c4d180bfdf4a0180121e258d42676fb Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 15:31:35 +0900 Subject: [PATCH 30/35] DEVX-7199: Adding tests for fraud check functionality --- .../verify2/start_verification_options_test.rb | 18 ++++++++++++++++++ test/vonage/verify2_test.rb | 4 +++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/test/vonage/verify2/start_verification_options_test.rb b/test/vonage/verify2/start_verification_options_test.rb index 057a8e6c..de213d34 100644 --- a/test/vonage/verify2/start_verification_options_test.rb +++ b/test/vonage/verify2/start_verification_options_test.rb @@ -82,6 +82,24 @@ def test_code_setter_method assert_equal 'abc123', opts.instance_variable_get(:@code) end + def test_fraud_check_getter_method + assert_nil options.fraud_check + end + + def test_fraud_check_setter_method + opts = options + opts.fraud_check = false + + assert_equal false, opts.instance_variable_get(:@fraud_check) + end + + def test_fraud_check_setter_method_with_invalid_arg + opts = options + assert_raises ArgumentError do + opts.fraud_check = 'no' + end + end + def test_to_h_method opts_hash = Vonage::Verify2::StartVerificationOptions.new( locale: 'en-gb', diff --git a/test/vonage/verify2_test.rb b/test/vonage/verify2_test.rb index 46793e29..ed738c01 100644 --- a/test/vonage/verify2_test.rb +++ b/test/vonage/verify2_test.rb @@ -121,7 +121,8 @@ def test_start_verification_options_method_with_opts channel_timeout: 300, client_ref: 'foo', code_length: 6, - code: 'abc123' + code: 'abc123', + fraud_check: false } verification_opts = verify2.start_verification_options(**opts) @@ -132,6 +133,7 @@ def test_start_verification_options_method_with_opts assert_equal opts[:client_ref], verification_opts.client_ref assert_equal opts[:code_length], verification_opts.code_length assert_equal opts[:code], verification_opts.code + assert_equal opts[:fraud_check], verification_opts.fraud_check end def test_cancel_verification_request_method From a2e9e26d394002ba9a65ccd43b1ca0a9022d935a Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 15:42:35 +0900 Subject: [PATCH 31/35] DEVX-7199: implementing fraud check functionality --- lib/vonage/verify2.rb | 2 ++ lib/vonage/verify2/start_verification_options.rb | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index d2c4f0bf..994277a4 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -26,6 +26,7 @@ class Verify2 < Namespace # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks + # @option opts [Boolean] When set to `false` will bypass a network block for a single Verify V2 request # # @return Vomage::Response # @see https://developer.vonage.com/en/api/verify.v2#newRequest @@ -73,6 +74,7 @@ def cancel_verification_request(request_id:) # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks + # @option opts [Boolean] When set to `false` will bypass a network block for a single Verify V2 request # def start_verification_options(**opts) StartVerificationOptions.new(**opts) diff --git a/lib/vonage/verify2/start_verification_options.rb b/lib/vonage/verify2/start_verification_options.rb index daa226e4..ce9e0944 100644 --- a/lib/vonage/verify2/start_verification_options.rb +++ b/lib/vonage/verify2/start_verification_options.rb @@ -3,7 +3,7 @@ module Vonage class Verify2::StartVerificationOptions - VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length, :code].freeze + VALID_OPTS = [:locale, :channel_timeout, :client_ref, :code_length, :code, :fraud_check].freeze VALID_LOCALES = [ 'en-us', 'en-gb', 'es-es', 'es-mx', 'es-us', 'it-it', 'fr-fr', @@ -54,6 +54,12 @@ def code=(code) @code = code end + def fraud_check=(fraud_check) + raise ArgumentError, "Invalid 'fraud_check' #{fraud_check}. Must be `true` or `false`" unless [true, false].include? fraud_check + + @fraud_check = fraud_check + end + def to_h hash = Hash.new self.instance_variables.each do |ivar| From d246801c0f4ddcb83faad620ce9e702cf4333deb Mon Sep 17 00:00:00 2001 From: superchilled Date: Mon, 22 May 2023 18:51:24 +0900 Subject: [PATCH 32/35] DEVX-7199: constraining fraud_check to false --- lib/vonage/verify2.rb | 4 ++-- lib/vonage/verify2/start_verification_options.rb | 2 +- test/vonage/verify2/start_verification_options_test.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vonage/verify2.rb b/lib/vonage/verify2.rb index 994277a4..3f96e8de 100644 --- a/lib/vonage/verify2.rb +++ b/lib/vonage/verify2.rb @@ -26,7 +26,7 @@ class Verify2 < Namespace # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks - # @option opts [Boolean] When set to `false` will bypass a network block for a single Verify V2 request + # @option opts [Boolean] If used, must be set to `false`. Will bypass a network block for a single Verify V2 request # # @return Vomage::Response # @see https://developer.vonage.com/en/api/verify.v2#newRequest @@ -74,7 +74,7 @@ def cancel_verification_request(request_id:) # @option opts [String] :locale The language to use for the verification message (where applicable) # @option opts [Integer] :channel_timeout Wait time in seconds before trying the next channel in the workflow # @option opts [String] :client_ref Reference to be included in callbacks - # @option opts [Boolean] When set to `false` will bypass a network block for a single Verify V2 request + # @option opts [Boolean] If used, must be set to `false`. Will bypass a network block for a single Verify V2 request # def start_verification_options(**opts) StartVerificationOptions.new(**opts) diff --git a/lib/vonage/verify2/start_verification_options.rb b/lib/vonage/verify2/start_verification_options.rb index ce9e0944..1212673f 100644 --- a/lib/vonage/verify2/start_verification_options.rb +++ b/lib/vonage/verify2/start_verification_options.rb @@ -55,7 +55,7 @@ def code=(code) end def fraud_check=(fraud_check) - raise ArgumentError, "Invalid 'fraud_check' #{fraud_check}. Must be `true` or `false`" unless [true, false].include? fraud_check + raise ArgumentError, "Invalid 'fraud_check' #{fraud_check}. Must be `false`" unless fraud_check == false @fraud_check = fraud_check end diff --git a/test/vonage/verify2/start_verification_options_test.rb b/test/vonage/verify2/start_verification_options_test.rb index de213d34..c71cf022 100644 --- a/test/vonage/verify2/start_verification_options_test.rb +++ b/test/vonage/verify2/start_verification_options_test.rb @@ -96,7 +96,7 @@ def test_fraud_check_setter_method def test_fraud_check_setter_method_with_invalid_arg opts = options assert_raises ArgumentError do - opts.fraud_check = 'no' + opts.fraud_check = true end end From d989a61b85092be9566b9eafd7a3b886efb8dca6 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 26 May 2023 12:08:21 +0100 Subject: [PATCH 33/35] Adding cancel_verification_request to README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 2721dbe4..949bf124 100644 --- a/README.md +++ b/README.md @@ -315,6 +315,17 @@ workflow_list = workflow.hashified_list verification_request = verify.start_verification(brand: 'Acme', workflow: workflow_list) ``` +### Cancelling a request + +You can cancel in in-progress verification request + +```ruby +# Get the `request_id` from the Vonage#Response object returned by the `start_verification` method call +request_id = verification_request.request_id + +verify.cancel_verification_request(request_id: request_id) +``` + ### Checking a code ```ruby From c1f8d2d5b23ac7b14dbd6ae6e3d79d550ec523fc Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 26 May 2023 16:33:17 +0100 Subject: [PATCH 34/35] Updating changelog --- CHANGES.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 58a6ac94..a17ec5db 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,11 @@ +# 7.10.0 + +* Adds Verify2. [#261](https://github.com/Vonage/vonage-ruby-sdk/pull/261) +* Fixes link in README. [#266](https://github.com/Vonage/vonage-ruby-sdk/pull/266) + # 7.9.0 -* Updates the Messages API implementation to ass support for `video` and `file` messages types to the Viber channel, and `sticker` messages in the WhatsApp channel. [#260](https://github.com/Vonage/vonage-ruby-sdk/pull/260) +* Updates the Messages API implementation to add support for `video` and `file` messages types to the Viber channel, and `sticker` messages in the WhatsApp channel. [#260](https://github.com/Vonage/vonage-ruby-sdk/pull/260) * Updates the Numbers API implementation to use Basic authentication. [#262](https://github.com/Vonage/vonage-ruby-sdk/pull/262) # 7.8.2 From 70d6da6925a87d47553711c6f7158b68a1f52f12 Mon Sep 17 00:00:00 2001 From: superchilled Date: Fri, 26 May 2023 16:33:25 +0100 Subject: [PATCH 35/35] 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 c34e68f7..6b047c81 100644 --- a/lib/vonage/version.rb +++ b/lib/vonage/version.rb @@ -1,5 +1,5 @@ # typed: strong module Vonage - VERSION = "7.9.0" + VERSION = "7.10.0" end