-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVX-7324: Add Number Insight v2 (#299)
* Implementing NumberInsight2
- Loading branch information
1 parent
88a87c6
commit d4d2317
Showing
5 changed files
with
113 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Vonage | ||
class NumberInsight2 < Namespace | ||
extend T::Sig | ||
|
||
self.authentication = Basic | ||
|
||
self.request_body = JSON | ||
|
||
# Make fraud check requests with a phone number by looking up fraud score and/or by checking sim swap status. | ||
# | ||
# @example | ||
# response = client.number_insight_2.fraud_check(type: 'phone', phone: '447900000000', insights: ['fraud_score']) | ||
# | ||
# @param [required, String] :type The type of number to check. | ||
# Accepted value is “phone” when a phone number is provided. | ||
# | ||
# @param [required, String] :phone A single phone number that you need insight about in the E.164 format. | ||
# | ||
# @param [required, Array] :insights An array of strings indicating the fraud check insights required for the number. | ||
# Must be least one of: `fraud_score`, `sim_swap` | ||
# | ||
# @return [Response] | ||
# | ||
# @see https://developer.vonage.com/en/api/number-insight.v2#fraud_check | ||
# | ||
sig { params(type: String, phone: String, insights: T::Array[String]).returns(Vonage::Response) } | ||
def fraud_check(type:, phone:, insights:) | ||
raise ArgumentError.new("`insights` must not be an empty") if insights.empty? | ||
|
||
request('/v2/ni', params: {type: type, phone: phone, insights: insights}, type: Post) | ||
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
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,63 @@ | ||
# typed: false | ||
require_relative './test' | ||
|
||
class Vonage::NumberInsight2Test < Vonage::Test | ||
def number_insight_2 | ||
Vonage::NumberInsight2.new(config) | ||
end | ||
|
||
def uri | ||
'https://api.nexmo.com/v2/ni' | ||
end | ||
|
||
def number | ||
'447700900000' | ||
end | ||
|
||
def test_fraud_check_method | ||
params = {type: 'phone', phone: number, insights: ['fraud_score', 'sim_swap']} | ||
stub_request(:post, uri).with(body: params).to_return(response) | ||
|
||
assert_kind_of Vonage::Response, number_insight_2.fraud_check(**params) | ||
end | ||
|
||
def test_fraud_check_method_without_type | ||
params = {phone: number, insights: ['fraud_score', 'sim_swap']} | ||
|
||
assert_raises ArgumentError do | ||
number_insight_2.fraud_check(**params) | ||
end | ||
end | ||
|
||
def test_fraud_check_method_without_phone | ||
params = {type: 'phone', insights: ['fraud_score', 'sim_swap']} | ||
|
||
assert_raises ArgumentError do | ||
number_insight_2.fraud_check(**params) | ||
end | ||
end | ||
|
||
def test_fraud_check_method_without_insights | ||
params = {type: 'phone', phone: number} | ||
|
||
assert_raises ArgumentError do | ||
number_insight_2.fraud_check(**params) | ||
end | ||
end | ||
|
||
def test_fraud_check_method_with_insights_not_an_array | ||
params = {type: 'phone', phone: number, insights: 'fraud_score'} | ||
|
||
assert_raises TypeError do | ||
number_insight_2.fraud_check(**params) | ||
end | ||
end | ||
|
||
def test_fraud_check_method_with_insights_an_empty_array | ||
params = {type: 'phone', phone: number, insights: []} | ||
|
||
assert_raises ArgumentError do | ||
number_insight_2.fraud_check(**params) | ||
end | ||
end | ||
end |