-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from Vonage/dev
Release 7.10.0
- Loading branch information
Showing
27 changed files
with
1,241 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# 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. | ||
# | ||
# @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<Hash>] :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] :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 | ||
# @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 | ||
# | ||
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? | ||
|
||
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. | ||
# | ||
# @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:) | ||
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. | ||
# @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 | ||
# @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) | ||
end | ||
|
||
# Instantiate a new Vonage::Verify2::Workflow object | ||
def workflow | ||
Workflow.new | ||
end | ||
|
||
# Return the Vonage::Verify2::WorkflowBuilder class | ||
def workflow_builder | ||
WorkflowBuilder.itself | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
require 'phonelib' | ||
|
||
module Vonage | ||
class Verify2::Channels::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
require 'phonelib' | ||
|
||
module Vonage | ||
class Verify2::Channels::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# typed: true | ||
# frozen_string_literal: true | ||
require 'phonelib' | ||
|
||
module Vonage | ||
class Verify2::Channels::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 |
Oops, something went wrong.