From 42c5ea3bed2751e471a65811447554eb3d3ee5aa Mon Sep 17 00:00:00 2001 From: Jarrad Lee Date: Tue, 22 Nov 2016 13:21:32 -0500 Subject: [PATCH] Added number_deactivation and telebureau create, retrieve and delete endpoints. --- README.rst | 131 +++++++++++++++++++++++++++-------------------- lib/telesign.rb | 102 +++++++++++++++++++++++++++++++++++- sample.rb | 64 +++++++++++++++-------- telesign.gemspec | 5 +- 4 files changed, 221 insertions(+), 81 deletions(-) diff --git a/README.rst b/README.rst index 7a78fdd..fb6a842 100644 --- a/README.rst +++ b/README.rst @@ -18,62 +18,81 @@ The Ruby Classes With just two classes, **Telesign::API** abstracts much of the complexity of the TeleSign REST API. -+------------------------+--------------------------------------------------------------------------+ -| Ruby Class | Description | -+========================+==========================================================================+ -| Telesign::API::PhoneId | The **PhoneId** class exposes four services that each provide | -| | information about a specified phone number. | -| | | -| | *standard* | -| | Retrieves the standard set of details about the specified phone | -| | number. This includes the type of phone (for example, land line or | -| | mobile), and its approximate geographic location. | -| | *score* | -| | Retrieves a score for the specified phone number. This ranks the | -| | phone number's "risk level" on a scale from 0 to 1000, so you can | -| | code your web application to handle particular use cases (for | -| | example, to stop things like chargebacks, identity theft, fraud, and | -| | spam). | -| | *contact* | -| | In addition to the information retrieved by *standard*, this service | -| | provides the name and address associated with the specified phone | -| | number. | -| | *live* | -| | In addition to the information retrieved by standard, this service | -| | provides actionable data associated with the specified phone number. | -| | | -+------------------------+--------------------------------------------------------------------------+ -| Telesign::API::Verify | The **Verify** class exposes five services for sending users a | -| | verification token (a three to five-digit number). You can use this | -| | mechanism to test whether you can reach users at the phone number | -| | they supplied, or you can have them use the token to authenticate | -| | themselves with your web application. In addition, this class also | -| | exposes a service that allows you to confirm the result of the | -| | authentication. | -| | | -| | You can use this verification factor in combination with *username* | -| | and *password* to provide *two-factor* authentication for higher | -| | security. | -| | | -| | *call* | -| | Calls the specified phone number and uses speech synthesis to speak | -| | the verification code to the user. | -| | *sms* | -| | Sends a text message containing the verification code to the | -| | specified phone number (supported for mobile phones only). | -| | *smart* | -| | Smart intelligently determines the best service to use based on | -| | the end user device and then attempts to place a call, send an SMS, | -| | or send a push request. | -| | *push* | -| | Sends a push notification containing the verification code to the | -| | specified phone number (supported for registered devices only). | -| | *status* | -| | Retrieves the verification result. You make this call in your web | -| | application after users complete the authentication transaction | -| | (using either a *call* or *sms*). | -| | | -+------------------------+--------------------------------------------------------------------------+ ++---------------------------+--------------------------------------------------------------------------+ +| Ruby Class | Description | ++===========================+==========================================================================+ +| Telesign::API::PhoneId | The **PhoneId** class exposes four services that each provide | +| | information about a specified phone number. | +| | | +| | *standard* | +| | Retrieves the standard set of details about the specified phone | +| | number. This includes the type of phone (for example, land line or | +| | mobile), and its approximate geographic location. | +| | *score* | +| | Retrieves a score for the specified phone number. This ranks the | +| | phone number's "risk level" on a scale from 0 to 1000, so you can | +| | code your web application to handle particular use cases (for | +| | example, to stop things like chargebacks, identity theft, fraud, and | +| | spam). | +| | *contact* | +| | In addition to the information retrieved by *standard*, this service | +| | provides the name and address associated with the specified phone | +| | number. | +| | *live* | +| | In addition to the information retrieved by *standard*, this service | +| | provides actionable data associated with the specified phone number. | +| | *number_deactivation* | +| | In addition to the information retrieved by *standard*, this service | +| | provides information on number deactivation for the phone number | +| | provided. | ++---------------------------+--------------------------------------------------------------------------+ +| Telesign::API::Verify | The **Verify** class exposes five services for sending users a | +| | verification token (a three to five-digit number). You can use this | +| | mechanism to test whether you can reach users at the phone number | +| | they supplied, or you can have them use the token to authenticate | +| | themselves with your web application. In addition, this class also | +| | exposes a service that allows you to confirm the result of the | +| | authentication. | +| | | +| | You can use this verification factor in combination with *username* | +| | and *password* to provide *two-factor* authentication for higher | +| | security. | +| | | +| | *call* | +| | Calls the specified phone number and uses speech synthesis to speak | +| | the verification code to the user. | +| | *sms* | +| | Sends a text message containing the verification code to the | +| | specified phone number (supported for mobile phones only). | +| | *smart* | +| | Smart intelligently determines the best service to use based on | +| | the end user device and then attempts to place a call, send an SMS, | +| | or send a push request. | +| | *push* | +| | Sends a push notification containing the verification code to the | +| | specified phone number (supported for registered devices only). | +| | *status* | +| | Retrieves the verification result. You make this call in your web | +| | application after users complete the authentication transaction | +| | (using either a *call* or *sms*). | +| | | ++---------------------------+--------------------------------------------------------------------------+ +| Telesign::API::TeleBureau | The **Telebureau** class exposes services for creating, retrieving, | +| | updating and deleting telebureau fraud events. You can use this | +| | mechanism to test whether you can reach Telebureau services. | +| | | +| | *create* | +| | Creates a Telebureau event corresponding to supplied data. | +| | *retrieve* | +| | Retrieves the fraud event status. You make this call in your web | +| | application after completion of create/update transaction for a | +| | Telebureau event. | +| | *delete* | +| | Deletes a previously submitted fraud event. You make this call in | +| | your web application after completion of submit/update transaction | +| | for a Telebureau event. | +| | | ++---------------------------+--------------------------------------------------------------------------+ Installation ------------ diff --git a/lib/telesign.rb b/lib/telesign.rb index d0b978a..dce2811 100644 --- a/lib/telesign.rb +++ b/lib/telesign.rb @@ -158,6 +158,26 @@ def call_forward(phone_number, timeout) end + # In addition to the information retrieved by standard, this service provides + # information on call forwarding for the phone number provided. + def number_deactivation(phone_number, + use_case_code, + extra=nil, + timeout=nil) + + params = {:ucid => use_case_code} + + unless extra.nil? + params.merge!(extra) + end + + execute(Net::HTTP::Get, + "/v1/phoneid/number_deactivation/#{phone_number}", + params, + nil, + timeout) + end + end # The Verify class exposes several services for sending users a verification @@ -270,7 +290,7 @@ def push(phone_number, end execute(Net::HTTP::Post, - "/v1/verify/push", + "/v2/verify/push", nil, params, timeout) @@ -301,5 +321,85 @@ def status(reference_id, timeout) end end + + + # The **Telebureau** class exposes services for creating, retrieving, updating and + # deleting telebureau fraud events. You can use this mechanism to simply test whether + # you can reach telebureau services. + class TeleBureau < Telesign::API::Rest + + def initialize(customer_id, + secret_key, + ssl=true, + api_host='rest.telesign.com', + timeout=nil) + + super(customer_id, + secret_key, + ssl, + api_host, + timeout) + end + + # Creates a telebureau event corresponding to supplied data. + def create(phone_number, + fraud_type, + occurred_at, + extra=nil, + timeout=nil) + + params = {:phone_number => phone_number, + :fraud_type => fraud_type, + :occurred_at => occurred_at} + + unless extra.nil? + params.merge!(extra) + end + + execute(Net::HTTP::Post, + "/v1/telebureau/event", + nil, + params, + timeout) + end + + # Retrieves the fraud event status. You make this call in your web application after + # completion of create transaction for a telebureau event. + def retrieve(reference_id, + extra=nil, + timeout=nil) + + params = {} + + unless extra.nil? + params.merge!(extra) + end + + execute(Net::HTTP::Get, + "/v1/telebureau/event/#{reference_id}", + params, + nil, + timeout) + end + + # Deletes a previously submitted fraud event. You make this call in your web application + # after completion of the create transaction for a telebureau event. + def delete(reference_id, + extra=nil, + timeout=nil) + + params = {} + + unless extra.nil? + params.merge!(extra) + end + + execute(Net::HTTP::Delete, + "/v1/telebureau/event/#{reference_id}", + params, + nil, + timeout) + end + end end end \ No newline at end of file diff --git a/sample.rb b/sample.rb index f185566..c5e0ff6 100644 --- a/sample.rb +++ b/sample.rb @@ -5,6 +5,7 @@ # require 'telesign' +require 'date' require 'pp' # update this with your credentials @@ -18,47 +19,66 @@ verify = Telesign::API::Verify.new(customer_id, secret_key) phoneid = Telesign::API::PhoneId.new(customer_id, secret_key) +telebureau = Telesign::API::TeleBureau.new(customer_id, secret_key) # sample sms -verify_response = verify.sms(phone_number) -pp verify_response.body +verify_sms_response = verify.sms(phone_number) +pp verify_sms_response.body # sample status -verify_response = verify.status(verify_response.body['reference_id']) -pp verify_response.body +verify_status_response = verify.status(verify_sms_response.body['reference_id']) +pp verify_status_response.body # sample voice -verify_response = verify.call(phone_number) -p verify_response.body +verify_voice_response = verify.call(phone_number) +p verify_voice_response.body # sample smart -verify_response = verify.smart(phone_number, use_case_code) -pp verify_response.body +verify_smart_response = verify.smart(phone_number, use_case_code) +pp verify_smart_response.body # sample push -verify_response = verify.push(phone_number, use_case_code) -pp verify_response.body +verify_push_response = verify.push(phone_number, use_case_code) +pp verify_push_response.body # sample phoneid standard -phoneid_response = phoneid.standard(phone_number) -pp phoneid_response.body +phoneid_standard_response = phoneid.standard(phone_number) +pp phoneid_standard_response.body # sample phoneid contact -phoneid_response = phoneid.contact(phone_number, use_case_code) -pp phoneid_response.body +phoneid_contact_response = phoneid.contact(phone_number, use_case_code) +pp phoneid_contact_response.body # sample phoneid score -phoneid_response = phoneid.score(phone_number, use_case_code) -pp phoneid_response.body +phoneid_score_response = phoneid.score(phone_number, use_case_code) +pp phoneid_score_response.body # sample phoneid live -phoneid_response = phoneid.live(phone_number, use_case_code) -pp phoneid_response.body +phoneid_live_response = phoneid.live(phone_number, use_case_code) +pp phoneid_live_response.body # sample phoneid sim_swap -phoneid_response = phoneid.sim_swap(phone_number, use_case_code) -pp phoneid_response.body +phoneid_sim_swap_response = phoneid.sim_swap(phone_number, use_case_code) +pp phoneid_sim_swap_response.body # sample phoneid call_forward -phoneid_response = phoneid.call_forward(phone_number, use_case_code) -pp phoneid_response.body +phoneid_call_forward_response = phoneid.call_forward(phone_number, use_case_code) +pp phoneid_call_forward_response.body + +# sample phoneid number_deactivation +phoneid_number_deactivation_response = phoneid.number_deactivation(phone_number, use_case_code) +pp phoneid_number_deactivation_response.body + +# sample telebureau create +fraud_type = 'takeover' +occurred_at = '2016-11-22T00:43:44Z' +telebureau_create_response = telebureau.create(phone_number, fraud_type, occurred_at) +pp telebureau_create_response.body + +# sample telebureau retrieve +telebureau_retrieve_response = telebureau.retrieve(telebureau_create_response.body['reference_id']) +pp telebureau_retrieve_response.body + +# sample telebureau delete +telebureau_delete_response = telebureau.delete(telebureau_create_response.body['reference_id']) +pp telebureau_delete_response.body diff --git a/telesign.gemspec b/telesign.gemspec index 76ff8e8..36fea66 100644 --- a/telesign.gemspec +++ b/telesign.gemspec @@ -1,7 +1,8 @@ Gem::Specification.new do |s| s.name = 'telesign' - s.version = '1.0.1' - s.date = '2016-03-02' + s.version = '1.0.2' + s.licenses = ['MIT'] + s.date = '2016-11-22' s.summary = 'TeleSign Ruby SDK' s.description = 'TeleSign Ruby SDK' s.authors = ['Jarrad Lee']