telesignature 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +51 -5
- data/lib/telesignature.rb +1 -1
- data/lib/telesignature/api.rb +50 -0
- data/lib/telesignature/helpers.rb +13 -0
- data/lib/telesignature/phone_id.rb +6 -35
- data/lib/telesignature/telesign_error.rb +3 -10
- data/lib/telesignature/verify.rb +13 -55
- data/lib/telesignature/version.rb +1 -1
- data/test/exceptions_test.rb +9 -11
- data/test/phone_id_test.rb +12 -12
- data/test/verify_test.rb +14 -14
- metadata +3 -3
- data/lib/telesignature/service_base.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c925e79f51c5d48ea857f4860b963caac89391e
|
4
|
+
data.tar.gz: c16c31aa5b6ea51f3be3d48a062af8f5ff590fd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c1346814b5b7fdab14b8350f6b1d10e78115fad00fa2bea1510ee64993ea235832c7bfb87fd20143fe5241fd9e087d1c577ccf39bdd6491a99f22008f2b1326
|
7
|
+
data.tar.gz: 973fd94eb9e5894cfefbf8ebeba17edd408262d16e68f9b6a63b8d13a329e365586043a404d02830c8c808e5ee6e37b7cb933c9431efab33266f7c922bc2d000
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -12,10 +12,52 @@ customer_id = 'FFFFFFFF-EEEE-DDDD-1234-AB1234567890'
|
|
12
12
|
secret_key = 'EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=='
|
13
13
|
phone_number = '4445551212'
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
require 'telesignature'
|
16
|
+
|
17
|
+
ta = Telesignature::Api.new customer_id: customer_id,
|
18
|
+
secret_key: secret_key
|
19
|
+
|
20
|
+
phone_info = ta.phone_id.standard phone_number
|
21
|
+
|
22
|
+
p "##################"
|
23
|
+
p phone_info.data
|
24
|
+
p phone_info.headers
|
25
|
+
p phone_info.status
|
26
|
+
p phone_info.raw_data
|
27
|
+
p "##################"
|
28
|
+
|
29
|
+
phone_info = ta.phone_id.contact phone_number, 'PWRT'
|
30
|
+
|
31
|
+
p "##################"
|
32
|
+
p phone_info.data
|
33
|
+
p phone_info.headers
|
34
|
+
p phone_info.status
|
35
|
+
p phone_info.raw_data
|
36
|
+
p "##################"
|
17
37
|
|
18
|
-
phone_info =
|
38
|
+
phone_info = ta.phone_id.score phone_number, 'PWRT'
|
39
|
+
|
40
|
+
p "##################"
|
41
|
+
p phone_info.data
|
42
|
+
p phone_info.headers
|
43
|
+
p phone_info.status
|
44
|
+
p phone_info.raw_data
|
45
|
+
p "##################"
|
46
|
+
|
47
|
+
begin
|
48
|
+
phone_info = ta.phone_id.live phone_number, 'RXPF'
|
49
|
+
rescue Telesignature::AuthorizationError => e
|
50
|
+
puts e.message
|
51
|
+
end
|
52
|
+
|
53
|
+
p "##################"
|
54
|
+
p phone_info.data
|
55
|
+
p phone_info.headers
|
56
|
+
p phone_info.status
|
57
|
+
p phone_info.raw_data
|
58
|
+
p "##################"
|
59
|
+
|
60
|
+
phone_info = ta.verify.sms phone_number: phone_number #, verify_code: '12345'
|
19
61
|
|
20
62
|
p "##################"
|
21
63
|
p phone_info.data
|
@@ -25,8 +67,8 @@ p phone_info.raw_data
|
|
25
67
|
p phone_info.verify_code
|
26
68
|
p "##################"
|
27
69
|
|
28
|
-
status_info =
|
29
|
-
# status_info =
|
70
|
+
status_info = ta.verify.status phone_info.data['reference_id'], phone_info.verify_code
|
71
|
+
# status_info = ta.verify.status phone_info.data['reference_id'], '12345'
|
30
72
|
|
31
73
|
p "\n\n\n"
|
32
74
|
p "##################"
|
@@ -56,3 +98,7 @@ Both of which always return a success response.
|
|
56
98
|
get '/v1/verify/:reference_id'
|
57
99
|
|
58
100
|
Returns VALID for any verify_code which does not contain '666'.
|
101
|
+
|
102
|
+
get '/v1/phoneid/standard/:phone_number'
|
103
|
+
|
104
|
+
See codes for triggering different phone-type responses.
|
data/lib/telesignature.rb
CHANGED
@@ -8,7 +8,7 @@ module Telesignature
|
|
8
8
|
autoload :Auth, 'telesignature/auth'
|
9
9
|
autoload :Response, 'telesignature/response'
|
10
10
|
autoload :Helpers, 'telesignature/helpers'
|
11
|
-
autoload :ServiceBase, 'telesignature/service_base'
|
12
11
|
autoload :Verify, 'telesignature/verify'
|
13
12
|
autoload :PhoneId, 'telesignature/phone_id'
|
13
|
+
autoload :Api, 'telesignature/api'
|
14
14
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Telesignature
|
5
|
+
class Api
|
6
|
+
# * - Attributes
|
7
|
+
# -
|
8
|
+
# * - `customer_id`
|
9
|
+
# - A string value that identifies your TeleSign account.
|
10
|
+
# * - `secret_key`
|
11
|
+
# - A base64-encoded string value that validates your access to the TeleSign web services.
|
12
|
+
# * - `ssl`
|
13
|
+
# - Specifies whether to use a secure connection with the TeleSign server. Defaults to *true*.
|
14
|
+
# * - `api_host`
|
15
|
+
# - The Internet host used in the base URI for REST web services.
|
16
|
+
# The default is *rest.telesign.com* (and the base URI is https://rest.telesign.com/).
|
17
|
+
# * - `proxy_host`
|
18
|
+
# - The host and port when going through a proxy server. ex: "localhost:8080. The default to no proxy.
|
19
|
+
|
20
|
+
# NOTE
|
21
|
+
# You can obtain both your Customer ID and Secret Key from the
|
22
|
+
# TeleSign Customer Portal <https://portal.telesign.com/account_profile_api_auth.php>
|
23
|
+
|
24
|
+
# """
|
25
|
+
|
26
|
+
attr_accessor :verify, :phone_id
|
27
|
+
|
28
|
+
def initialize opts = {}
|
29
|
+
@customer_id = opts[:customer_id]
|
30
|
+
@secret_key = opts[:secret_key]
|
31
|
+
api_host = opts[:api_host] || 'rest.telesign.com'
|
32
|
+
ssl = opts[:ssl].nil? ? true : opts[:ssl]
|
33
|
+
proxy_host = opts[:proxy_host] || nil
|
34
|
+
|
35
|
+
http_root = ssl ? 'https' : 'http'
|
36
|
+
proxy = proxy_host ? "#{http_root}://#{proxy_host}" : nil
|
37
|
+
url = "#{http_root}://#{api_host}"
|
38
|
+
|
39
|
+
@conn = Faraday.new(url: url) do |faraday|
|
40
|
+
faraday.request :url_encoded
|
41
|
+
faraday.response :logger # log requests to STDOUT
|
42
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
43
|
+
end
|
44
|
+
|
45
|
+
@verify = Verify.new(conn: @conn, customer_id: opts[:customer_id], secret_key: opts[:secret_key])
|
46
|
+
@phone_id = PhoneId.new(conn: @conn, customer_id: opts[:customer_id], secret_key: opts[:secret_key])
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
@@ -5,5 +5,18 @@ module Telesignature
|
|
5
5
|
range_end = (10 ** n) - 1
|
6
6
|
Random.new.rand(range_start...range_end)
|
7
7
|
end
|
8
|
+
|
9
|
+
def validate_response response
|
10
|
+
resp_obj = JSON.load response.body
|
11
|
+
if response.status != 200
|
12
|
+
if response.status == 401
|
13
|
+
raise AuthorizationError.new resp_obj, response
|
14
|
+
else
|
15
|
+
raise TelesignError.new resp_obj, response
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
resp_obj
|
20
|
+
end
|
8
21
|
end
|
9
22
|
end
|
@@ -1,38 +1,16 @@
|
|
1
1
|
module Telesignature
|
2
|
-
class PhoneId
|
2
|
+
class PhoneId
|
3
3
|
include Helpers
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# * - Attributes
|
8
|
-
# -
|
9
|
-
# * - `customer_id`
|
10
|
-
# - A string value that identifies your TeleSign account.
|
11
|
-
# * - `secret_key`
|
12
|
-
# - A base64-encoded string value that validates your access to the TeleSign web services.
|
13
|
-
# * - `ssl`
|
14
|
-
# - Specifies whether to use a secure connection with the TeleSign server. Defaults to *true*.
|
15
|
-
# * - `api_host`
|
16
|
-
# - The Internet host used in the base URI for REST web services. The default is *rest.telesign.com* (and the base URI is https://rest.telesign.com/).
|
17
|
-
# * - `proxy_host`
|
18
|
-
# - The host and port when going through a proxy server. ex: "localhost:8080. The default to no proxy.
|
19
|
-
|
20
|
-
# .. note::
|
21
|
-
# You can obtain both your Customer ID and Secret Key from the `TeleSign Customer Portal <https://portal.telesign.com/account_profile_api_auth.php>`_.
|
22
|
-
# """
|
4
|
+
|
5
|
+
attr_accessor :conn, :customer_id, :secret_key
|
23
6
|
|
24
7
|
def initialize opts = {}
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
ssl: ((opts[:ssl].nil?) ? true : opts[:ssl]),
|
29
|
-
api_host: (opts[:api_host] || 'rest.telesign.com'),
|
30
|
-
proxy_host: (opts[:proxy_host] || nil)
|
31
|
-
)
|
8
|
+
@conn = opts[:conn]
|
9
|
+
@customer_id = opts[:customer_id]
|
10
|
+
@secret_key = opts[:secret_key]
|
32
11
|
end
|
33
12
|
|
34
13
|
def standard phone_number
|
35
|
-
# """
|
36
14
|
# Retrieves the standard set of details about the specified phone number.
|
37
15
|
# This includes the type of phone (e.g., land line or mobile),
|
38
16
|
# and it's approximate geographic location.
|
@@ -65,7 +43,6 @@ module Telesignature
|
|
65
43
|
# # for details. Data returned might be incomplete or invalid.
|
66
44
|
# ...
|
67
45
|
|
68
|
-
# """
|
69
46
|
resource = "/v1/phoneid/standard/%s" % phone_number
|
70
47
|
method = 'GET'
|
71
48
|
|
@@ -85,7 +62,6 @@ module Telesignature
|
|
85
62
|
end
|
86
63
|
|
87
64
|
def score phone_number, use_case_code
|
88
|
-
# """
|
89
65
|
# Retrieves a score for the specified phone number.
|
90
66
|
# This ranks the phone number's "risk level" on a scale from 0 to 1000,
|
91
67
|
# so you can code your web application to handle particular use cases
|
@@ -120,7 +96,6 @@ module Telesignature
|
|
120
96
|
# except TelesignError as ex:
|
121
97
|
# ...
|
122
98
|
|
123
|
-
# """
|
124
99
|
resource = "/v1/phoneid/score/%s" % phone_number
|
125
100
|
method = 'GET'
|
126
101
|
|
@@ -141,7 +116,6 @@ module Telesignature
|
|
141
116
|
end
|
142
117
|
|
143
118
|
def contact phone_number, use_case_code
|
144
|
-
# """
|
145
119
|
# In addition to the information retrieved by **standard**,
|
146
120
|
# this service provides the Name & Address associated with the specified phone number.
|
147
121
|
|
@@ -173,7 +147,6 @@ module Telesignature
|
|
173
147
|
# # for details; data returned may be incomplete or not be valid
|
174
148
|
# ...
|
175
149
|
|
176
|
-
# """
|
177
150
|
resource = "/v1/phoneid/contact/%s" % phone_number
|
178
151
|
method = 'GET'
|
179
152
|
|
@@ -194,7 +167,6 @@ module Telesignature
|
|
194
167
|
end
|
195
168
|
|
196
169
|
def live phone_number, use_case_code
|
197
|
-
# """
|
198
170
|
# In addition to the information retrieved by **standard**,
|
199
171
|
# this service provides actionable data associated with the specified phone number.
|
200
172
|
|
@@ -231,7 +203,6 @@ module Telesignature
|
|
231
203
|
# # for details; data returned may be incomplete or not be valid
|
232
204
|
# ...
|
233
205
|
|
234
|
-
# """
|
235
206
|
resource = "/v1/phoneid/live/%s" % phone_number
|
236
207
|
method = 'GET'
|
237
208
|
|
@@ -1,12 +1,7 @@
|
|
1
1
|
module Telesignature
|
2
2
|
class TelesignError < ::StandardError
|
3
|
-
# """
|
4
3
|
# The **exceptions** base class.
|
5
4
|
|
6
|
-
# .. list-table::
|
7
|
-
# :widths: 5 30
|
8
|
-
# :header-rows: 1
|
9
|
-
|
10
5
|
# * - Attributes
|
11
6
|
# -
|
12
7
|
# * - `data`
|
@@ -14,12 +9,10 @@ module Telesignature
|
|
14
9
|
# * - `http_response`
|
15
10
|
# - The full HTTP Response object, including the HTTP status code, headers, and raw returned data.
|
16
11
|
|
17
|
-
|
18
|
-
|
19
|
-
attr_accessor :errors, :headers, :status, :data, :raw_data
|
12
|
+
attr_accessor :errors, :headers, :status, :data
|
20
13
|
|
21
|
-
def initialize
|
22
|
-
@errors = errors
|
14
|
+
def initialize response_json, http_response
|
15
|
+
@errors = response_json['errors']
|
23
16
|
@headers = http_response.headers
|
24
17
|
@status = http_response.status
|
25
18
|
@data = http_response.body
|
data/lib/telesignature/verify.rb
CHANGED
@@ -1,44 +1,23 @@
|
|
1
1
|
module Telesignature
|
2
|
-
class Verify
|
2
|
+
class Verify
|
3
3
|
include Helpers
|
4
|
-
# """
|
5
|
-
# The **Verify** class exposes two services for sending users a verification token (a three to five-digit number). You can use this mechanism to simply 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.
|
6
4
|
|
7
|
-
|
5
|
+
attr_accessor :conn, :customer_id, :secret_key
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# * - Attributes
|
16
|
-
# -
|
17
|
-
# * - `customer_id`
|
18
|
-
# - A string value that identifies your TeleSign account.
|
19
|
-
# * - `secret_key`
|
20
|
-
# - A base64-encoded string value that validates your access to the TeleSign web services.
|
21
|
-
# * - `ssl`
|
22
|
-
# - Specifies whether to use a secure connection with the TeleSign server. Defaults to *true*.
|
23
|
-
# * - `api_host`
|
24
|
-
# - The Internet host used in the base URI for REST web services. The default is *rest.telesign.com* (and the base URI is https://rest.telesign.com/).
|
25
|
-
# * - `proxy_host`
|
26
|
-
# - The host and port when going through a proxy server. ex: "localhost:8080. The default to no proxy.
|
7
|
+
def initialize opts = {}
|
8
|
+
@conn = opts[:conn]
|
9
|
+
@customer_id = opts[:customer_id]
|
10
|
+
@secret_key = opts[:secret_key]
|
11
|
+
end
|
27
12
|
|
28
|
-
#
|
29
|
-
#
|
13
|
+
# The **Verify** class exposes two services for sending users a verification token (a three to five-digit number).
|
14
|
+
# You can use this mechanism to simply test whether you can reach users at the phone number they supplied,
|
15
|
+
# or you can have them use the token to authenticate themselves with your web application.
|
30
16
|
|
31
|
-
#
|
17
|
+
# This class also exposes a service that is used in conjunction with the first two services,
|
18
|
+
# in that it allows you to confirm the result of the authentication.
|
32
19
|
|
33
|
-
|
34
|
-
super(
|
35
|
-
customer_id: opts[:customer_id],
|
36
|
-
secret_key: opts[:secret_key],
|
37
|
-
ssl: ((opts[:ssl].nil?) ? true : opts[:ssl]),
|
38
|
-
api_host: (opts[:api_host] || 'rest.telesign.com'),
|
39
|
-
proxy_host: (opts[:proxy_host] || nil)
|
40
|
-
)
|
41
|
-
end
|
20
|
+
# You can use this verification factor in combination with username & password to provide two-factor authentication for higher security.
|
42
21
|
|
43
22
|
def sms opts = {}
|
44
23
|
phone_number = opts[:phone_number]
|
@@ -46,13 +25,8 @@ module Telesignature
|
|
46
25
|
language = opts[:language] || 'en-US'
|
47
26
|
template = opts[:template] || ''
|
48
27
|
|
49
|
-
# """
|
50
28
|
# Sends a text message containing the verification code, to the specified phone number (supported for mobile phones only).
|
51
29
|
|
52
|
-
# .. list-table::
|
53
|
-
# :widths: 5 30
|
54
|
-
# :header-rows: 1
|
55
|
-
|
56
30
|
# * - Parameters
|
57
31
|
# -
|
58
32
|
# * - `phone_number`
|
@@ -93,8 +67,6 @@ module Telesignature
|
|
93
67
|
# except TelesignError as ex:
|
94
68
|
# ...
|
95
69
|
|
96
|
-
# """
|
97
|
-
|
98
70
|
if verify_code.nil?
|
99
71
|
verify_code = random_with_N_digits(5)
|
100
72
|
end
|
@@ -130,13 +102,8 @@ module Telesignature
|
|
130
102
|
verify_code = opts[:verify_code]
|
131
103
|
language = opts[:language] || 'en-US'
|
132
104
|
|
133
|
-
# """
|
134
105
|
# Calls the specified phone number, and using speech synthesis, speaks the verification code to the user.
|
135
106
|
|
136
|
-
# .. list-table::
|
137
|
-
# :widths: 5 30
|
138
|
-
# :header-rows: 1
|
139
|
-
|
140
107
|
# * - Parameters
|
141
108
|
# -
|
142
109
|
# * - `phone_number`
|
@@ -176,8 +143,6 @@ module Telesignature
|
|
176
143
|
# except TelesignError as ex:
|
177
144
|
# ...
|
178
145
|
|
179
|
-
# """
|
180
|
-
|
181
146
|
if verify_code.nil?
|
182
147
|
verify_code = random_with_N_digits(5)
|
183
148
|
end
|
@@ -208,13 +173,8 @@ module Telesignature
|
|
208
173
|
end
|
209
174
|
|
210
175
|
def status ref_id, verify_code=nil
|
211
|
-
# """
|
212
176
|
# Retrieves the verification result. You make this call in your web application after users complete the authentication transaction (using either a call or sms).
|
213
177
|
|
214
|
-
# .. list-table::
|
215
|
-
# :widths: 5 30
|
216
|
-
# :header-rows: 1
|
217
|
-
|
218
178
|
# * - Parameters
|
219
179
|
# -
|
220
180
|
# * - `ref_id`
|
@@ -244,8 +204,6 @@ module Telesignature
|
|
244
204
|
# except TelesignError as ex:
|
245
205
|
# ...
|
246
206
|
|
247
|
-
# """
|
248
|
-
|
249
207
|
resource = "/v1/verify/%s" % ref_id
|
250
208
|
method = 'GET'
|
251
209
|
|
data/test/exceptions_test.rb
CHANGED
@@ -4,36 +4,34 @@ require 'telesignature'
|
|
4
4
|
|
5
5
|
class ExceptionTestTest < Minitest::Test
|
6
6
|
# Test for exceptions in telesign sdk
|
7
|
+
ExpectedHttpResponse = Struct.new('MockFaraday', :headers, :status, :body)
|
8
|
+
|
7
9
|
def setup
|
8
|
-
@expected_errors = [{code
|
9
|
-
|
10
|
+
@expected_errors = {'errors' => [ {'code' => '1', 'description' => 'Error 1'},
|
11
|
+
{'code' => '2', 'description' => 'Error 2'}]}
|
10
12
|
@expected_headers = {a: 'AA', b: 'BB'}
|
11
13
|
@expected_status = '200'
|
12
14
|
@expected_data = 'abcdefg'
|
13
15
|
|
14
|
-
@expected_http_response =
|
15
|
-
@expected_http_response[:headers] = @expected_headers
|
16
|
-
@expected_http_response[:status_code] = @expected_status
|
17
|
-
@expected_http_response[:text] = @expected_data
|
16
|
+
@expected_http_response = ExpectedHttpResponse.new( @expected_headers, @expected_status, @expected_data )
|
18
17
|
end
|
19
18
|
|
20
19
|
|
21
20
|
def validate_exception_properties x
|
22
|
-
assert_equal x.errors, @expected_errors, 'Errors property was not set on exception'
|
21
|
+
assert_equal x.errors, @expected_errors['errors'], 'Errors property was not set on exception'
|
23
22
|
assert_equal x.headers, @expected_headers, 'Headers property was not set on exception'
|
24
23
|
assert_equal x.status, @expected_status, 'Status property was not set on exception'
|
25
24
|
assert_equal x.data, @expected_data, 'Data property was not set on exception'
|
26
|
-
assert_equal x.raw_data, @expected_data, 'RawData property was not set on exception'
|
27
25
|
|
28
26
|
msg = x.message
|
29
|
-
@expected_errors.each do |err|
|
30
|
-
assert_match err[
|
27
|
+
@expected_errors['errors'].each do |err|
|
28
|
+
assert_match err['description'], msg
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
32
|
def test_properties_are_populated_in_TelesignError
|
35
33
|
begin
|
36
|
-
raise Telesignature::TelesignError.new
|
34
|
+
raise Telesignature::TelesignError.new @expected_errors, @expected_http_response
|
37
35
|
rescue Telesignature::TelesignError => x
|
38
36
|
validate_exception_properties x
|
39
37
|
end
|
data/test/phone_id_test.rb
CHANGED
@@ -30,8 +30,8 @@ class PhoneIdTest < Minitest::Test
|
|
30
30
|
with( headers: @acceptance_headers).
|
31
31
|
to_return(body: @expected_data, status: 200)
|
32
32
|
|
33
|
-
tele = Telesignature::
|
34
|
-
tele.standard @expected_phone_no
|
33
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
34
|
+
tele.phone_id.standard @expected_phone_no
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_standard_phoneid_unauthorized
|
@@ -41,10 +41,10 @@ class PhoneIdTest < Minitest::Test
|
|
41
41
|
with( headers: @acceptance_headers).
|
42
42
|
to_return(body: response_body, status: [401, 'Unauthorized'])
|
43
43
|
|
44
|
-
tele = Telesignature::
|
44
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
45
45
|
|
46
46
|
assert_raises(Telesignature::AuthorizationError){
|
47
|
-
tele.standard(@expected_phone_no)
|
47
|
+
tele.phone_id.standard(@expected_phone_no)
|
48
48
|
}
|
49
49
|
end
|
50
50
|
|
@@ -55,10 +55,10 @@ class PhoneIdTest < Minitest::Test
|
|
55
55
|
with( headers: @acceptance_headers).
|
56
56
|
to_return(body: response_body, status: [502, 'Bad Gateway'])
|
57
57
|
|
58
|
-
tele = Telesignature::
|
58
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
59
59
|
|
60
60
|
assert_raises(Telesignature::TelesignError){
|
61
|
-
tele.standard(@expected_phone_no)
|
61
|
+
tele.phone_id.standard(@expected_phone_no)
|
62
62
|
}
|
63
63
|
end
|
64
64
|
|
@@ -67,8 +67,8 @@ class PhoneIdTest < Minitest::Test
|
|
67
67
|
with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
|
68
68
|
to_return(body: @expected_data, status: 200)
|
69
69
|
|
70
|
-
tele = Telesignature::
|
71
|
-
tele.score @expected_phone_no, 'OTHR'
|
70
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
71
|
+
tele.phone_id.score @expected_phone_no, 'OTHR'
|
72
72
|
end
|
73
73
|
|
74
74
|
def test_contact_phoneid
|
@@ -76,8 +76,8 @@ class PhoneIdTest < Minitest::Test
|
|
76
76
|
with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
|
77
77
|
to_return(body: @expected_data, status: 200)
|
78
78
|
|
79
|
-
tele = Telesignature::
|
80
|
-
tele.contact @expected_phone_no, 'OTHR'
|
79
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
80
|
+
tele.phone_id.contact @expected_phone_no, 'OTHR'
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_live_phoneid
|
@@ -85,8 +85,8 @@ class PhoneIdTest < Minitest::Test
|
|
85
85
|
with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
|
86
86
|
to_return(body: @expected_data, status: 200)
|
87
87
|
|
88
|
-
tele = Telesignature::
|
89
|
-
tele.live @expected_phone_no, 'OTHR'
|
88
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
89
|
+
tele.phone_id.live @expected_phone_no, 'OTHR'
|
90
90
|
end
|
91
91
|
|
92
92
|
# # @mock.patch.object(requests, "get")
|
data/test/verify_test.rb
CHANGED
@@ -41,8 +41,8 @@ class VerifyTest < Minitest::Test
|
|
41
41
|
headers: @acceptance_headers).
|
42
42
|
to_return(body: @expected_data, status: 200)
|
43
43
|
|
44
|
-
tele = Telesignature::
|
45
|
-
tele.sms phone_number: @expected_phone_no,
|
44
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
45
|
+
tele.verify.sms phone_number: @expected_phone_no,
|
46
46
|
verify_code: @expected_verify_code,
|
47
47
|
language: @expected_language
|
48
48
|
end
|
@@ -58,11 +58,11 @@ class VerifyTest < Minitest::Test
|
|
58
58
|
headers: @acceptance_headers).
|
59
59
|
to_return(body: @expected_data, status: 200)
|
60
60
|
|
61
|
-
tele = Telesignature::
|
61
|
+
tele = Telesignature::Api.new customer_id: @expected_cid,
|
62
62
|
secret_key: @expected_secret_key,
|
63
63
|
ssl: false
|
64
64
|
|
65
|
-
tele.sms phone_number: @expected_phone_no,
|
65
|
+
tele.verify.sms phone_number: @expected_phone_no,
|
66
66
|
verify_code: @expected_verify_code,
|
67
67
|
language: @expected_language
|
68
68
|
end
|
@@ -77,8 +77,8 @@ class VerifyTest < Minitest::Test
|
|
77
77
|
headers: @acceptance_headers).
|
78
78
|
to_return(body: @expected_data, status: 200)
|
79
79
|
|
80
|
-
tele = Telesignature::
|
81
|
-
tele.call phone_number: @expected_phone_no,
|
80
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
81
|
+
tele.verify.call phone_number: @expected_phone_no,
|
82
82
|
verify_code: @expected_verify_code,
|
83
83
|
language: @expected_language
|
84
84
|
end
|
@@ -94,8 +94,8 @@ class VerifyTest < Minitest::Test
|
|
94
94
|
headers: @acceptance_headers).
|
95
95
|
to_return(body: @expected_data, status: 200)
|
96
96
|
|
97
|
-
tele = Telesignature::
|
98
|
-
tele.sms phone_number: @expected_phone_no,
|
97
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
98
|
+
tele.verify.sms phone_number: @expected_phone_no,
|
99
99
|
language: @expected_language
|
100
100
|
end
|
101
101
|
|
@@ -109,8 +109,8 @@ class VerifyTest < Minitest::Test
|
|
109
109
|
headers: @acceptance_headers).
|
110
110
|
to_return(body: @expected_data, status: 200)
|
111
111
|
|
112
|
-
tele = Telesignature::
|
113
|
-
tele.call phone_number: @expected_phone_no,
|
112
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
113
|
+
tele.verify.call phone_number: @expected_phone_no,
|
114
114
|
language: @expected_language
|
115
115
|
end
|
116
116
|
|
@@ -120,8 +120,8 @@ class VerifyTest < Minitest::Test
|
|
120
120
|
with( headers: @acceptance_headers).
|
121
121
|
to_return(body: @expected_data, status: 200)
|
122
122
|
|
123
|
-
tele = Telesignature::
|
124
|
-
tele.status @expected_ref_id
|
123
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
124
|
+
tele.verify.status @expected_ref_id
|
125
125
|
end
|
126
126
|
|
127
127
|
def test_report_code
|
@@ -131,8 +131,8 @@ class VerifyTest < Minitest::Test
|
|
131
131
|
headers: @acceptance_headers).
|
132
132
|
to_return(body: @expected_data, status: 200)
|
133
133
|
|
134
|
-
tele = Telesignature::
|
135
|
-
tele.status @expected_ref_id, @expected_verify_code
|
134
|
+
tele = Telesignature::Api.new customer_id: @expected_cid, secret_key: @expected_secret_key
|
135
|
+
tele.verify.status @expected_ref_id, @expected_verify_code
|
136
136
|
end
|
137
137
|
|
138
138
|
# # @mock.patch.object(requests, "post")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telesignature
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- README.md
|
168
168
|
- Rakefile
|
169
169
|
- lib/telesignature.rb
|
170
|
+
- lib/telesignature/api.rb
|
170
171
|
- lib/telesignature/auth.rb
|
171
172
|
- lib/telesignature/authorization_error.rb
|
172
173
|
- lib/telesignature/helpers.rb
|
@@ -175,7 +176,6 @@ files:
|
|
175
176
|
- lib/telesignature/mock_service/spin_up.rb
|
176
177
|
- lib/telesignature/phone_id.rb
|
177
178
|
- lib/telesignature/response.rb
|
178
|
-
- lib/telesignature/service_base.rb
|
179
179
|
- lib/telesignature/telesign_error.rb
|
180
180
|
- lib/telesignature/validation_error.rb
|
181
181
|
- lib/telesignature/verify.rb
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Telesignature
|
5
|
-
class ServiceBase
|
6
|
-
# attr_accessor :customer_id, :secret_key, :api_host
|
7
|
-
|
8
|
-
def initialize opts = {}
|
9
|
-
@customer_id = opts[:customer_id]
|
10
|
-
@secret_key = opts[:secret_key]
|
11
|
-
api_host = opts[:api_host]
|
12
|
-
ssl = opts[:ssl] || nil
|
13
|
-
proxy_host = opts[:proxy_host] || nil
|
14
|
-
|
15
|
-
http_root = ssl ? 'https' : 'http'
|
16
|
-
proxy = proxy_host ? "#{http_root}://#{proxy_host}" : nil
|
17
|
-
url = "#{http_root}://#{api_host}"
|
18
|
-
|
19
|
-
@conn = Faraday.new(url: url) do |faraday|
|
20
|
-
faraday.request :url_encoded
|
21
|
-
faraday.response :logger # log requests to STDOUT
|
22
|
-
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def validate_response response
|
27
|
-
resp_obj = JSON.load response.body
|
28
|
-
if response.status != 200
|
29
|
-
if response.status == 401
|
30
|
-
raise AuthorizationError.new resp_obj['errors'], response
|
31
|
-
else
|
32
|
-
raise TelesignError.new resp_obj['errors'], response
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
resp_obj
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|