telesignature 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0315db19789bbb83887daaa4591e416e0b4386a5
4
+ data.tar.gz: cbd82000f57cdbf90e40be4b5a3eea96673490ae
5
+ SHA512:
6
+ metadata.gz: fceb07c01cb4f378bf1157ca2e3efca492d81992e65c6af2c886e9a66f1abfd4d1a128dd8d69173992949e746c89af388937d9c05cedbb59f56a242ed1094e46
7
+ data.tar.gz: aa09a4204c157b1b1baa6df91370553c7abfbe84e75d9de92c779c4d1fa1af9ce88cdb6c8141a596c0fa51830ef0430832dd1af80328ca1559804b1d9b59d336
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.pryrc ADDED
@@ -0,0 +1,6 @@
1
+ if defined?(PryDebugger)
2
+ Pry.commands.alias_command 'c', 'continue'
3
+ Pry.commands.alias_command 's', 'step'
4
+ Pry.commands.alias_command 'n', 'next'
5
+ Pry.commands.alias_command 'f', 'finish'
6
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in telesign.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ telesignature (0.0.2)
5
+ faraday
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.5)
11
+ celluloid (0.15.2)
12
+ timers (~> 1.1.0)
13
+ coderay (1.0.9)
14
+ columnize (0.3.6)
15
+ crack (0.4.1)
16
+ safe_yaml (~> 0.9.0)
17
+ debugger (1.6.2)
18
+ columnize (>= 0.3.1)
19
+ debugger-linecache (~> 1.2.0)
20
+ debugger-ruby_core_source (~> 1.2.3)
21
+ debugger-linecache (1.2.0)
22
+ debugger-ruby_core_source (1.2.3)
23
+ faraday (0.9.0)
24
+ multipart-post (>= 1.2, < 3)
25
+ ffi (1.9.3)
26
+ formatador (0.2.4)
27
+ guard (2.2.3)
28
+ formatador (>= 0.2.4)
29
+ listen (~> 2.1)
30
+ lumberjack (~> 1.0)
31
+ pry (>= 0.9.12)
32
+ thor (>= 0.18.1)
33
+ guard-minitest (2.2.0)
34
+ guard (~> 2.0)
35
+ minitest (>= 3.0)
36
+ listen (2.2.0)
37
+ celluloid (>= 0.15.2)
38
+ rb-fsevent (>= 0.9.3)
39
+ rb-inotify (>= 0.9)
40
+ lumberjack (1.0.4)
41
+ method_source (0.8.2)
42
+ minitest (5.2.3)
43
+ multipart-post (2.0.0)
44
+ pry (0.9.12.2)
45
+ coderay (~> 1.0.5)
46
+ method_source (~> 0.8)
47
+ slop (~> 3.4)
48
+ pry-debugger (0.2.2)
49
+ debugger (~> 1.3)
50
+ pry (~> 0.9.10)
51
+ rake (10.1.1)
52
+ rb-fsevent (0.9.3)
53
+ rb-inotify (0.9.2)
54
+ ffi (>= 0.5.0)
55
+ safe_yaml (0.9.7)
56
+ slop (3.4.6)
57
+ thor (0.18.1)
58
+ timers (1.1.0)
59
+ webmock (1.12.0)
60
+ addressable (>= 2.2.7)
61
+ crack (>= 0.3.2)
62
+
63
+ PLATFORMS
64
+ ruby
65
+
66
+ DEPENDENCIES
67
+ bundler (~> 1.3)
68
+ guard
69
+ guard-minitest
70
+ minitest
71
+ pry
72
+ pry-debugger
73
+ rake
74
+ telesignature!
75
+ webmock
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ # with Minitest::Unit
6
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
7
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[2]}_test.rb" }
8
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
9
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 TeleSign Corp.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Andy Koch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ telesign
2
+ =============
3
+
4
+ Ruby TeleSign SDK
5
+
6
+ Coming soon ...
7
+
8
+ Don't want to wait? Fork it!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,67 @@
1
+ # Authorization header definitions
2
+
3
+ require 'securerandom'
4
+ require 'base64'
5
+ require 'uri'
6
+ require 'openssl'
7
+
8
+ # __author__ = "Jeremy Cunningham, Michael Fox, and Radu Maierean"
9
+ # __copyright__ = "Copyright 2012, TeleSign Corp."
10
+ # __credits__ = ["Jeremy Cunningham", "Radu Maierean", "Michael Fox", "Nancy Vitug", "Humberto Morales"]
11
+ # __license__ = "MIT"
12
+ # __maintainer__ = "Jeremy Cunningham"
13
+ # __email__ = "support@telesign.com"
14
+ # __status__ = ""
15
+
16
+ AUTH_METHOD = {
17
+ sha1: {hash: OpenSSL::Digest::SHA1, name: 'HMAC-SHA1'},
18
+ sha256: {hash: OpenSSL::Digest::SHA256, name: 'HMAC-SHA256'}
19
+ }
20
+
21
+ module Telesignature
22
+ class Auth
23
+ def self.generate_auth_headers(opts = {})
24
+ content_type = opts[:content_type] ? opts[:content_type] : ''
25
+ auth_method = opts[:auth_method] ? opts[:auth_method] : :sha1
26
+ fields = opts[:fields] ? opts[:fields] : nil
27
+
28
+ customer_id = opts[:customer_id]
29
+ secret_key = opts[:secret_key]
30
+ resource = opts[:resource]
31
+ method = opts[:method]
32
+
33
+ current_date = Time.now.strftime("%a, %d %b %Y %H:%M:%S %z")
34
+ nonce = SecureRandom.uuid
35
+
36
+ if %w(POST PUT).include? method
37
+ content_type = "application/x-www-form-urlencoded"
38
+ end
39
+
40
+ string_to_sign = "%s\n%s\n\nx-ts-auth-method:%s\nx-ts-date:%s\nx-ts-nonce:%s" % [
41
+ method,
42
+ content_type,
43
+ AUTH_METHOD[auth_method][:name],
44
+ current_date,
45
+ nonce]
46
+
47
+ if fields
48
+ string_to_sign += "\n%s" % URI.encode_www_form(fields)
49
+ end
50
+
51
+ string_to_sign += "\n%s" % resource
52
+
53
+ digest = AUTH_METHOD[auth_method][:hash].new
54
+ signer = OpenSSL::HMAC.digest digest, Base64.decode64(secret_key), string_to_sign
55
+
56
+ signature = Base64.encode64 signer
57
+
58
+ {
59
+ 'Authorization' => "TSA %s:%s" % [customer_id, signature],
60
+ 'x-ts-date' => current_date,
61
+ 'x-ts-auth-method' => AUTH_METHOD[auth_method][:name],
62
+ 'x-ts-nonce' => nonce
63
+ }
64
+ end
65
+ end
66
+ end
67
+
@@ -0,0 +1,23 @@
1
+ module Telesignature
2
+ class AuthorizationError < TelesignError
3
+ # """
4
+ # Either the client failed to authenticate with the REST API server, or the service cannot be executed using the specified credentials.
5
+
6
+ # .. list-table::
7
+ # :widths: 5 30
8
+ # :header-rows: 1
9
+
10
+ # * - Attributes
11
+ # -
12
+ # * - `data`
13
+ # - The data returned by the service, in a dictionary form.
14
+ # * - `http_response`
15
+ # - The full HTTP Response object, including the HTTP status code, headers, and raw returned data.
16
+
17
+ # """
18
+
19
+ def initialize errors, http_response
20
+ super
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Telesignature
2
+ module Helpers
3
+ def random_with_N_digits n
4
+ range_start = 10 ** (n - 1)
5
+ range_end = (10 ** n) - 1
6
+ Random.new.rand(range_start...range_end)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,324 @@
1
+ module Telesignature
2
+ class PhoneId < ServiceBase
3
+ include Helpers
4
+ # """
5
+ # The **PhoneId** class exposes three services that each provide detailed information about a specified phone number.
6
+
7
+ # .. list-table::
8
+ # :widths: 5 30
9
+ # :header-rows: 1
10
+
11
+ # * - Attributes
12
+ # -
13
+ # * - `customer_id`
14
+ # - A string value that identifies your TeleSign account.
15
+ # * - `secret_key`
16
+ # - A base64-encoded string value that validates your access to the TeleSign web services.
17
+ # * - `ssl`
18
+ # - Specifies whether to use a secure connection with the TeleSign server. Defaults to *true*.
19
+ # * - `api_host`
20
+ # - 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/).
21
+ # * - `proxy_host`
22
+ # - The host and port when going through a proxy server. ex: "localhost:8080. The default to no proxy.
23
+
24
+ # .. note::
25
+ # You can obtain both your Customer ID and Secret Key from the `TeleSign Customer Portal <https://portal.telesign.com/account_profile_api_auth.php>`_.
26
+ # """
27
+
28
+ def initialize opts = {}
29
+ super(
30
+ customer_id: opts[:customer_id],
31
+ secret_key: opts[:secret_key],
32
+ ssl: (opts[:ssl] || true),
33
+ api_host: (opts[:api_host] || 'rest.telesign.com'),
34
+ proxy_host: (opts[:proxy_host] || nil)
35
+ )
36
+ end
37
+
38
+ def standard phone_number
39
+ # """
40
+ # Retrieves the standard set of details about the specified phone number. This includes the type of phone (e.g., land line or mobile), and it's approximate geographic location.
41
+
42
+ # .. list-table::
43
+ # :widths: 5 30
44
+ # :header-rows: 1
45
+
46
+ # * - Parameters
47
+ # -
48
+ # * - `phone_number`
49
+ # - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
50
+
51
+ # **Example**::
52
+
53
+ # from telesign.api import PhoneId
54
+ # from telesign.exceptions import AuthorizationError, TelesignError
55
+
56
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
57
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
58
+ # phone_number = "13107409700"
59
+
60
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
61
+
62
+ # try:
63
+ # phone_info = phoneid.standard(phone_number)
64
+
65
+ # except AuthorizationError as ex:
66
+ # # API authorization failed. Check the API response for details.
67
+ # ...
68
+
69
+ # except TelesignError as ex:
70
+ # # Failed to completely execute the PhoneID service. Check the API response
71
+ # # for details. Data returned might be incomplete or invalid.
72
+ # ...
73
+
74
+ # """
75
+ resource = "/v1/phoneid/standard/%s" % phone_number
76
+ method = 'GET'
77
+
78
+ headers = Telesignature::Auth.generate_auth_headers(
79
+ customer_id: @customer_id,
80
+ secret_key: @secret_key,
81
+ resource: resource,
82
+ method: method)
83
+
84
+ response = @conn.get do |req|
85
+ req.url resource
86
+ req.headers = headers
87
+ # proxies=@proxy
88
+ end
89
+
90
+ return Telesignature::Response.new validate_response(response), response
91
+ end
92
+
93
+ def score phone_number, use_case_code
94
+ # """
95
+ # 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 (e.g., to stop things like chargebacks, identity theft, fraud, and spam).
96
+
97
+ # .. list-table::
98
+ # :widths: 5 30
99
+ # :header-rows: 1
100
+
101
+ # * - Parameters
102
+ # -
103
+ # * - `phone_number`
104
+ # - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
105
+ # * - `use_case_code`
106
+ # - A four letter code used to specify a particular usage scenario for the web service.
107
+
108
+ # .. rubric:: Use-case Codes
109
+
110
+ # The following table list the available use-case codes, and includes a description of each.
111
+
112
+ # ======== =====================================
113
+ # Code Description
114
+ # ======== =====================================
115
+ # **BACS** Prevent bulk account creation + spam.
116
+ # **BACF** Prevent bulk account creation + fraud.
117
+ # **CHBK** Prevent chargebacks.
118
+ # **ATCK** Prevent account takeover/compromise.
119
+ # **LEAD** Prevent false lead entry.
120
+ # **RESV** Prevent fake/missed reservations.
121
+ # **PWRT** Password reset.
122
+ # **THEF** Prevent identity theft.
123
+ # **TELF** Prevent telecom fraud.
124
+ # **RXPF** Prevent prescription fraud.
125
+ # **OTHR** Other.
126
+ # **UNKN** Unknown/prefer not to say.
127
+ # ======== =====================================
128
+
129
+ # **Example**::
130
+
131
+ # from telesign.api import PhoneId
132
+ # from telesign.exceptions import AuthorizationError, TelesignError
133
+
134
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
135
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
136
+ # phone_number = "13107409700"
137
+ # use_case_code = "ATCK"
138
+
139
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
140
+
141
+ # try:
142
+ # score_info = phoneid.score(phone_number, use_case_code)
143
+ # except AuthorizationError as ex:
144
+ # ...
145
+ # except TelesignError as ex:
146
+ # ...
147
+
148
+ # """
149
+ resource = "/v1/phoneid/score/%s" % phone_number
150
+ method = 'GET'
151
+
152
+ headers = Telesignature::Auth.generate_auth_headers(
153
+ customer_id: @customer_id,
154
+ secret_key: @secret_key,
155
+ resource: resource,
156
+ method: method)
157
+
158
+ response = @conn.get do |req|
159
+ req.url resource
160
+ req.params[:ucid] = use_case_code
161
+ req.headers = headers
162
+ # proxies=@proxy
163
+ end
164
+
165
+ return Telesignature::Response.new validate_response(response), response
166
+ end
167
+
168
+ def contact phone_number, use_case_code
169
+ # """
170
+ # In addition to the information retrieved by **standard**, this service provides the Name & Address associated with the specified phone number.
171
+
172
+ # .. list-table::
173
+ # :widths: 5 30
174
+ # :header-rows: 1
175
+
176
+ # * - Parameters
177
+ # -
178
+ # * - `phone_number`
179
+ # - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
180
+ # * - `use_case_code`
181
+ # - A four letter code used to specify a particular usage scenario for the web service.
182
+
183
+ # .. rubric:: Use-case Codes
184
+
185
+ # The following table list the available use-case codes, and includes a description of each.
186
+
187
+ # ======== =====================================
188
+ # Code Description
189
+ # ======== =====================================
190
+ # **BACS** Prevent bulk account creation + spam.
191
+ # **BACF** Prevent bulk account creation + fraud.
192
+ # **CHBK** Prevent chargebacks.
193
+ # **ATCK** Prevent account takeover/compromise.
194
+ # **LEAD** Prevent false lead entry.
195
+ # **RESV** Prevent fake/missed reservations.
196
+ # **PWRT** Password reset.
197
+ # **THEF** Prevent identity theft.
198
+ # **TELF** Prevent telecom fraud.
199
+ # **RXPF** Prevent prescription fraud.
200
+ # **OTHR** Other.
201
+ # **UNKN** Unknown/prefer not to say.
202
+ # ======== =====================================
203
+
204
+ # **Example**::
205
+
206
+ # from telesign.api import PhoneId
207
+ # from telesign.exceptions import AuthorizationError, TelesignError
208
+
209
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
210
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
211
+ # phone_number = "13107409700"
212
+ # use_case_code = "LEAD"
213
+
214
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
215
+
216
+ # try:
217
+ # phone_info = phoneid.contact(phone_number, use_case_code)
218
+ # except AuthorizationError as ex:
219
+ # # API authorization failed, the API response should tell you the reason
220
+ # ...
221
+ # except TelesignError as ex:
222
+ # # failed to completely execute the PhoneID service, check the API response
223
+ # # for details; data returned may be incomplete or not be valid
224
+ # ...
225
+
226
+ # """
227
+ resource = "/v1/phoneid/contact/%s" % phone_number
228
+ method = 'GET'
229
+
230
+ headers = Telesignature::Auth.generate_auth_headers(
231
+ customer_id: @customer_id,
232
+ secret_key: @secret_key,
233
+ resource: resource,
234
+ method: method)
235
+
236
+ response = @conn.get do |req|
237
+ req.url resource
238
+ req.params[:ucid] = use_case_code
239
+ req.headers = headers
240
+ # proxies=@proxy
241
+ end
242
+
243
+ return Telesignature::Response.new validate_response(response), response
244
+ end
245
+
246
+ def live phone_number, use_case_code
247
+ # """
248
+ # In addition to the information retrieved by **standard**, this service provides actionable data associated with the specified phone number.
249
+
250
+ # .. list-table::
251
+ # :widths: 5 30
252
+ # :header-rows: 1
253
+
254
+ # * - Parameters
255
+ # -
256
+ # * - `phone_number`
257
+ # - The phone number you want details about. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212.
258
+ # * - `use_case_code`
259
+ # - A four letter code used to specify a particular usage scenario for the web service.
260
+
261
+ # .. rubric:: Use-case Codes
262
+
263
+ # The following table list the available use-case codes, and includes a description of each.
264
+
265
+ # ======== =====================================
266
+ # Code Description
267
+ # ======== =====================================
268
+ # **BACS** Prevent bulk account creation + spam.
269
+ # **BACF** Prevent bulk account creation + fraud.
270
+ # **CHBK** Prevent chargebacks.
271
+ # **ATCK** Prevent account takeover/compromise.
272
+ # **LEAD** Prevent false lead entry.
273
+ # **RESV** Prevent fake/missed reservations.
274
+ # **PWRT** Password reset.
275
+ # **THEF** Prevent identity theft.
276
+ # **TELF** Prevent telecom fraud.
277
+ # **RXPF** Prevent prescription fraud.
278
+ # **OTHR** Other.
279
+ # **UNKN** Unknown/prefer not to say.
280
+ # ======== =====================================
281
+
282
+ # **Example**::
283
+
284
+ # from telesign.api import PhoneId
285
+ # from telesign.exceptions import AuthorizationError, TelesignError
286
+
287
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
288
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
289
+ # phone_number = "13107409700"
290
+ # use_case_code = "RXPF"
291
+
292
+ # phoneid = PhoneId(cust_id, secret_key) # Instantiate a PhoneId object.
293
+
294
+ # try:
295
+ # phone_info = phoneid.live(phone_number, use_case_code)
296
+ # except AuthorizationError as ex:
297
+ # # API authorization failed, the API response should tell you the reason
298
+ # ...
299
+ # except TelesignError as ex:
300
+ # # failed to completely execute the PhoneID service, check the API response
301
+ # # for details; data returned may be incomplete or not be valid
302
+ # ...
303
+
304
+ # """
305
+ resource = "/v1/phoneid/live/%s" % phone_number
306
+ method = 'GET'
307
+
308
+ headers = Telesignature::Auth.generate_auth_headers(
309
+ customer_id: @customer_id,
310
+ secret_key: @secret_key,
311
+ resource: resource,
312
+ method: method)
313
+
314
+ response = @conn.get do |req|
315
+ req.url resource
316
+ req.params[:ucid] = use_case_code
317
+ req.headers = headers
318
+ # proxies=@proxy
319
+ end
320
+
321
+ return Telesignature::Response.new validate_response(response), response
322
+ end
323
+ end
324
+ end
@@ -0,0 +1,13 @@
1
+ module Telesignature
2
+ class Response
3
+ attr_accessor :data, :headers, :status, :raw_data, :verify_code
4
+
5
+ def initialize data, http_response, verify_code=nil
6
+ @data = data
7
+ @headers = http_response.headers
8
+ @status = http_response.status
9
+ @raw_data = http_response.body
10
+ @verify_code = verify_code
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
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, response
31
+ else
32
+ raise TelesignError.new resp_obj, response
33
+ end
34
+ end
35
+
36
+ resp_obj
37
+ end
38
+ end
39
+ end