telesignature 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,34 @@
1
+ module Telesignature
2
+ class TelesignError < ::StandardError
3
+ # """
4
+ # The **exceptions** base class.
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
+ attr_accessor :errors, :headers, :status, :data, :raw_data
20
+
21
+ def initialize errors, http_response
22
+ @errors = errors
23
+ @headers = http_response[:headers]
24
+ @status = http_response[:status_code]
25
+ @data = http_response[:text]
26
+ @raw_data = http_response[:text]
27
+ super()
28
+ end
29
+
30
+ def to_s
31
+ @errors.inject(''){|ret, x| ret += "%s\n" % x[:description] }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Telesignature
2
+ class ValidationError < TelesignError
3
+ # """
4
+ # The submitted data failed the intial validation, and the service was not executed.
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,273 @@
1
+ module Telesignature
2
+ class Verify < ServiceBase
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
+
7
+ # This class also exposes a service that is used in conjunction with the first two services, in that it allows you to confirm the result of the authentication.
8
+
9
+ # You can use this verification factor in combination with username & password to provide two-factor authentication for higher security.
10
+
11
+ # .. list-table::
12
+ # :widths: 5 30
13
+ # :header-rows: 1
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.
27
+
28
+ # .. note::
29
+ # You can obtain both your Customer ID and Secret Key from the `TeleSign Customer Portal <https://portal.telesign.com/account_profile_api_auth.php>`_.
30
+
31
+ # """
32
+
33
+ def initialize opts = {}
34
+ super(
35
+ customer_id: opts[:customer_id],
36
+ secret_key: opts[:secret_key],
37
+ ssl: (opts[:ssl] || true),
38
+ api_host: (opts[:api_host] || 'rest.telesign.com'),
39
+ proxy_host: (opts[:proxy_host] || nil)
40
+ )
41
+ end
42
+
43
+ def sms opts = {}
44
+ phone_number = opts[:phone_number]
45
+ verify_code = opts[:verify_code]
46
+ language = opts[:language] || 'en-US'
47
+ template = opts[:template] || ''
48
+
49
+ # """
50
+ # Sends a text message containing the verification code, to the specified phone number (supported for mobile phones only).
51
+
52
+ # .. list-table::
53
+ # :widths: 5 30
54
+ # :header-rows: 1
55
+
56
+ # * - Parameters
57
+ # -
58
+ # * - `phone_number`
59
+ # - The phone number to receive the text message. 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.
60
+ # * - `verify_code`
61
+ # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you.
62
+ # * - `language`
63
+ # - (optional) The written language used in the message. The default is English.
64
+ # * - `template`
65
+ # - (optional) A standard form for the text message. It must contain the token ``$$CODE$$``, which TeleSign auto-populates with the verification code.
66
+
67
+ # **Example**::
68
+
69
+ # from telesign.api import Verify
70
+ # from telesign.exceptions import AuthorizationError, TelesignError
71
+
72
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
73
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
74
+ # phone_number = "13107409700"
75
+
76
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
77
+
78
+ # try:
79
+ # phone_info = verify.sms(phone_number)
80
+ # except AuthorizationError as ex:
81
+ # # API authorization failed, the API response should tell you the reason
82
+ # ...
83
+ # except TelesignError as ex:
84
+ # # failed to execute the Verify service, check the API response for details
85
+ # ...
86
+
87
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
88
+ # if (phone_info != None):
89
+ # try:
90
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
91
+ # except AuthorizationError as ex:
92
+ # ...
93
+ # except TelesignError as ex:
94
+ # ...
95
+
96
+ # """
97
+
98
+ if verify_code.nil?
99
+ verify_code = random_with_N_digits(5)
100
+ end
101
+
102
+ resource = '/v1/verify/sms'
103
+ method = 'POST'
104
+
105
+ fields = {
106
+ phone_number: phone_number,
107
+ language: language,
108
+ verify_code: verify_code,
109
+ template: template}
110
+
111
+ headers = Telesignature::Auth.generate_auth_headers(
112
+ customer_id: @customer_id,
113
+ secret_key: @secret_key,
114
+ resource: resource,
115
+ method: method,
116
+ fields: fields)
117
+
118
+ response = @conn.post do |req|
119
+ req.url resource
120
+ req.body = fields
121
+ req.headers = headers
122
+ # proxies=@proxy
123
+ end
124
+
125
+ return Telesignature::Response.new validate_response(response), response, verify_code
126
+ end
127
+
128
+ def call opts = {}
129
+ phone_number = opts[:phone_number]
130
+ verify_code = opts[:verify_code]
131
+ language = opts[:language] || 'en-US'
132
+
133
+ # """
134
+ # Calls the specified phone number, and using speech synthesis, speaks the verification code to the user.
135
+
136
+ # .. list-table::
137
+ # :widths: 5 30
138
+ # :header-rows: 1
139
+
140
+ # * - Parameters
141
+ # -
142
+ # * - `phone_number`
143
+ # - The phone number to receive the text message. 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.
144
+ # * - `verify_code`
145
+ # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you.
146
+ # * - `language`
147
+ # - (optional) The written language used in the message. The default is English.
148
+
149
+
150
+ # **Example**::
151
+
152
+ # from telesign.api import Verify
153
+ # from telesign.exceptions import AuthorizationError, TelesignError
154
+
155
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
156
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
157
+ # phone_number = "13107409700"
158
+
159
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
160
+
161
+ # try:
162
+ # phone_info = verify.call(phone_number)
163
+ # except AuthorizationError as ex:
164
+ # # API authorization failed, the API response should tell you the reason
165
+ # ...
166
+ # except TelesignError as ex:
167
+ # # failed to execute the Verify service, check the API response for details
168
+ # ...
169
+
170
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
171
+ # if (phone_info != None):
172
+ # try:
173
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
174
+ # except AuthorizationError as ex:
175
+ # ...
176
+ # except TelesignError as ex:
177
+ # ...
178
+
179
+ # """
180
+
181
+ if verify_code.nil?
182
+ verify_code = random_with_N_digits(5)
183
+ end
184
+
185
+ resource = '/v1/verify/call'
186
+ method = 'POST'
187
+
188
+ fields = {
189
+ phone_number: phone_number,
190
+ language: language,
191
+ verify_code: verify_code}
192
+
193
+ headers = Telesignature::Auth.generate_auth_headers(
194
+ customer_id: @customer_id,
195
+ secret_key: @secret_key,
196
+ resource: resource,
197
+ method: method,
198
+ fields: fields)
199
+
200
+ response = @conn.post do |req|
201
+ req.url resource
202
+ req.body = fields
203
+ req.headers = headers
204
+ # proxies=@proxy
205
+ end
206
+
207
+ return Telesignature::Response.new validate_response(response), response, verify_code
208
+ end
209
+
210
+ def status ref_id, verify_code=nil
211
+ # """
212
+ # 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
+
214
+ # .. list-table::
215
+ # :widths: 5 30
216
+ # :header-rows: 1
217
+
218
+ # * - Parameters
219
+ # -
220
+ # * - `ref_id`
221
+ # - The Reference ID returned in the response from the TeleSign server, after you called either **call** or **sms**.
222
+ # * - `verify_code`
223
+ # - The verification code received from the user.
224
+
225
+ # **Example**::
226
+
227
+ # from telesign.api import Verify
228
+ # from telesign.exceptions import AuthorizationError, TelesignError
229
+
230
+ # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890"
231
+ # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw=="
232
+ # phone_number = "13107409700"
233
+
234
+ # verify = Verify(cust_id, secret_key) # Instantiate a Verify object.
235
+
236
+ # phone_info = verify.sms(phone_number) # Send a text message that contains an auto-generated validation code, to the user.
237
+
238
+ # # When the user inputs the validation code, you can verify that it matches the one that you sent.
239
+ # if (phone_info != None):
240
+ # try:
241
+ # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code)
242
+ # except AuthorizationError as ex:
243
+ # ...
244
+ # except TelesignError as ex:
245
+ # ...
246
+
247
+ # """
248
+
249
+ resource = "/v1/verify/%s" % ref_id
250
+ method = 'GET'
251
+
252
+ headers = Telesignature::Auth.generate_auth_headers(
253
+ customer_id: @customer_id,
254
+ secret_key: @secret_key,
255
+ resource: resource,
256
+ method: method)
257
+
258
+ fields = nil
259
+ if !verify_code.nil?
260
+ fields = {verify_code: verify_code}
261
+ end
262
+
263
+ response = @conn.get do |req|
264
+ req.url resource
265
+ fields.each{|k,v| req.params[k] = v} if fields
266
+ req.headers = headers
267
+ # proxies=@proxy
268
+ end
269
+
270
+ return Telesignature::Response.new validate_response(response), response
271
+ end
272
+ end
273
+ end
@@ -0,0 +1,3 @@
1
+ module Telesignature
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,13 @@
1
+ require 'telesignature/version'
2
+
3
+ module Telesignature
4
+ autoload :TelesignError, 'telesignature/telesign_error'
5
+ autoload :AuthorizationError, 'telesignature/authorization_error'
6
+ autoload :ValidationError, 'telesignature/validation_error'
7
+ autoload :Auth, 'telesignature/auth'
8
+ autoload :Response, 'telesignature/response'
9
+ autoload :Helpers, 'telesignature/helpers'
10
+ autoload :ServiceBase, 'telesignature/service_base'
11
+ autoload :Verify, 'telesignature/verify'
12
+ autoload :PhoneId, 'telesignature/phone_id'
13
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'telesignature/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'telesignature'
8
+ spec.version = Telesignature::VERSION
9
+ spec.authors = ['Andy Koch']
10
+ spec.email = ['akoch@practicefusion.com']
11
+ spec.description = %q{Client gem for Telesign REST API}
12
+ spec.summary = %q{Client gem for Telesign REST API}
13
+ spec.homepage = 'https://github.com/practicefusion/telesignature'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.test_files = spec.files.grep(%r{^(test)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'faraday'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'minitest'
25
+ spec.add_development_dependency 'webmock'
26
+ spec.add_development_dependency 'guard'
27
+ spec.add_development_dependency 'guard-minitest'
28
+ spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'pry-debugger'
30
+ end
data/test/auth_test.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+ require 'telesignature'
4
+
5
+ class TestAuth < Minitest::Test
6
+ def setup
7
+ @expected_cid = '99999999-1F7E-11E1-B760-000000000000'
8
+ @expected_secret_key = '8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M=='
9
+ @expected_resource = '/foo/bar/baz/'
10
+ end
11
+
12
+ def test_headers_are_set_on_get
13
+ Telesignature::Auth.generate_auth_headers(
14
+ customer_id: @expected_cid,
15
+ secret_key: @expected_secret_key,
16
+ resource: @expected_resource,
17
+ method: 'GET')
18
+ end
19
+
20
+ def test_nonce_is_set
21
+ expected_nonce = '1234'
22
+
23
+ headers = SecureRandom.stub :uuid, expected_nonce do
24
+ Telesignature::Auth.generate_auth_headers(
25
+ customer_id: @expected_cid,
26
+ secret_key: @expected_secret_key,
27
+ resource: @expected_resource,
28
+ method: 'GET')
29
+ end
30
+
31
+ assert_equal headers['x-ts-nonce'], expected_nonce
32
+ end
33
+
34
+ def test_date_is_set
35
+ headers = Telesignature::Auth.generate_auth_headers(
36
+ customer_id: @expected_cid,
37
+ secret_key: @expected_secret_key,
38
+ resource: @expected_resource,
39
+ method: 'GET')
40
+
41
+ # Can't mock datetime
42
+ refute_match headers['x-ts-date'], nil
43
+ end
44
+
45
+ def test_sha1_default_auth_method
46
+ expected_auth_method = 'HMAC-SHA1'
47
+
48
+ headers = Telesignature::Auth.generate_auth_headers(
49
+ customer_id: @expected_cid,
50
+ secret_key: @expected_secret_key,
51
+ resource: @expected_resource,
52
+ method: 'GET')
53
+
54
+ assert_equal headers['x-ts-auth-method'], expected_auth_method, 'Auth method did not match'
55
+ end
56
+
57
+ def test_sha256_auth_method
58
+ expected_auth_method = 'HMAC-SHA256'
59
+
60
+ headers = Telesignature::Auth.generate_auth_headers(
61
+ customer_id: @expected_cid,
62
+ secret_key: @expected_secret_key,
63
+ resource: @expected_resource,
64
+ method: 'GET',
65
+ auth_method: :sha256)
66
+
67
+ assert_equal headers['x-ts-auth-method'], expected_auth_method, 'Auth method did not match'
68
+ end
69
+
70
+ def test_customer_id_in_auth
71
+ expected_auth_start = "TSA %s:" % @expected_cid
72
+
73
+ headers = Telesignature::Auth.generate_auth_headers(
74
+ customer_id: @expected_cid,
75
+ secret_key: @expected_secret_key,
76
+ resource: @expected_resource,
77
+ method: 'GET')
78
+
79
+ assert_match /^#{expected_auth_start}/, headers['Authorization'], 'Authorization did not start with TSA and customer ID'
80
+ end
81
+ end
@@ -0,0 +1,57 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+ require 'telesignature'
4
+
5
+ class ExceptionTestTest < Minitest::Test
6
+ # Test for exceptions in telesign sdk
7
+ def setup
8
+ @expected_errors = [{code: 1, description: 'Error 1'},
9
+ {code: 2, description: 'Error 2'}]
10
+ @expected_headers = {a: 'AA', b: 'BB'}
11
+ @expected_status = '200'
12
+ @expected_data = 'abcdefg'
13
+
14
+ @expected_http_response = Hash.new
15
+ @expected_http_response[:headers] = @expected_headers
16
+ @expected_http_response[:status_code] = @expected_status
17
+ @expected_http_response[:text] = @expected_data
18
+ end
19
+
20
+
21
+ def validate_exception_properties x
22
+ assert_equal x.errors, @expected_errors, 'Errors property was not set on exception'
23
+ assert_equal x.headers, @expected_headers, 'Headers property was not set on exception'
24
+ assert_equal x.status, @expected_status, 'Status property was not set on exception'
25
+ 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
+
28
+ msg = x.message
29
+ @expected_errors.each do |err|
30
+ assert_match err[:description], msg
31
+ end
32
+ end
33
+
34
+ def test_properties_are_populated_in_TelesignError
35
+ begin
36
+ raise Telesignature::TelesignError.new( @expected_errors, @expected_http_response )
37
+ rescue Telesignature::TelesignError => x
38
+ validate_exception_properties x
39
+ end
40
+ end
41
+
42
+ def test_properties_are_populated_in_AuthorizationError
43
+ begin
44
+ raise Telesignature::AuthorizationError.new @expected_errors, @expected_http_response
45
+ rescue Telesignature::AuthorizationError => x
46
+ validate_exception_properties x
47
+ end
48
+ end
49
+
50
+ def test_properties_are_populated_in_ValidationError
51
+ begin
52
+ raise Telesignature::ValidationError.new @expected_errors, @expected_http_response
53
+ rescue Telesignature::ValidationError => x
54
+ validate_exception_properties(x)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,159 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+ require 'telesignature'
4
+ require 'webmock/minitest'
5
+
6
+
7
+ class PhoneIdTest < Minitest::Test
8
+ # Test for phone id telesign sdk
9
+
10
+ def setup
11
+ @expected_cid = '99999999-1F7E-11E1-B760-000000000000'
12
+ @expected_secret_key = '8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M8M=='
13
+ @expected_phone_no = '12343455678'
14
+ @expected_data = '{ "a":"AA", "b":"BB" }'
15
+ @expected_resource = "https://rest.telesign.com/v1/phoneid/%s/%s"
16
+ @proxy = 'localhost:8080'
17
+ @expected_proxy = 'https://localhost:8080'
18
+
19
+ @acceptance_headers = { 'Accept' => /.*/,
20
+ 'Accept-Encoding' => /.*/,
21
+ 'Authorization' => /.*/,
22
+ 'User-Agent' => /.*/,
23
+ 'X-Ts-Auth-Method' => /.*/,
24
+ 'X-Ts-Date'=> /.*/,
25
+ 'X-Ts-Nonce' => /.*/}
26
+ end
27
+
28
+ def test_standard_phoneid
29
+ stub_request(:get, @expected_resource % ['standard', @expected_phone_no]).
30
+ with( headers: @acceptance_headers).
31
+ to_return(body: @expected_data, status: 200)
32
+
33
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
34
+ p.standard @expected_phone_no
35
+ end
36
+
37
+ def test_standard_phoneid_unauthorized
38
+ response_body = '{ "a":"AA", "b":"BB", "errors": { "code":"401", "description":"Unauthorized" } }'
39
+
40
+ stub_request(:get, @expected_resource % ['standard', @expected_phone_no]).
41
+ with( headers: @acceptance_headers).
42
+ to_return(body: response_body, status: [401, 'Unauthorized'])
43
+
44
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
45
+
46
+ assert_raises(Telesignature::AuthorizationError){
47
+ p.standard(@expected_phone_no)
48
+ }
49
+ end
50
+
51
+ def test_standard_phoneid_other_error
52
+ response_body = '{ "a":"AA", "b":"BB", "errors": { "code":"502", "description":"Bad Gateway" } }'
53
+
54
+ stub_request(:get, @expected_resource % ['standard', @expected_phone_no]).
55
+ with( headers: @acceptance_headers).
56
+ to_return(body: response_body, status: [502, 'Bad Gateway'])
57
+
58
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
59
+
60
+ assert_raises(Telesignature::TelesignError){
61
+ p.standard(@expected_phone_no)
62
+ }
63
+ end
64
+
65
+ def test_score_phoneid
66
+ stub_request(:get, @expected_resource % ['score', @expected_phone_no]).
67
+ with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
68
+ to_return(body: @expected_data, status: 200)
69
+
70
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
71
+ p.score @expected_phone_no, 'OTHR'
72
+ end
73
+
74
+ def test_contact_phoneid
75
+ stub_request(:get, @expected_resource % ['contact', @expected_phone_no]).
76
+ with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
77
+ to_return(body: @expected_data, status: 200)
78
+
79
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
80
+ p.contact @expected_phone_no, 'OTHR'
81
+ end
82
+
83
+ def test_live_phoneid
84
+ stub_request(:get, @expected_resource % ['live', @expected_phone_no]).
85
+ with(query: {ucid: 'OTHR'}, headers: @acceptance_headers).
86
+ to_return(body: @expected_data, status: 200)
87
+
88
+ p = Telesignature::PhoneId.new customer_id: @expected_cid, secret_key: @expected_secret_key
89
+ p.live @expected_phone_no, 'OTHR'
90
+ end
91
+
92
+ # # @mock.patch.object(requests, "get")
93
+ # def test_standard_phoneid_with_proxy
94
+ # response = mock.Mock()
95
+ # response.reason = ""
96
+ # response.status_code = 200
97
+ # response.text = @expected_data
98
+ # req_mock.return_value = response
99
+
100
+ # p = PhoneId.new(@expected_cid, @expected_secret_key, @proxy)
101
+ # p.standard(@expected_phone_no)
102
+
103
+ # assert_true.called
104
+ # _, kwargs = req_mock.call_args
105
+ # assert_equal kwargs["url"], @expected_resource % ['standard', @expected_phone_no], "Phone ID resource name is incorrect"
106
+ # assert_equal kwargs["proxies"]["https"], @expected_proxy, "Proxy did not match"
107
+ # end
108
+
109
+ # # @mock.patch.object(requests, "get")
110
+ # def test_score_phoneid_with_proxy
111
+ # response = mock.Mock()
112
+ # response.reason = ""
113
+ # response.status_code = 200
114
+ # response.text = @expected_data
115
+ # req_mock.return_value = response
116
+
117
+ # p = PhoneId.new(@expected_cid, @expected_secret_key, @proxy)
118
+ # p.score(@expected_phone_no, 'OTHR')
119
+
120
+ # assert_true.called
121
+ # _, kwargs = req_mock.call_args
122
+ # assert_equal kwargs["url"], @expected_resource % ['score', @expected_phone_no], "Phone ID resource name is incorrect"
123
+ # assert_equal kwargs["proxies"]["https"], @expected_proxy, "Proxy did not match"
124
+ # end
125
+
126
+ # # @mock.patch.object(requests, "get")
127
+ # def test_contact_phoneid_with_proxy
128
+ # response = mock.Mock()
129
+ # response.reason = ""
130
+ # response.status_code = 200
131
+ # response.text = @expected_data
132
+ # req_mock.return_value = response
133
+
134
+ # p = PhoneId.new(@expected_cid, @expected_secret_key, @proxy)
135
+ # p.contact(@expected_phone_no, 'OTHR')
136
+
137
+ # assert_true.called
138
+ # _, kwargs = req_mock.call_args
139
+ # assert_equal kwargs["url"], @expected_resource % ['contact', @expected_phone_no], "Phone ID resource name is incorrect"
140
+ # assert_equal kwargs["proxies"]["https"], @expected_proxy, "Proxy did not match"
141
+ # end
142
+
143
+ # # @mock.patch.object(requests, "get")
144
+ # def test_live_phoneid_with_proxy
145
+ # response = mock.Mock()
146
+ # response.reason = ""
147
+ # response.status_code = 200
148
+ # response.text = @expected_data
149
+ # req_mock.return_value = response
150
+
151
+ # p = PhoneId.new(@expected_cid, @expected_secret_key, proxy_host=@proxy)
152
+ # p.live(@expected_phone_no, 'OTHR')
153
+
154
+ # assert_true.called
155
+ # _, kwargs = req_mock.call_args
156
+ # assert_equal kwargs["url"], @expected_resource % ['live', @expected_phone_no], "Phone ID resource name is incorrect"
157
+ # assert_equal kwargs["proxies"]["https"], @expected_proxy, "Proxy did not match"
158
+ # end
159
+ end
@@ -0,0 +1,10 @@
1
+ require 'minitest/autorun'
2
+ require 'pry'
3
+ require 'telesignature'
4
+
5
+ begin
6
+ require 'turn/autorun'
7
+ Turn.config.format = :progress
8
+ rescue LoadError
9
+ p 'failed to load turn'
10
+ end