brite_verify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brite_verify.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Simon Schoeters
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,57 @@
1
+ # BriteVerify
2
+
3
+ [BriteVerify](http://www.briteverify.com/) is a paying e-mail verification service. You pass it an e-mail address and it tells you if the e-mail address is real or not. They offer a typical REST like API. This gem wraps the API in a more Ruby friendly syntax.
4
+
5
+ This gem is no way endorsed or certified by BriteVerify. I extracted the code from a project where we are using the BriteVerify e-mail verification service.
6
+
7
+ ## Shortcomings
8
+
9
+ This gem does not cover all of BriteVerify's services. It only does e-mail verification and does not help you with any of BriteVerify's other services as I did not have a need for any of those so far. Feel free to contribute if you can help, it can only help the Ruby community.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'brite_verify'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install brite_verify
24
+
25
+ ## Usage
26
+
27
+ Minimum viable example:
28
+
29
+ email = BriteVerify::Email.new("john@example.com", "1298c367-ca34-6e11-3ab5-56027f1d1ec7")
30
+ email.verified?
31
+ => true
32
+ email.status
33
+ => :invalid
34
+ email.account
35
+ => "john"
36
+ email.domain
37
+ => "example.com"
38
+ email.connected
39
+ => nil
40
+ email.disposable
41
+ => false
42
+ email.role_address
43
+ => false
44
+ email.duration
45
+ => 0.039381279
46
+ email.error_code
47
+ => "email_domain_invalid"
48
+ email.error
49
+ => "Email domain invalid"
50
+
51
+ You can skip the API key parameter and specify the `ENV['BRITEVERIFY_API_KEY']` environment variable for convenience.
52
+
53
+ A more detailed description of the API can be found in the [BriteVerify e-mail documentation](https://github.com/BriteVerify/BriteCode/blob/master/email.md).
54
+
55
+ ## Contributing
56
+
57
+ Something missing? Found a bug? Horrified by the code? Open a [github issue](https://github.com/cimm/brite_verify/issues), write a failing test or add some code using pull requests. Your help is greatly appreciated!
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brite_verify/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "brite_verify"
8
+ gem.version = BriteVerify::VERSION
9
+ gem.authors = ["Simon Schoeters"]
10
+ gem.email = ["hamfilter@gmail.com"]
11
+ gem.description = %q{Ruby interface for BriteVerify's paying e-mail verification service.}
12
+ gem.summary = %q{BriteVerify is a paying e-mail verification service. You pass it an e-mail address and it tells you if the e-mail address is real or not. They offer a typical REST like API. This gem wraps the API in a more Ruby friendly syntax.}
13
+ gem.homepage = "https://github.com/cimm/brite_verify"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'webmock', '~> 1.9.0'
21
+ end
@@ -0,0 +1,60 @@
1
+ module BriteVerify
2
+ class Email
3
+ def initialize(address, key = ENV['BRITEVERIFY_API_KEY'])
4
+ raise ArgumentError, "Missing BriteVerify API key" if key.nil? || key.strip.empty?
5
+ @address = address
6
+ @key = key
7
+ end
8
+
9
+ def verified?
10
+ raw_email.keys.any?
11
+ end
12
+
13
+ def address
14
+ raw_email["address"]
15
+ end
16
+
17
+ def account
18
+ raw_email["account"]
19
+ end
20
+
21
+ def domain
22
+ raw_email["domain"]
23
+ end
24
+
25
+ def status
26
+ raw_email["status"].to_sym if raw_email["status"]
27
+ end
28
+
29
+ def connected
30
+ raw_email["connected"].downcase == "true" if raw_email["connected"]
31
+ end
32
+
33
+ def duration
34
+ raw_email["duration"]
35
+ end
36
+
37
+ def disposable
38
+ raw_email["disposable"]
39
+ end
40
+
41
+ def role_address
42
+ raw_email["role_address"]
43
+ end
44
+
45
+ def error_code
46
+ raw_email["error_code"]
47
+ end
48
+
49
+ def error
50
+ raw_email["error"]
51
+ end
52
+
53
+ private
54
+
55
+ def raw_email
56
+ email_fetcher = EmailFetcher.new(@key)
57
+ @raw_email ||= email_fetcher.fetch_raw_email(@address)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,35 @@
1
+ require 'net/https'
2
+ require 'openssl'
3
+ require 'uri'
4
+
5
+ module BriteVerify
6
+ class EmailFetcher
7
+ EMAIL_PATH = "/emails.json"
8
+
9
+ def initialize(key)
10
+ @key = key
11
+ end
12
+
13
+ def fetch_raw_email(address)
14
+ email_response = fetch_email(address)
15
+ email_response.raw_email
16
+ rescue Timeout::Error => e
17
+ {}
18
+ end
19
+
20
+ def fetch_email(address)
21
+ uri = verification_uri(address)
22
+ http = Net::HTTP.new(uri.host, uri.port)
23
+ http.use_ssl = true
24
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
25
+ request = Net::HTTP::Get.new(uri.request_uri)
26
+ response = http.request(request)
27
+ EmailResponse.new(response)
28
+ end
29
+
30
+ def verification_uri(address)
31
+ query = URI.encode_www_form(address: address, apikey: @key)
32
+ URI::HTTPS.build({host: HOST, path: EMAIL_PATH, query: query})
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'json'
2
+
3
+ module BriteVerify
4
+ class EmailResponse
5
+ SUCCESS_STATUS_CODE = 200
6
+ EMPTY_JSON = "{}"
7
+
8
+ def initialize(response)
9
+ @response = response
10
+ end
11
+
12
+ def successful?
13
+ @response.code.to_i == SUCCESS_STATUS_CODE
14
+ end
15
+
16
+ def raw_email
17
+ body = successful? ? @response.body : EMPTY_JSON
18
+ JSON.parse(body)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module BriteVerify
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ require 'brite_verify/version'
2
+ require 'brite_verify/email_fetcher'
3
+ require 'brite_verify/email_response'
4
+ require 'brite_verify/email'
5
+
6
+ module BriteVerify
7
+ HOST = "bpi.briteverify.com"
8
+ end
@@ -0,0 +1,50 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+
3
+ module BriteVerify
4
+ describe EmailFetcher do
5
+ ADDRESS = "john.doe@example.com"
6
+ KEY = "123-abc-123-abc"
7
+
8
+ before do
9
+ @email_verification_request = stub_email_verification_request(ADDRESS, KEY, valid_email_body)
10
+ end
11
+
12
+ it "accepts a key" do
13
+ email_fetcher = EmailFetcher.new(KEY)
14
+ email_fetcher.wont_be_nil
15
+ end
16
+
17
+ it "requires a key" do
18
+ lambda { EmailFetcher.new }.must_raise(ArgumentError)
19
+ end
20
+
21
+ describe :fetch_raw_email do
22
+ it "returns the raw e-mail" do
23
+ email_fetcher = EmailFetcher.new(KEY)
24
+ parsed_valid_email_body = JSON.parse(valid_email_body)
25
+ email_fetcher.fetch_raw_email(ADDRESS).must_equal(parsed_valid_email_body)
26
+ end
27
+ end
28
+
29
+ describe :fetch_email do
30
+ it "verifies the e-mail with BriteVerify" do
31
+ email_fetcher = EmailFetcher.new(KEY)
32
+ email_fetcher.fetch_email(ADDRESS)
33
+ assert_requested(@email_verification_request)
34
+ end
35
+
36
+ it "returns an e-mail response" do
37
+ email_fetcher = EmailFetcher.new(KEY)
38
+ email_fetcher.fetch_email(ADDRESS).must_be_instance_of(EmailResponse)
39
+ end
40
+ end
41
+
42
+ describe :verification_uri do
43
+ it "returns the verification URI" do
44
+ email_fetcher = EmailFetcher.new(KEY)
45
+ uri = email_fetcher.verification_uri(ADDRESS)
46
+ uri.to_s.must_equal("https://bpi.briteverify.com/emails.json?address=john.doe%40example.com&apikey=123-abc-123-abc")
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+ require 'json'
3
+
4
+ module BriteVerify
5
+ describe EmailResponse do
6
+ before do
7
+ @response = Net::HTTPResponse.new(1.0, 200, "OK")
8
+ end
9
+
10
+ describe :successful? do
11
+ describe "when it succeeded" do
12
+ it "returns true" do
13
+ email_response = EmailResponse.new(@response)
14
+ email_response.successful?.must_equal(true)
15
+ end
16
+ end
17
+
18
+ describe "when something went wrong" do
19
+ before do
20
+ @response = Net::HTTPResponse.new(1.0, 500, "Internal Server Error")
21
+ end
22
+
23
+ it "returns false" do
24
+ email_response = EmailResponse.new(@response)
25
+ email_response.successful?.must_equal(false)
26
+ end
27
+ end
28
+ end
29
+
30
+ describe :raw_email do
31
+ describe "when it succeeded" do
32
+ before do
33
+ @response = MiniTest::Mock.new # can't set response.body for some reason
34
+ @response.expect(:code, "200")
35
+ @response.expect(:body, valid_email_body)
36
+ end
37
+
38
+ it "returns the raw email" do
39
+ email_response = EmailResponse.new(@response)
40
+ parsed_valid_email_body = JSON.parse(valid_email_body)
41
+ email_response.raw_email.must_equal(parsed_valid_email_body)
42
+ end
43
+ end
44
+
45
+ describe "when something went wrong" do
46
+ before do
47
+ @response = Net::HTTPResponse.new(1.0, 500, "Internal Server Error")
48
+ end
49
+
50
+ it "returns an empty raw email" do
51
+ email_response = EmailResponse.new(@response)
52
+ email_response.raw_email.must_equal({})
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,374 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/test_helper")
2
+ require 'json'
3
+
4
+ module BriteVerify
5
+ describe Email do
6
+ ADDRESS = "john.doe@example.com"
7
+ KEY = "123-abc-123-abc"
8
+
9
+ before do
10
+ stub_email_verification_request(ADDRESS, KEY, valid_email_body)
11
+ end
12
+
13
+ it "accepts a key" do
14
+ email = Email.new(ADDRESS, KEY)
15
+ email.wont_be_nil
16
+ end
17
+
18
+ it "requires a key" do
19
+ lambda { Email.new(ADDRESS) }.must_raise(ArgumentError)
20
+ end
21
+
22
+ it "does not accept an empty key" do
23
+ lambda { Email.new(ADDRESS, "") }.must_raise(ArgumentError)
24
+ end
25
+
26
+ it "uses the environment variable the key wasn't given" do
27
+ ENV['BRITEVERIFY_API_KEY'] = "456-def-456-def"
28
+ lambda { Email.new(ADDRESS) }.must_be_silent
29
+ ENV['BRITEVERIFY_API_KEY'] = nil
30
+ end
31
+
32
+ describe :verified? do
33
+ describe "when the response was successful" do
34
+ it "returns true" do
35
+ email = Email.new(ADDRESS, KEY)
36
+ email.verified?.must_equal(true)
37
+ end
38
+ end
39
+
40
+ describe "when the response was not successful" do
41
+ before do
42
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
43
+ end
44
+
45
+ it "returns false" do
46
+ email = Email.new(ADDRESS, KEY)
47
+ email.verified?.must_equal(false)
48
+ end
49
+ end
50
+
51
+ describe "when the response timed out" do
52
+ before do
53
+ stub_error_email_verification_request(ADDRESS, KEY, :timeout)
54
+ end
55
+
56
+ it "returns false" do
57
+ email = Email.new(ADDRESS, KEY)
58
+ email.verified?.must_equal(false)
59
+ end
60
+ end
61
+
62
+ describe "when the response is unauthorized" do
63
+ before do
64
+ stub_error_email_verification_request(ADDRESS, KEY, 401)
65
+ end
66
+
67
+ it "returns false" do
68
+ email = Email.new(ADDRESS, KEY)
69
+ email.verified?.must_equal(false)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe :address do
75
+ describe "when the response was successful" do
76
+ it "returns the verified address returned from BriteVerify" do
77
+ email = Email.new(ADDRESS, KEY)
78
+ email.address.must_equal("john.doe@example.com")
79
+ end
80
+ end
81
+
82
+ describe "when the response was not successful" do
83
+ before do
84
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
85
+ end
86
+
87
+ it "returns nil" do
88
+ email = Email.new(ADDRESS, KEY)
89
+ email.address.must_be_nil
90
+ end
91
+ end
92
+ end
93
+
94
+ describe :account do
95
+ describe "when the response was successful" do
96
+ it "returns the account returned from BriteVerify" do
97
+ email = Email.new(ADDRESS, KEY)
98
+ email.account.must_equal("john.doe")
99
+ end
100
+ end
101
+
102
+ describe "when the response was not successful" do
103
+ before do
104
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
105
+ end
106
+
107
+ it "returns nil" do
108
+ email = Email.new(ADDRESS, KEY)
109
+ email.account.must_be_nil
110
+ end
111
+ end
112
+ end
113
+
114
+ describe :domain do
115
+ describe "when the response was successful" do
116
+ it "returns the domain returned from BriteVerify" do
117
+ email = Email.new(ADDRESS, KEY)
118
+ email.domain.must_equal("example.com")
119
+ end
120
+ end
121
+
122
+ describe "when the response was not successful" do
123
+ before do
124
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
125
+ end
126
+
127
+ it "returns nil" do
128
+ email = Email.new(ADDRESS, KEY)
129
+ email.domain.must_be_nil
130
+ end
131
+ end
132
+ end
133
+
134
+ describe :status do
135
+ describe "when the response was successful" do
136
+ describe "when the address is valid" do
137
+ it "returns the valid status" do
138
+ email = Email.new(ADDRESS, KEY)
139
+ email.status.must_equal(:valid)
140
+ end
141
+ end
142
+
143
+ describe "when the address is invalid" do
144
+ before do
145
+ stub_email_verification_request(ADDRESS, KEY, invalid_email_body)
146
+ end
147
+
148
+ it "returns the invalid status" do
149
+ email = Email.new(ADDRESS, KEY)
150
+ email.status.must_equal(:invalid)
151
+ end
152
+ end
153
+
154
+ describe "when the address is unknown" do
155
+ before do
156
+ stub_email_verification_request(ADDRESS, KEY, unknown_email_body)
157
+ end
158
+
159
+ it "returns the unknown status" do
160
+ email = Email.new(ADDRESS, KEY)
161
+ email.status.must_equal(:unknown)
162
+ end
163
+ end
164
+
165
+ describe "when the address is an accept all address" do
166
+ before do
167
+ stub_email_verification_request(ADDRESS, KEY, accept_all_email_body)
168
+ end
169
+
170
+ it "returns the unknown status" do
171
+ email = Email.new(ADDRESS, KEY)
172
+ email.status.must_equal(:accept_all)
173
+ end
174
+ end
175
+ end
176
+
177
+ describe "when the response was not successful" do
178
+ before do
179
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
180
+ end
181
+
182
+ it "returns nil" do
183
+ email = Email.new(ADDRESS, KEY)
184
+ email.status.must_be_nil
185
+ end
186
+ end
187
+ end
188
+
189
+ describe :connected do
190
+ describe "when the response was successful" do
191
+ describe "when the address is connected" do
192
+ before do
193
+ stub_email_verification_request(ADDRESS, KEY, connected_email_body)
194
+ end
195
+
196
+ it "returns true" do
197
+ email = Email.new(ADDRESS, KEY)
198
+ email.connected.must_equal(true)
199
+ end
200
+ end
201
+
202
+ describe "when it is not known if the address is connected" do
203
+ it "returns nil" do
204
+ email = Email.new(ADDRESS, KEY)
205
+ email.connected.must_be_nil
206
+ end
207
+ end
208
+ end
209
+
210
+ describe "when the response was not successful" do
211
+ before do
212
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
213
+ end
214
+
215
+ it "returns nil" do
216
+ email = Email.new(ADDRESS, KEY)
217
+ email.connected.must_be_nil
218
+ end
219
+ end
220
+ end
221
+
222
+ describe :duration do
223
+ describe "when the response was successful" do
224
+ it "returns the time it took BriteVerify to verify the address" do
225
+ email = Email.new(ADDRESS, KEY)
226
+ email.duration.must_equal(0.104516605)
227
+ end
228
+ end
229
+
230
+ describe "when the response was not successful" do
231
+ before do
232
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
233
+ end
234
+
235
+ it "returns nil" do
236
+ email = Email.new(ADDRESS, KEY)
237
+ email.duration.must_be_nil
238
+ end
239
+ end
240
+ end
241
+
242
+ describe :disposable do
243
+ describe "when the response was successful" do
244
+ describe "the address is disposable" do
245
+ before do
246
+ stub_email_verification_request(ADDRESS, KEY, disposable_email_body)
247
+ end
248
+
249
+ it "returns true" do
250
+ email = Email.new(ADDRESS, KEY)
251
+ email.disposable.must_equal(true)
252
+ end
253
+ end
254
+
255
+ describe "when it is not known if the address is disposable" do
256
+ it "returns nil" do
257
+ email = Email.new(ADDRESS, KEY)
258
+ email.disposable.must_be_nil
259
+ end
260
+ end
261
+ end
262
+
263
+ describe "when the response was not successful" do
264
+ before do
265
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
266
+ end
267
+
268
+ it "returns nil" do
269
+ email = Email.new(ADDRESS, KEY)
270
+ email.disposable.must_be_nil
271
+ end
272
+ end
273
+ end
274
+
275
+ describe :role_address do
276
+ describe "when the response was successful" do
277
+ describe "when the address is a role address" do
278
+ before do
279
+ stub_email_verification_request(ADDRESS, KEY, role_address_email_body)
280
+ end
281
+
282
+ it "returns true" do
283
+ email = Email.new(ADDRESS, KEY)
284
+ email.role_address.must_equal(true)
285
+ end
286
+ end
287
+
288
+ describe "when it is not known if the address is a role address" do
289
+ it "returns nil" do
290
+ email = Email.new(ADDRESS, KEY)
291
+ email.role_address.must_be_nil
292
+ end
293
+ end
294
+ end
295
+
296
+ describe "when the response was not successful" do
297
+ before do
298
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
299
+ end
300
+
301
+ it "returns nil" do
302
+ email = Email.new(ADDRESS, KEY)
303
+ email.role_address.must_be_nil
304
+ end
305
+ end
306
+ end
307
+
308
+ describe :error_code do
309
+ describe "when the response was successful" do
310
+ describe "when the address is valid" do
311
+ it "has no error code" do
312
+ email = Email.new(ADDRESS, KEY)
313
+ email.error_code.must_be_nil
314
+ end
315
+ end
316
+
317
+ describe "when the address is not valid" do
318
+ before do
319
+ stub_email_verification_request(ADDRESS, KEY, invalid_email_body)
320
+ end
321
+
322
+ it "has an error code" do
323
+ email = Email.new(ADDRESS, KEY)
324
+ email.error_code.must_equal("email_domain_invalid")
325
+ end
326
+ end
327
+ end
328
+
329
+ describe "when the response was not successful" do
330
+ before do
331
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
332
+ end
333
+
334
+ it "returns nil" do
335
+ email = Email.new(ADDRESS, KEY)
336
+ email.error_code.must_be_nil
337
+ end
338
+ end
339
+ end
340
+
341
+ describe :error do
342
+ describe "when the response was successful" do
343
+ describe "when the address is valid" do
344
+ it "has no error" do
345
+ email = Email.new(ADDRESS, KEY)
346
+ email.error.must_be_nil
347
+ end
348
+ end
349
+
350
+ describe "when the address is not valid" do
351
+ before do
352
+ stub_email_verification_request(ADDRESS, KEY, invalid_email_body)
353
+ end
354
+
355
+ it "has a more detailed error" do
356
+ email = Email.new(ADDRESS, KEY)
357
+ email.error.must_equal("Email domain invalid")
358
+ end
359
+ end
360
+ end
361
+
362
+ describe "when the response was not successful" do
363
+ before do
364
+ stub_error_email_verification_request(ADDRESS, KEY, 500)
365
+ end
366
+
367
+ it "returns nil" do
368
+ email = Email.new(ADDRESS, KEY)
369
+ email.error.must_be_nil
370
+ end
371
+ end
372
+ end
373
+ end
374
+ end
@@ -0,0 +1,8 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"accept_all",
6
+ "connected":"true",
7
+ "duration":0.104516605
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"valid",
6
+ "connected":"true",
7
+ "duration":0.104516605
8
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"valid",
6
+ "connected":"true",
7
+ "duration":0.104516605,
8
+ "disposable":true
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"invalid",
6
+ "error_code":"email_domain_invalid",
7
+ "error":"Email domain invalid",
8
+ "connected":"true",
9
+ "duration":0.104516605
10
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"valid",
6
+ "connected":"true",
7
+ "duration":0.104516605,
8
+ "role_address":true
9
+ }
@@ -0,0 +1,9 @@
1
+
2
+ {
3
+ "address":"john.doe@example.com",
4
+ "account":"john.doe",
5
+ "domain":"example.com",
6
+ "status":"unknown",
7
+ "connected":"true",
8
+ "duration":0.104516605
9
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "address":"john.doe@example.com",
3
+ "account":"john.doe",
4
+ "domain":"example.com",
5
+ "status":"valid",
6
+ "duration":0.104516605
7
+ }
@@ -0,0 +1,60 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/mock'
3
+ require 'minitest/autorun'
4
+ require 'webmock/minitest'
5
+ require 'brite_verify'
6
+
7
+ FIXTURES_PATH = File.expand_path("#{File.dirname(__FILE__)}/fixtures")
8
+
9
+ def valid_email_body
10
+ @valid_email_body ||= File.read(File.join(FIXTURES_PATH, 'valid_email.json'))
11
+ end
12
+
13
+ def invalid_email_body
14
+ @invalid_email_body ||= File.read(File.join(FIXTURES_PATH, 'invalid_email.json'))
15
+ end
16
+
17
+ def unknown_email_body
18
+ @unknown_email_body ||= File.read(File.join(FIXTURES_PATH, 'unknown_email.json'))
19
+ end
20
+
21
+ def accept_all_email_body
22
+ @accept_all_email_body ||= File.read(File.join(FIXTURES_PATH, 'accept_all_email.json'))
23
+ end
24
+
25
+ def connected_email_body
26
+ @connected_email_body ||= File.read(File.join(FIXTURES_PATH, 'connected_email.json'))
27
+ end
28
+
29
+ def disposable_email_body
30
+ @disposable_email_body ||= File.read(File.join(FIXTURES_PATH, 'disposable_email.json'))
31
+ end
32
+
33
+ def role_address_email_body
34
+ @role_address_email_body ||= File.read(File.join(FIXTURES_PATH, 'role_address_email.json'))
35
+ end
36
+
37
+ def stub_email_verification_request(address, key, body)
38
+ request = { :headers => {'Accept' => '*/*', 'User-Agent' => 'Ruby'} }
39
+ response = { :status => 200, :body => body, :headers => {} }
40
+ stub_request(:get, email_verification_url(address, key)).with(request).to_return(response)
41
+ end
42
+
43
+ def stub_error_email_verification_request(address, key, code)
44
+ status = []
45
+ verification_url = email_verification_url(address, key)
46
+ case code
47
+ when 401
48
+ stub_request(:get, verification_url).to_return(:status => [401, "Unauthorized"])
49
+ when 500
50
+ stub_request(:get, verification_url).to_return(:status => [500, "Internal Server Error"])
51
+ when :timeout
52
+ stub_request(:get, verification_url).to_timeout
53
+ else
54
+ raise "Unknown response code: #{code}"
55
+ end
56
+ end
57
+
58
+ def email_verification_url(address, key)
59
+ "https://bpi.briteverify.com/emails.json?address=#{address}&apikey=#{key}"
60
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brite_verify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Simon Schoeters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: webmock
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.9.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 1.9.0
30
+ description: Ruby interface for BriteVerify's paying e-mail verification service.
31
+ email:
32
+ - hamfilter@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - brite_verify.gemspec
43
+ - lib/brite_verify.rb
44
+ - lib/brite_verify/email.rb
45
+ - lib/brite_verify/email_fetcher.rb
46
+ - lib/brite_verify/email_response.rb
47
+ - lib/brite_verify/version.rb
48
+ - test/email_fetcher_test.rb
49
+ - test/email_response_test.rb
50
+ - test/email_test.rb
51
+ - test/fixtures/accept_all_email.json
52
+ - test/fixtures/connected_email.json
53
+ - test/fixtures/disposable_email.json
54
+ - test/fixtures/invalid_email.json
55
+ - test/fixtures/role_address_email.json
56
+ - test/fixtures/unknown_email.json
57
+ - test/fixtures/valid_email.json
58
+ - test/test_helper.rb
59
+ homepage: https://github.com/cimm/brite_verify
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.24
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: BriteVerify is a paying e-mail verification service. You pass it an e-mail
83
+ address and it tells you if the e-mail address is real or not. They offer a typical
84
+ REST like API. This gem wraps the API in a more Ruby friendly syntax.
85
+ test_files:
86
+ - test/email_fetcher_test.rb
87
+ - test/email_response_test.rb
88
+ - test/email_test.rb
89
+ - test/fixtures/accept_all_email.json
90
+ - test/fixtures/connected_email.json
91
+ - test/fixtures/disposable_email.json
92
+ - test/fixtures/invalid_email.json
93
+ - test/fixtures/role_address_email.json
94
+ - test/fixtures/unknown_email.json
95
+ - test/fixtures/valid_email.json
96
+ - test/test_helper.rb