From ac9a26d60d581d0c36f666197d696b9483004ab0 Mon Sep 17 00:00:00 2001 From: abheet-plivo <83641147+abheet-plivo@users.noreply.github.com> Date: Wed, 8 Nov 2023 13:45:35 +0530 Subject: [PATCH] ruby fix (#230) * ruby fix * fix * fix * addded UTCs * added UTCs * added UTCs * filters applied * filters applied * filters applied * bump version * corrected url * correcte the example file --------- Co-authored-by: kalyan-plivo --- CHANGELOG.md | 6 + README.md | 2 +- examples/tollfree_verification.rb | 42 +++++ lib/plivo/resources.rb | 1 + lib/plivo/resources/numbers.rb | 12 +- lib/plivo/resources/tollfree_verification.rb | 178 ++++++++++++++++++ lib/plivo/rest_client.rb | 2 + lib/plivo/version.rb | 2 +- spec/mocks/numberGetResponse.json | 4 +- spec/mocks/numberListResponse.json | 12 +- .../tollfreeVerificationCreateResponse.json | 5 + .../tollfreeVerificationListResponse.json | 50 +++++ .../tollfreeVerificationUpdateResponse.json | 4 + .../tollfreeverificationGetResponse.json | 19 ++ spec/resource_numbers_spec.rb | 4 +- spec/resource_tollfree_verification_spec.rb | 74 ++++++++ 16 files changed, 407 insertions(+), 10 deletions(-) create mode 100644 examples/tollfree_verification.rb create mode 100644 lib/plivo/resources/tollfree_verification.rb create mode 100644 spec/mocks/tollfreeVerificationCreateResponse.json create mode 100644 spec/mocks/tollfreeVerificationListResponse.json create mode 100644 spec/mocks/tollfreeVerificationUpdateResponse.json create mode 100644 spec/mocks/tollfreeverificationGetResponse.json create mode 100644 spec/resource_tollfree_verification_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 71891159..fe804aeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## [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. +- Added New Param `toll_free_sms_verification_id` and `toll_free_sms_verification_order_status` in to the response of the [list all numbers API], [list single number API] +- Added `toll_free_sms_verification_order_status` filter to AccountPhoneNumber - list all my numbers API. + ## [4.51.0](https://github.com/plivo/plivo-ruby/tree/v4.51.0) (2023-10-16) **Introducing campaign_source & import partner camapign API** - New field campaign_source introduced diff --git a/README.md b/README.md index 9a401558..a8e001a3 100644 --- a/README.md +++ b/README.md @@ -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.51.0' +gem 'plivo', '>= 4.52.0' ``` And then execute: diff --git a/examples/tollfree_verification.rb b/examples/tollfree_verification.rb new file mode 100644 index 00000000..41ef8368 --- /dev/null +++ b/examples/tollfree_verification.rb @@ -0,0 +1,42 @@ +require 'rubygems' +require "plivo" + +include Plivo +include Plivo::Exceptions + +AUTH_ID = 'AUTH_ID' +AUTH_TOKEN = 'AUTH_TOKEN' + +api = RestClient.new(AUTH_ID, AUTH_TOKEN) + +begin + response = api.tollfree_verifications.get('uuid') + puts response +rescue PlivoRESTError => e + puts 'Exception: ' + e.message +end + + +begin + response = api.tollfree_verifications.create('18773582986', '2FA', 'dasas', + 'd5a9c4d4-d086-42db-940f-e798d480d064', 'VERBAL', 'https://www.aa.com,http://google.com', + '100', 'qwqwq') + puts response +rescue PlivoRESTError => e + puts 'Exception: ' + e.message +end + +begin +response = api.tollfree_verifications.update('uuid', usecase: '2FA') + puts response +rescue PlivoRESTError => e + puts 'Exception: ' + e.message +end + + +begin +response = api.tollfree_verifications.delete('uuid') + puts response +rescue PlivoRESTError => e + puts 'Exception: ' + e.message +end diff --git a/lib/plivo/resources.rb b/lib/plivo/resources.rb index f6b3622a..0f8f1ad9 100644 --- a/lib/plivo/resources.rb +++ b/lib/plivo/resources.rb @@ -22,6 +22,7 @@ require_relative 'resources/lookup' require_relative 'resources/regulatory_compliance' require_relative 'resources/multipartycalls' +require_relative 'resources/tollfree_verification' module Plivo module Resources diff --git a/lib/plivo/resources/numbers.rb b/lib/plivo/resources/numbers.rb index 076b34bb..2769a492 100644 --- a/lib/plivo/resources/numbers.rb +++ b/lib/plivo/resources/numbers.rb @@ -37,7 +37,9 @@ def to_s voice_rate: @voice_rate, tendlc_campaign_id: @tendlc_campaign_id, tendlc_registration_status: @tendlc_registration_status, - toll_free_sms_verification: @toll_free_sms_verification + toll_free_sms_verification: @toll_free_sms_verification, + toll_free_sms_verification_id: @toll_free_sms_verification_id, + toll_free_sms_verification_order_status: @toll_free_sms_verification_order_status }.to_s end end @@ -185,7 +187,9 @@ def to_s tendlc_registration_status: @tendlc_registration_status, toll_free_sms_verification: @toll_free_sms_verification, renewal_date: @renewal_date, - cnam_lookup: @cnam_lookup + cnam_lookup: @cnam_lookup, + toll_free_sms_verification_id: @toll_free_sms_verification_id, + toll_free_sms_verification_order_status: @toll_free_sms_verification_order_status }.to_s end end @@ -231,6 +235,8 @@ def get(number) # @option options [String] :cnam_lookup The Cnam Lookup Configuration associated with that number. The following values are valid: # - enabled - Returns the list of numbers for which Cnam Lookup configuration is enabled # - disabled - Returns the list of numbers for which Cnam Lookup configuration is disabled + # @option options [String] :toll_free_sms_verification_id The id of tollfree verification that the number is currently linked with. + # @option options [String] :toll_free_sms_verification_order_status Indicates the tollfree verification status of a number. def list(options = nil) return perform_list if options.nil? @@ -238,7 +244,7 @@ def list(options = nil) params = {} - %i[number_startswith subaccount alias tendlc_campaign_id tendlc_registration_status toll_free_sms_verification renewal_date renewal_date__lt renewal_date__lte renewal_date__gt renewal_date__gte cnam_lookup].each do |param| + %i[number_startswith subaccount alias tendlc_campaign_id tendlc_registration_status toll_free_sms_verification renewal_date renewal_date__lt renewal_date__lte renewal_date__gt renewal_date__gte cnam_lookup toll_free_sms_verification_order_status].each do |param| if options.key?(param) && valid_param?(param, options[param], [String, Symbol], true) params[param] = options[param] diff --git a/lib/plivo/resources/tollfree_verification.rb b/lib/plivo/resources/tollfree_verification.rb new file mode 100644 index 00000000..d23d78f4 --- /dev/null +++ b/lib/plivo/resources/tollfree_verification.rb @@ -0,0 +1,178 @@ +module Plivo + module Resources + include Plivo::Utils + + class TollfreeVerification < Base::Resource + def initialize(client, options = nil) + @_name = 'TollfreeVerification' + @_identifier_string = 'tollfree_verification' + super + end + + def update(options = nil) + return perform_update({}) if options.nil? + + valid_param?(:options, options, Hash, true) + + params = {} + params_expected = %i[ usecase usecase_summary profile_uuid optin_type optin_image_url volume message_sample callback_method callback_url extra_data additional_information ] + params_expected.each do |param| + if options.key?(param) && + valid_param?(param, options[param], [String, Symbol], false) + params[param] = options[param] + end + end + + perform_update(params) + end + + def delete + perform_delete + end + + def to_s + { + api_id: @api_id, + uuid: @uuid, + number: @number, + created_at: @created_at, + updated_at: @updated_at, + callback_method: @callback_url, + callback_url: @callback_url, + extra_data: @extra_data, + additional_information: @additional_information, + message_sample: @message_sample, + optin_image_url: @optin_image_url, + optin_type: @optin_type, + profile_uuid: @profile_uuid, + rejection_reason: @rejection_reason, + status: @status, + usecase: @usecase, + usecase_summary: @usecase_summary, + volume: @volume + }.delete_if { |key, value| value.nil? }.to_s + end + end + + class TollfreeVerificationsInterface < Base::ResourceInterface + def initialize(client, resource_list_json = nil) + @_name = 'TollfreeVerification' + @_resource_type = TollfreeVerification + @_identifier_string = 'tollfree_verification' + super + end + + ## + # Get an TollfreeVerification + # @param [String] uuid + # return [TollfreeVerification] + def get(uuid) + valid_param?(:uuid, uuid, [String, Symbol], true) + perform_get(uuid) + end + + ## + # List all TollfreeVerification + # @param [Hash] options + # @option options [Int] :offset + # @option options [Int] :limit + # @return [Hash] + def list(options = nil) + return perform_list if options.nil? + valid_param?(:options, options, Hash, true) + + params = {} + params_expected = %i[ profile_uuid number status created__lt created__gt usecase created__lte created__gte ] + 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], true) + params[param] = options[param] + end + end + + raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0 + + 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 + + perform_list(params) + end + + ## + # Create an TollfreeVerification + # @param [String] number + # @param [String] usecase + # @param [String] usecase_summary + # @param [String] profile_uuid + # @param [String] optin_type + # @param [String] optin_image_url + # @param [String] volume + # @param [String] message_sample + # @param [String] callback_url + # @param [String] callback_method + # @param [String] extra_data + # @param [String] additional_information + # return [TollfreeVerification] TollfreeVerification + def create(number, usecase, usecase_summary, profile_uuid, optin_type, optin_image_url, volume, message_sample, callback_url = nil, callback_method = nil, extra_data = nil, additional_information = nil) + valid_param?(:number, number, [String, Symbol], true) + valid_param?(:usecase, usecase, [String, Symbol], true) + valid_param?(:usecase_summary, usecase_summary, [String, Symbol], true) + valid_param?(:profile_uuid, profile_uuid, [String, Symbol], true) + valid_param?(:optin_type, optin_type, [String, Symbol], true) + valid_param?(:optin_image_url, optin_image_url, [String, Symbol], true) + valid_param?(:volume, volume, [String, Symbol], true) + valid_param?(:message_sample, message_sample, [String, Symbol], true) + valid_param?(:callback_url, callback_url, [String, Symbol], false) + valid_param?(:callback_method, callback_method, [String, Symbol], false) + valid_param?(:extra_data, extra_data, [String, Symbol], false) + valid_param?(:additional_information, additional_information, [String, Symbol], false) + + params = { + number: number, + usecase: usecase, + usecase_summary: usecase_summary, + profile_uuid: profile_uuid, + optin_type: optin_type, + optin_image_url: optin_image_url, + volume: volume, + message_sample: message_sample, + callback_url: callback_url, + callback_method: callback_method, + extra_data: extra_data, + additional_information: additional_information + }.delete_if { |key, value| value.nil? } + + return perform_create(params) + end + + ## + # Update an TollfreeVerification + # @param [String] uuid + # @param [Hash] options + # return [TollfreeVerification] + def update(uuid, options = nil) + valid_param?(:uuid, uuid, [String, Symbol], true) + TollfreeVerification.new(@_client, + resource_id: uuid).update(options) + end + + ## + # Delete an TollfreeVerification. + # @param [String] uuid + def delete(uuid) + valid_param?(:uuid, uuid, [String, Symbol], true) + TollfreeVerification.new(@_client, + resource_id: uuid).delete + end + end + end +end \ No newline at end of file diff --git a/lib/plivo/rest_client.rb b/lib/plivo/rest_client.rb index 28597660..16101030 100644 --- a/lib/plivo/rest_client.rb +++ b/lib/plivo/rest_client.rb @@ -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 :tollfree_verifications def initialize(auth_id = nil, auth_token = nil, proxy_options = nil, timeout = 5) configure_base_uri @@ -64,6 +65,7 @@ def configure_interfaces @compliance_documents = Resources::ComplianceDocumentsInterface.new(self) @compliance_requirements = Resources::ComplianceRequirementsInterface.new(self) @compliance_applications = Resources::ComplianceApplicationsInterface.new(self) + @tollfree_verifications = Resources::TollfreeVerificationsInterface.new(self) end end end diff --git a/lib/plivo/version.rb b/lib/plivo/version.rb index 7c6fd03b..fb2bc1f7 100644 --- a/lib/plivo/version.rb +++ b/lib/plivo/version.rb @@ -1,3 +1,3 @@ module Plivo - VERSION = "4.51.0".freeze + VERSION = "4.52.0".freeze end diff --git a/spec/mocks/numberGetResponse.json b/spec/mocks/numberGetResponse.json index 85996fe0..73681033 100644 --- a/spec/mocks/numberGetResponse.json +++ b/spec/mocks/numberGetResponse.json @@ -18,5 +18,7 @@ "tendlc_registration_status": "COMPLETED", "toll_free_sms_verification": null, "renewal_date": "2023-05-10", - "cnam_lookup": "enabled" + "cnam_lookup": "enabled", + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null } \ No newline at end of file diff --git a/spec/mocks/numberListResponse.json b/spec/mocks/numberListResponse.json index 785f7d92..8b2f5717 100644 --- a/spec/mocks/numberListResponse.json +++ b/spec/mocks/numberListResponse.json @@ -27,7 +27,9 @@ "tendlc_registration_status": "COMPLETED", "toll_free_sms_verification": null, "renewal_date": "2023-05-10", - "cnam_lookup": "enabled" + "cnam_lookup": "enabled", + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null }, { "added_on": "2013-01-01", @@ -48,7 +50,9 @@ "tendlc_registration_status": "COMPLETED", "toll_free_sms_verification": null, "renewal_date": "2023-05-10", - "cnam_lookup": "enabled" + "cnam_lookup": "enabled", + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null }, { "added_on": "2013-03-25", @@ -69,7 +73,9 @@ "tendlc_registration_status": null, "toll_free_sms_verification": "verified", "renewal_date": "2023-05-10", - "cnam_lookup": "enabled" + "cnam_lookup": "enabled", + "toll_free_sms_verification_id": null, + "toll_free_sms_verification_order_status": null } ] } \ No newline at end of file diff --git a/spec/mocks/tollfreeVerificationCreateResponse.json b/spec/mocks/tollfreeVerificationCreateResponse.json new file mode 100644 index 00000000..cf963de4 --- /dev/null +++ b/spec/mocks/tollfreeVerificationCreateResponse.json @@ -0,0 +1,5 @@ +{ + "api_id": "8540e282-7335-11ee-a39b-0242ac110004", + "message": "created", + "uuid": "7f4deae2-5d79-46ec-5088-218504abf664" +} \ No newline at end of file diff --git a/spec/mocks/tollfreeVerificationListResponse.json b/spec/mocks/tollfreeVerificationListResponse.json new file mode 100644 index 00000000..28ebcdd6 --- /dev/null +++ b/spec/mocks/tollfreeVerificationListResponse.json @@ -0,0 +1,50 @@ +{ + "api_id": "e7f4a232-74ad-11ee-a860-0242ac110002", + "meta": { + "limit": 20, + "next": null, + "offset": 0, + "previous": null, + "total_count": 2 + }, + "objects": [ + { + "additional_information": "additional update1", + "callback_method": "POST", + "callback_url": "https://www.callbackurl1.com", + "created": "2023-10-25T06:28:45.168185Z", + "extra_data": "extra updated1", + "message_sample": "sample update1", + "number": "18557312530", + "optin_image_url": "https://wwww.updatedur1.com", + "optin_type": "VERBAL", + "profile_uuid": "fb239ee1-fb5c-4dd9-b55c-5cf10170e756", + "error_message": "", + "status": "SUBMITTED", + "last_modified": "2023-10-26T06:06:40.052089Z", + "usecase": "FRAUD_ALERT", + "usecase_summary": "summary up1", + "uuid": "aa5eab21-4931-468e-7502-2d8d18311fcc", + "volume": "10" + }, + { + "additional_information": "this is additional_information", + "callback_method": "POST", + "callback_url": "http://plivobin-prod-usw1.plivops.com/14ha4pv1", + "created": "2023-10-25T06:10:46.650776Z", + "extra_data": "this is extra_data", + "message_sample": "mes", + "number": "18449034555", + "optin_image_url": "https://www.aa.com,http://google.com", + "optin_type": "VERBAL", + "profile_uuid": "fb239ee1-fb5c-4dd9-b55c-5cf10170e756", + "error_message": "", + "status": "SUBMITTED", + "last_modified": "2023-10-25T07:40:34.402899Z", + "usecase": "2FA,FRAUD_ALERT,HIGHER_EDUCATION,PUBLIC_SERVICE_ANNOUNCEMENT", + "usecase_summary": "use ", + "uuid": "4e86e627-a12f-4bb6-601f-c47ec7f5e367", + "volume": "10" + } + ] +} \ No newline at end of file diff --git a/spec/mocks/tollfreeVerificationUpdateResponse.json b/spec/mocks/tollfreeVerificationUpdateResponse.json new file mode 100644 index 00000000..575e52a3 --- /dev/null +++ b/spec/mocks/tollfreeVerificationUpdateResponse.json @@ -0,0 +1,4 @@ +{ + "api_id": "2c3be616-74af-11ee-a860-0242ac110002", + "message": "Tollfree verification request for uuid 81fc8b2d-1ab8-47c9-7245-e454227b7b7b updated successfully." +} \ No newline at end of file diff --git a/spec/mocks/tollfreeverificationGetResponse.json b/spec/mocks/tollfreeverificationGetResponse.json new file mode 100644 index 00000000..9e9cac1c --- /dev/null +++ b/spec/mocks/tollfreeverificationGetResponse.json @@ -0,0 +1,19 @@ +{ + "additional_information": "this is additional_information", + "callback_method": "POST", + "callback_url": "https://plivobin-prod-usw1.plivops.com/1pcfjrt1", + "created": "2023-10-25T12:53:40.598379Z", + "extra_data": "this is extra_data", + "message_sample": "message_sample", + "number": "18554950186", + "optin_image_url": "http://google.com", + "optin_type": "VERBAL", + "profile_uuid": "42f92135-6ec2-4110-8da4-71171f6aad44", + "error_message": "Number not provisioned to submitting org", + "status": "REJECTED", + "last_modified": "2023-10-25T12:53:44.56875Z", + "usecase": "2FA", + "usecase_summary": "hbv", + "uuid": "7f4deae2-5d79-46ec-5088-218504abf664", + "volume": "100" +} \ No newline at end of file diff --git a/spec/resource_numbers_spec.rb b/spec/resource_numbers_spec.rb index b6ec913b..ee189772 100644 --- a/spec/resource_numbers_spec.rb +++ b/spec/resource_numbers_spec.rb @@ -22,7 +22,9 @@ def to_json(number) tendlc_registration_status: number.tendlc_registration_status, toll_free_sms_verification: number.toll_free_sms_verification, renewal_date: number.renewal_date, - cnam_lookup: number.cnam_lookup + cnam_lookup: number.cnam_lookup, + toll_free_sms_verification_id: number.toll_free_sms_verification_id, + toll_free_sms_verification_order_status: number.toll_free_sms_verification_order_status, }.to_json end diff --git a/spec/resource_tollfree_verification_spec.rb b/spec/resource_tollfree_verification_spec.rb new file mode 100644 index 00000000..21b7f7cd --- /dev/null +++ b/spec/resource_tollfree_verification_spec.rb @@ -0,0 +1,74 @@ +require 'rspec' + +describe 'TollfreeVerifications test' do + def to_json(tfverificationobj) + { + created: tfverificationobj.created, + number: tfverificationobj.number, + last_modified: tfverificationobj.last_modified, + callback_method: tfverificationobj.callback_method, + callback_url: tfverificationobj.callback_url, + extra_data: tfverificationobj.extra_data, + additional_information: tfverificationobj.additional_information, + message_sample: tfverificationobj.message_sample, + optin_image_url: tfverificationobj.optin_image_url, + optin_type: tfverificationobj.optin_type, + profile_uuid: tfverificationobj.profile_uuid, + error_message: tfverificationobj.error_message, + status: tfverificationobj.status, + usecase: tfverificationobj.usecase, + usecase_summary: tfverificationobj.usecase_summary, + uuid: tfverificationobj.uuid, + volume: tfverificationobj.volume, + }.to_json + end + + def to_json_update(tfverificationobj) + { + api_id: tfverificationobj.api_id, + message: tfverificationobj.message + }.to_json + end + + def to_json_create(tfverificationobj) + { + message: tfverificationobj.message, + uuid: tfverificationobj.uuid, + api_id: tfverificationobj.api_id + }.to_json + end + + def to_json_list(list_object) + objects_json = list_object[:objects].map do |object| + obj = JSON.parse(to_json(object)) + obj.delete('api_id') + obj + end + { + api_id: list_object[:api_id], + meta: list_object[:meta], + objects: objects_json + }.to_json + end + + it 'fetches details of tollfree verification' do + contents = File.read(Dir.pwd + '/spec/mocks/tollfreeverificationGetResponse.json') + mock(200, JSON.parse(contents)) + expect(JSON.parse(to_json(@api.tollfree_verifications.get('SAXXXXXXXXXXXXXXXXXX')))) + .to eql(JSON.parse(contents)) + compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/'\ + 'SAXXXXXXXXXXXXXXXXXX/', + method: 'GET', + data: nil) + end + + it 'deletes the tollfree verifications' do + id = 'SAXXXXXXXXXXXXXXXXXX' + contents = '{}' + mock(204, JSON.parse(contents)) + @api.tollfree_verifications.delete(id) + compare_requests(uri: '/v1/Account/MAXXXXXXXXXXXXXXXXXX/TollfreeVerification/' + id + '/', + method: 'DELETE', + data: nil) + end +end \ No newline at end of file