Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/telesignenterprise.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require 'telesignenterprise/phoneid'
require 'telesignenterprise/telebureau'
require 'telesignenterprise/verify'
require 'telesignenterprise/score'
require 'telesignenterprise/messaging'
require 'telesignenterprise/voice'
require 'telesignenterprise/appverify'
21 changes: 21 additions & 0 deletions lib/telesignenterprise/appverify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'telesign'

module TelesignEnterprise

# App Verify is a secure, lightweight SDK that integrates a frictionless user verification process into existing
# native mobile applications.
class AppVerifyClient < Telesign::AppVerifyClient

def initialize(customer_id,
api_key,
rest_endpoint: 'https://rest-ww.telesign.com',
timeout: nil)

super(customer_id,
api_key,
rest_endpoint: rest_endpoint,
timeout: timeout)
end

end
end
20 changes: 20 additions & 0 deletions lib/telesignenterprise/messaging.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'telesign'

module TelesignEnterprise

# TeleSign's Messaging API allows you to easily send SMS messages. You can send alerts, reminders, and notifications,
# or you can send verification messages containing one-time passcodes (OTP).
class MessagingClient < Telesign::MessagingClient

def initialize(customer_id,
api_key,
rest_endpoint: 'https://rest-ww.telesign.com',
timeout: nil)

super(customer_id,
api_key,
rest_endpoint: rest_endpoint,
timeout: timeout)
end
end
end
4 changes: 2 additions & 2 deletions lib/telesignenterprise/phoneid.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'telesign/rest'
require 'telesign/phoneid'

PHONEID_STANDARD_RESOURCE = '/v1/phoneid/standard/%{phone_number}'
PHONEID_SCORE_RESOURCE = '/v1/phoneid/score/%{phone_number}'
Expand All @@ -14,7 +14,7 @@ module TelesignEnterprise
# TeleSign PhoneID provides a wide range of risk assessment indicators on the number to help confirm user identity,
# delivering real-time decision making throughout the number lifecycle and ensuring only legitimate users are
# creating accounts and accessing your applications.
class PhoneIdClient < Telesign::RestClient
class PhoneIdClient < Telesign::PhoneIdClient

def initialize(customer_id,
api_key,
Expand Down
20 changes: 20 additions & 0 deletions lib/telesignenterprise/score.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'telesign'

module TelesignEnterprise

# Score provides risk information about a specified phone number.
class ScoreClient < Telesign::ScoreClient

def initialize(customer_id,
api_key,
rest_endpoint: 'https://rest-ww.telesign.com',
timeout: nil)

super(customer_id,
api_key,
rest_endpoint: rest_endpoint,
timeout: timeout)
end

end
end
20 changes: 20 additions & 0 deletions lib/telesignenterprise/voice.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'telesign'

module TelesignEnterprise

# TeleSign's Voice API allows you to easily send voice messages. You can send alerts, reminders, and notifications,
# or you can send verification messages containing time-based, one-time passcodes (TOTP).
class VoiceClient < Telesign::VoiceClient

def initialize(customer_id,
api_key,
rest_endpoint: 'https://rest-ww.telesign.com',
timeout: nil)

super(customer_id,
api_key,
rest_endpoint: rest_endpoint,
timeout: timeout)
end
end
end
4 changes: 2 additions & 2 deletions telesignenterprise.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = 'telesignenterprise'
s.version = '2.1.2'
s.add_runtime_dependency 'telesign', '~> 2.2.0'
s.version = '2.2.0'
s.add_runtime_dependency 'telesign', '~> 2.2.2'
s.licenses = ['MIT']
s.date = '2017-05-02'
s.summary = 'TeleSign Ruby SDK'
Expand Down
182 changes: 179 additions & 3 deletions test/test_rest.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,187 @@
require 'uuid'
require 'time'
require 'test/unit'
require_relative '../lib/telesignenterprise.rb'
require 'webmock/test_unit'
require 'mocha/setup'

require 'telesignenterprise'

class TestRest < Test::Unit::TestCase

def test_version
def setup
@customer_id = 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890'
@api_key = 'EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='
@phone_number = '1234567890'
end

def test_phoneid_standard
stub_request(:get, "localhost/v1/phoneid/standard/#{@phone_number}").to_return(body: '{}')

client = TelesignEnterprise::PhoneIdClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')
client.standard(@phone_number)
assert_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}"
assert_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}", body: ''
assert_not_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}", headers: {'Content-Type' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/phoneid/standard/#{@phone_number}", headers: {'Date' => /.*\S.*/}
end

def test_phoneid

stub_request(:post, "localhost/v1/phoneid/#{@phone_number}").to_return(body: '{}')

client = TelesignEnterprise::PhoneIdClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.phoneid(@phone_number)

assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}"
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", body: '{}'
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'Content-Type' => 'application/json'}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'Date' => /.*\S.*/}
end

def test_phoneid_with_addons

stub_request(:post, "localhost/v1/phoneid/#{@phone_number}").to_return(body: '{}')

client = TelesignEnterprise::PhoneIdClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.phoneid(@phone_number, addons: {'contact': {}})

assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}"
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", body: '{"addons":{"contact":{}}}'
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'Content-Type' => 'application/json'}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :post, "http://localhost/v1/phoneid/#{@phone_number}", headers: {'Date' => /.*\S.*/}
end

def test_phoneid_score

stub_request(:get, "localhost/v1/phoneid/score/#{@phone_number}").to_return(body: '{}')

client = TelesignEnterprise::PhoneIdClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.score(@phone_number, 'TOOL')

assert_requested :get, "http://localhost/v1/phoneid/score/#{@phone_number}"
assert_not_requested :get, "http://localhost/v1/phoneid/score/#{@phone_number}", headers: {'Content-Type' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/phoneid/score/#{@phone_number}", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :get, "http://localhost/v1/phoneid/score/#{@phone_number}", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/phoneid/score/#{@phone_number}", headers: {'Date' => /.*\S.*/}
end

def test_score

stub_request(:post, "localhost/v1/score/#{@phone_number}").to_return(body: '{}')

client = TelesignEnterprise::ScoreClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.score(@phone_number, 'create')

assert_requested :post, "http://localhost/v1/score/#{@phone_number}"
assert_requested :post, "http://localhost/v1/score/#{@phone_number}", body: 'account_lifecycle_event=create'
assert_requested :post, "http://localhost/v1/score/#{@phone_number}", headers: {'Content-Type' => 'application/x-www-form-urlencoded'}
assert_requested :post, "http://localhost/v1/score/#{@phone_number}", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :post, "http://localhost/v1/score/#{@phone_number}", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :post, "http://localhost/v1/score/#{@phone_number}", headers: {'Date' => /.*\S.*/}
end

def test_messaging

stub_request(:post, 'localhost/v1/messaging').to_return(body: '{}')

client = TelesignEnterprise::MessagingClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.message(@phone_number, 'Test Message', 'ARN')

assert_requested :post, "http://localhost/v1/messaging"
assert_requested :post, "http://localhost/v1/messaging", body: "phone_number=#{@phone_number}&message=Test+Message&message_type=ARN"
assert_requested :post, "http://localhost/v1/messaging", headers: {'Content-Type' => 'application/x-www-form-urlencoded'}
assert_requested :post, "http://localhost/v1/messaging", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :post, "http://localhost/v1/messaging", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :post, "http://localhost/v1/messaging", headers: {'Date' => /.*\S.*/}
end

def test_messaging_status

stub_request(:get, 'localhost/v1/messaging/REFERENCE_ID').to_return(body: '{}')

client = TelesignEnterprise::MessagingClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.status('REFERENCE_ID')

assert_requested :get, "http://localhost/v1/messaging/REFERENCE_ID"
assert_requested :get, "http://localhost/v1/messaging/REFERENCE_ID", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :get, "http://localhost/v1/messaging/REFERENCE_ID", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/messaging/REFERENCE_ID", headers: {'Date' => /.*\S.*/}
end

def test_voice

stub_request(:post, 'localhost/v1/voice').to_return(body: '{}')

client = TelesignEnterprise::VoiceClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.call(@phone_number, 'Test Message', 'ARN')

assert_requested :post, "http://localhost/v1/voice"
assert_requested :post, "http://localhost/v1/voice", body: "phone_number=#{@phone_number}&message=Test+Message&message_type=ARN"
assert_requested :post, "http://localhost/v1/voice", headers: {'Content-Type' => 'application/x-www-form-urlencoded'}
assert_requested :post, "http://localhost/v1/voice", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :post, "http://localhost/v1/voice", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :post, "http://localhost/v1/voice", headers: {'Date' => /.*\S.*/}
end

def test_voice_status

stub_request(:get, 'localhost/v1/voice/REFERENCE_ID').to_return(body: '{}')

client = TelesignEnterprise::VoiceClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.status('REFERENCE_ID')

assert_requested :get, "http://localhost/v1/voice/REFERENCE_ID"
assert_requested :get, "http://localhost/v1/voice/REFERENCE_ID", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :get, "http://localhost/v1/voice/REFERENCE_ID", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/voice/REFERENCE_ID", headers: {'Date' => /.*\S.*/}
end

def test_app_verify_status

stub_request(:get, 'localhost/v1/mobile/verification/status/EXTERNAL_ID').to_return(body: '{}')

client = TelesignEnterprise::AppVerifyClient.new(@customer_id,
@api_key,
rest_endpoint: 'http://localhost')

client.status('EXTERNAL_ID')

puts Telesign::SDK_VERSION
assert_requested :get, "http://localhost/v1/mobile/verification/status/EXTERNAL_ID"
assert_requested :get, "http://localhost/v1/mobile/verification/status/EXTERNAL_ID", headers: {'x-ts-auth-method' => 'HMAC-SHA256'}
assert_requested :get, "http://localhost/v1/mobile/verification/status/EXTERNAL_ID", headers: {'x-ts-nonce' => /.*\S.*/}
assert_requested :get, "http://localhost/v1/mobile/verification/status/EXTERNAL_ID", headers: {'Date' => /.*\S.*/}
end

end