-
Notifications
You must be signed in to change notification settings - Fork 78
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 #233 from plivo/VT-6714
verify called id apis added
- Loading branch information
Showing
11 changed files
with
226 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
module Plivo | ||
module Resources | ||
include Plivo::Utils | ||
class Verify < Base::Resource | ||
def initialize(client, options = nil) | ||
@_name = 'Verify' | ||
@_identifier_string = 'api_id' | ||
super | ||
end | ||
def to_s | ||
{ | ||
api_id: @api_id, | ||
alias: @alias, | ||
country: @country, | ||
created_at: @created_at, | ||
modified_at: @modified_at, | ||
phone_number: @phone_number, | ||
subaccount: @subaccount, | ||
verification_uuid: @verification_uuid | ||
}.to_s | ||
end | ||
end | ||
|
||
class VerifyCallerIdInterface < Base::ResourceInterface | ||
def initialize(client, resource_list_json = nil) | ||
@_name = 'VerifiedCallerId' | ||
@_resource_type = Verify | ||
@_identifier_string = 'api_id' | ||
super | ||
end | ||
|
||
def initiate(phone_number = nil, channel = nil, alias_ = nil, subaccount = nil) | ||
valid_param?(:phone_number, phone_number, [String], true) | ||
valid_param?(:channel, channel, [String], false) | ||
valid_param?(:alias, alias_, [String], false) | ||
valid_param?(:subaccount, subaccount, [String], false) | ||
|
||
params = { | ||
phone_number: phone_number, | ||
channel: channel, | ||
alias: alias_, | ||
subaccount: subaccount | ||
} | ||
perform_create(params) | ||
end | ||
|
||
def verify(verification_uuid = nil, otp = nil) | ||
valid_param?(:verification_uuid, verification_uuid, [String], true) | ||
valid_param?(:otp, otp, [String], true) | ||
id = 'Verification/' + verification_uuid | ||
params = { | ||
otp: otp | ||
} | ||
perform_action_with_identifier(id, 'POST', params) | ||
end | ||
|
||
def update(phone_number = nil, subaccount = nil, alias_ = nil) | ||
valid_param?(:phone_number, phone_number, [String], true) | ||
valid_param?(:subaccount, subaccount, [String], false) | ||
valid_param?(:alias, alias_, [String], false) | ||
params = { | ||
subaccount: subaccount, | ||
alias: alias_ | ||
} | ||
perform_action_with_identifier(phone_number, 'POST', params) | ||
end | ||
|
||
def get(phone_number = nil) | ||
valid_param?(:phone_number, phone_number, [String], true) | ||
perform_get(phone_number) | ||
end | ||
|
||
def list(options = nil) | ||
return perform_list_without_object if options.nil? | ||
valid_param?(:options, options, Hash, false) | ||
|
||
params = {} | ||
params_expected = %i[subaccount country alias] | ||
|
||
params_expected.each do |param| | ||
if options.key?(param) && | ||
valid_param?(param, options[param], [String, Symbol], false) | ||
params[param] = options[param] | ||
end | ||
end | ||
|
||
%i[offset limit].each do |param| | ||
if options.key?(param) && | ||
valid_param?(param, options[param], [Integer, Integer], false) | ||
params[param] = options[param] | ||
end | ||
end | ||
|
||
if options.key?(:limit) && | ||
(options[:limit] > 20 || options[:limit] <= 0) | ||
raise_invalid_request('The maximum number of results that can be '\ | ||
"fetched is 20. limit can't be more than 20 or less than 1") | ||
end | ||
|
||
raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0 | ||
|
||
perform_list_without_object(params) | ||
end | ||
|
||
def delete(phone_number) | ||
perform_delete(phone_number, nil) | ||
end | ||
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Plivo | ||
VERSION = "4.53.1".freeze | ||
VERSION = "4.54.0".freeze | ||
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,10 @@ | ||
{ | ||
"alias": "test", | ||
"api_id": "35c999a4-f1ad-4af7-9cc6-c8ccac7fd283", | ||
"country": "US", | ||
"created_at": "2023-10-13T11:46:58.334899Z", | ||
"modified_at": "2023-10-13T11:46:58.334899Z", | ||
"phone_number": "+919999999999", | ||
"subaccount": "", | ||
"verification_uuid": "605c75f2-02b6-4cb8-883d-69cf37b21e5a" | ||
} |
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,5 @@ | ||
{ | ||
"api_id": "b1e04bbb-9cb3-435e-946a-aea5e4f4709e", | ||
"message": "Verification code is sent to number +919999999999 which is valid for 15 minutes", | ||
"verification_uuid": "74df1f8f-056d-4c9c-8fc5-11615fbb23a0" | ||
} |
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,22 @@ | ||
{ | ||
"api_id": "5449144c-ff78-4da3-b6a2-9b22abdb7bd4", | ||
"meta": { | ||
"limit": 20, | ||
"next": null, | ||
"offset": 0, | ||
"previous": null, | ||
"total_count": 1 | ||
}, | ||
"objects": [ | ||
{ | ||
"alias": "test", | ||
"country": "IN", | ||
"created_at": "2023-09-26T07:58:10.345732Z", | ||
"modified_at": "2023-09-26T07:58:10.345732Z", | ||
"phone_number": "+919999999999", | ||
"resource_uri": "/v1/Account/authID/VerifiedCallerId/919999999999", | ||
"subaccount": "subaccount", | ||
"verification_uuid": "30fe8cc9-be93-4315-afa8-7fe26d05bb01" | ||
} | ||
] | ||
} |
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,9 @@ | ||
{ | ||
"alias": "QA Test", | ||
"api_id": "910cc1e1-c5fc-4f58-b9de-aa30e1cfd241", | ||
"channel": "call", | ||
"country": "US", | ||
"created_at": "2023-10-13T11:46:58.334898885Z", | ||
"phone_number": "+919999999999", | ||
"verification_uuid": "605c75f2-02b6-4cb8-883d-69cf37b21e5a" | ||
} |
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,62 @@ | ||
require 'rspec' | ||
require 'json' | ||
require_relative 'spec_helper' | ||
|
||
describe 'Verify test' do | ||
|
||
def to_json_initate(verify) | ||
{ | ||
message: verify.message, | ||
verification_uuid: verify.verification_uuid, | ||
api_id: verify.api_id | ||
}.to_json | ||
end | ||
|
||
def to_json_verify(verify) | ||
{ | ||
api_id: verify.api_id, | ||
alias: verify.alias, | ||
channel: verify.channel, | ||
country: verify.country, | ||
created_at: verify.created_at, | ||
phone_number: verify.phone_number, | ||
verification_uuid: verify.verification_uuid, | ||
}.to_json | ||
end | ||
|
||
|
||
|
||
it 'initiates verification of a caller id' do | ||
contents = File.read(Dir.pwd + '/spec/mocks/initiateVerifyResponse.json') | ||
mock(200, JSON.parse(contents)) | ||
expect(JSON.parse(to_json_initate(@api.verify_caller_id | ||
.initiate("919999999999", nil, nil, nil | ||
)))) | ||
.to eql(JSON.parse(contents)) | ||
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/VerifiedCallerId/', | ||
method: 'POST', | ||
data: { | ||
phone_number: '919999999999', | ||
channel: nil, | ||
alias: nil, | ||
subaccount: nil | ||
}) | ||
end | ||
|
||
it 'verifies a caller id' do | ||
contents = File.read(Dir.pwd + '/spec/mocks/verifyCallerIdResponse.json') | ||
mock(200, JSON.parse(contents)) | ||
expect(JSON.parse(to_json_verify(@api.verify_caller_id | ||
.verify("test-uuid", "123456" | ||
)))) | ||
.to eql(JSON.parse(contents)) | ||
compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/VerifiedCallerId/Verification/test-uuid/', | ||
method: 'POST', | ||
data: { | ||
otp: '123456', | ||
}) | ||
end | ||
|
||
|
||
|
||
end |