Skip to content

Commit

Permalink
Merge pull request #226 from plivo/SMS-6236
Browse files Browse the repository at this point in the history
SMS-6236: Verify Service SDK
  • Loading branch information
narayana-plivo authored Nov 8, 2023
2 parents ac9a26d + e6970da commit 5477cc2
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log


## [4.53.0](https://github.com/plivo/plivo-ruby/tree/v4.53.0) (2023-11-08)
**Feature - Verify Service**
-Added Support for Verify Service Public API'S
-Create Session API(POST): To create a verify session (2FA). Allowed params recipient, method, channel, callback_url, app_uuid
-Get Session API(GET): To retrieve a particular session
-List Sessions : To retrieve all the sessions
-Validate Session : To validate OTP for a particular session

## [4.52.0](https://github.com/plivo/plivo-ruby/tree/v4.52.0) (2023-11-08)
**[BETA] Feature - TollFree Verification API Support**
- API support for Create, Update, Get, Delete, and List Tollfree Verification.
Expand All @@ -23,6 +32,7 @@
**Feature - Added New Param 'carrier_fees', 'carrier_fees_rate', 'destination_network' in Get Message and List Message APIs**
- Added new params on message get and list response


## [4.47.0](https://github.com/plivo/plivo-ruby/tree/v4.47.0) (2023-08-03)
**Feature - DLT parameters**
- Added new params `DLTEntityID`, `DLTTemplateID`, `DLTTemplateCategory` to the [send message API](https://www.plivo.com/docs/sms/api/message/send-a-message/)
Expand Down
4 changes: 2 additions & 2 deletions 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.52.0'
gem 'plivo', '>= 4.53.0'
```

And then execute:
Expand Down Expand Up @@ -197,4 +197,4 @@ export PLIVO_API_PROD_HOST=<plivoapi_public_endpoint>
(The docker container should be running)

> Test code and unit tests can also be run within the container using
`make run` and `make test` respectively. (`CONTAINER` argument should be omitted when running from the container)
`make run` and `make test` respectively. (`CONTAINER` argument should be omitted when running from the container)
2 changes: 1 addition & 1 deletion lib/plivo/base/resource_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def perform_list(params = nil)
objects: @_resource_list
}
end

def perform_action(action = nil, method = 'GET', params = nil, parse = false)
resource_path = action ? @_resource_uri + action + '/' : @_resource_uri
response = @_client.send_request(resource_path, method, params, nil, false, is_voice_request: @_is_voice_request)
Expand Down
1 change: 1 addition & 0 deletions lib/plivo/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
require_relative 'resources/lookup'
require_relative 'resources/regulatory_compliance'
require_relative 'resources/multipartycalls'
require_relative 'resources/verify_session'
require_relative 'resources/tollfree_verification'

module Plivo
Expand Down
106 changes: 106 additions & 0 deletions lib/plivo/resources/verify_session.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
module Plivo
module Resources
include Plivo::Utils
class Session < Base::Resource
def initialize(client, options = nil)
@_name = 'Session'
@_identifier_string = 'session_uuid'
super
end
def to_s
{
api_id: @api_id,
session_uuid: @session_uuid,
app_uuid: @app_uuid,
alias: @alias,
recipient: @recipient,
channel: @channel,
status: @status,
count: @count,
requestor_ip: @requestor_ip,
destination_country_iso2: @destination_country_iso2,
destination_network: @destination_network,
attempt_details: @attempt_details,
charges: @charges,
created_at: @created_at,
updated_at: @updated_at
}.to_s
end
end

class SessionInterface < Base::ResourceInterface
def initialize(client, resource_list_json = nil)
@_name = 'Verify/Session'
@_resource_type = Session
@_identifier_string = 'session_uuid'
super
end

# @param [String] session_uuid
def get(session_uuid)
perform_get(session_uuid)
end

def create(app_uuid = nil, recipient = nil,channel = nil,url = nil, method = nil)
valid_param?(:app_uuid, app_uuid, [String, Symbol], false)
valid_param?(:recipient, recipient, [Integer, String, Symbol], true)
valid_param?(:channel, channel, [String, Symbol], false)
valid_param?(:url, url, [String], false)
valid_param?(:method, method, String, false, %w[POST GET])

params = {
app_uuid: app_uuid,
recipient: recipient,
channel: channel,
url: url,
method: method
}
perform_create(params)
end

def list(options = nil)
return perform_list if options.nil?
valid_param?(:options, options, Hash, true)
params = {}
params_expected = %i[
subaccount status session_time__gt session_time__gte
session_time__lt session_time__lte session_time country alias app_uuid recipient
]

params_expected.each do |param|
if options.key?(param) &&
valid_param?(param, options[param], [String, Symbol], true)
params[param] = options[param]
end
end

%i[offset limit].each do |param|
if options.key?(param) &&
valid_param?(param, options[param], [Integer, Integer], true)
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 validate(session_uuid = nil, otp = nil)
valid_param?(:session_uuid, session_uuid, [String, Symbol], true)
valid_param?(:otp, otp, [String], true)
id = session_uuid
params = {
otp: otp
}
perform_action_with_identifier(id, 'POST', params)
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 @@ -18,6 +18,7 @@ class RestClient < BaseClient
attr_reader :brand, :campaign, :profile
attr_reader :end_users
attr_reader :compliance_document_types, :compliance_documents, :compliance_requirements, :compliance_applications
attr_reader :verify_session
attr_reader :tollfree_verifications

def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5)
Expand Down Expand Up @@ -65,6 +66,7 @@ def configure_interfaces
@compliance_documents = Resources::ComplianceDocumentsInterface.new(self)
@compliance_requirements = Resources::ComplianceRequirementsInterface.new(self)
@compliance_applications = Resources::ComplianceApplicationsInterface.new(self)
@verify_session = Resources::SessionInterface.new(self)
@tollfree_verifications = Resources::TollfreeVerificationsInterface.new(self)
end
end
Expand Down
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.52.0".freeze
VERSION = "4.53.0".freeze
end
34 changes: 34 additions & 0 deletions spec/mocks/sessionGetResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"api_id": "affc3af1-3ee3-4d8e-a577-317fabd4944e",
"session_uuid": "118a0352-6818-4cc4-99b4-635647730091",
"app_uuid": "bd772d6d-7882-4e77-b2b1-d84c7f73713a",
"alias": "verify_app_210",
"recipient": "1234567890",
"channel": "sms",
"status": "expired",
"count": 1,
"requestor_ip": "122.163.227.219",
"destination_country_iso2": "IN",
"destination_network": "Jio",
"attempt_details": [
{
"channel": "sms",
"attempt_uuid": "d67d0b98-4646-4c5e-b76a-7afe29435a02",
"status": "failed",
"time": "2023-08-21T14:32:40.436767+05:30"
}
],
"charges": {
"total_charge": "0.00000",
"validation_charge": "0.0000",
"attempt_charges": [
{
"attempt_uuid": "d67d0b98-4646-4c5e-b76a-7afe29435a02",
"channel": "sms",
"charge": "0.00000"
}
]
},
"created_at": "2023-08-21T14:32:40.42576+05:30",
"updated_at": "2023-08-21T14:32:40.436767+05:30"
}
44 changes: 44 additions & 0 deletions spec/mocks/sessionListResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"api_id": "0a80fbe1-e2d6-46fd-abf5-885fba1a22fd",
"meta": {
"limit": 1,
"offset": 0,
"next": "/v1/Account/MAODZKMDFJMJU3MTEYNG/Verify/Session/?limit=1&offset=1",
"previous": null
},
"sessions": [
{
"session_uuid": "2879cb3a-3742-4c41-adb6-2d0de6297652",
"app_uuid": "f34e00c4-fdca-4675-bfad-6096553ef33f",
"alias": "default_verify_app",
"recipient": "1234567890",
"channel": "sms",
"status": "expired",
"count": 1,
"requestor_ip": "223.236.171.206",
"destination_country_iso2": "IN",
"destination_network": "Jio",
"attempt_details": [
{
"channel": "sms",
"attempt_uuid": "29e48f18-42e1-4ad2-b28d-ed93a4fbd3a1",
"status": "failed",
"time": "2023-08-25T13:00:45.281324+05:30"
}
],
"charges": {
"total_charge": "0.00000",
"validation_charge": "0.0000",
"attempt_charges": [
{
"attempt_uuid": "29e48f18-42e1-4ad2-b28d-ed93a4fbd3a1",
"channel": "sms",
"charge": "0.00000"
}
]
},
"created_at": "2023-08-25T13:00:45.266046+05:30",
"updated_at": "2023-08-25T13:00:45.281324+05:30"
}
]
}
5 changes: 5 additions & 0 deletions spec/mocks/sessionSendResponse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"api_id": "bbeb49e9-8e71-47ac-9701-86455c702138",
"message": "Session initiated",
"session_uuid": "201c62fb-22bb-41da-90b6-e4be2a157299"
}
Loading

0 comments on commit 5477cc2

Please sign in to comment.