Skip to content

Commit

Permalink
Merge pull request #233 from plivo/VT-6714
Browse files Browse the repository at this point in the history
verify called id apis added
  • Loading branch information
abhishekGupta-Plivo authored Nov 22, 2023
2 parents 3375fb1 + 866d208 commit 3f52a55
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## [4.54.0](https://github.com/plivo/plivo-ruby/tree/v4.54.0) (2023-11-17)
**Feature - Verify Caller Id API support**
- API support for verifying, updating, getting and deleting caller IDs.

## [4.53.1](https://github.com/plivo/plivo-ruby/tree/v4.53.1) (2023-11-09)
**Feature - Verify Service**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
Add this line to your application's Gemfile:

```ruby
gem 'plivo', '>= 4.53.1'
gem 'plivo', '>= 4.54.1'
```

And then execute:
Expand Down
1 change: 1 addition & 0 deletions lib/plivo/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require_relative 'resources/multipartycalls'
require_relative 'resources/verify_session'
require_relative 'resources/tollfree_verification'
require_relative 'resources/verify_caller_id'

module Plivo
module Resources
Expand Down
110 changes: 110 additions & 0 deletions lib/plivo/resources/verify_caller_id.rb
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
2 changes: 2 additions & 0 deletions lib/plivo/rest_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RestClient < BaseClient
attr_reader :compliance_document_types, :compliance_documents, :compliance_requirements, :compliance_applications
attr_reader :verify_session
attr_reader :tollfree_verifications
attr_reader :verify_caller_id

def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5)
configure_base_uri
Expand Down Expand Up @@ -68,6 +69,7 @@ def configure_interfaces
@compliance_applications = Resources::ComplianceApplicationsInterface.new(self)
@verify_session = Resources::SessionInterface.new(self)
@tollfree_verifications = Resources::TollfreeVerificationsInterface.new(self)
@verify_caller_id = Resources::VerifyCallerIdInterface.new(self)
end
end
end
2 changes: 1 addition & 1 deletion lib/plivo/version.rb
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
10 changes: 10 additions & 0 deletions spec/mocks/getVerifiedCallerIdResponse.json
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"
}
5 changes: 5 additions & 0 deletions spec/mocks/initiateVerifyResponse.json
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"
}
22 changes: 22 additions & 0 deletions spec/mocks/listVerifiedCallerIdResponse.json
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"
}
]
}
9 changes: 9 additions & 0 deletions spec/mocks/verifyCallerIdResponse.json
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"
}
62 changes: 62 additions & 0 deletions spec/resource_verify_caller_id_spec.rb
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

0 comments on commit 3f52a55

Please sign in to comment.