mailgun_email_validator 0.0.3 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/lib/mailgun_email_validator/validator.rb +5 -3
- data/lib/mailgun_email_validator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06c8b8755370a7fece874003d16c53b4e3566f7d
|
4
|
+
data.tar.gz: 5189b916fe30c726a23f8e34db52a4b2cfd4b129
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 787d5cd9c28252da82282eb914e5667c1e619b6cc1394553d2d04277b1e88c4469c63333d48849ee170e6aa365490885456aa10c10430e9d550331d0f4eaf332
|
7
|
+
data.tar.gz: 48395969f9b6e32103d20a81adce56d6d022a5507b48c2ee225f044c9970dda6040940bb694159031b64063f11f5eb4628ef5274098f82a0e12c6377db2321db
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# mailgun_email_validator
|
2
2
|
|
3
|
-
This gem adds a
|
3
|
+
This gem adds a `validates_as_email_with_mailgun` method to ActiveRecord. It first tries to verify an e-mail using the amazing Mailgun e-mail validation API and then falls back to using the [spectator_validates_email](https://github.com/spectator/validates_email) gem if it can't connect.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
@@ -8,15 +8,15 @@ Add the gem to your Rails project's Gemfile, then bundle install to get started.
|
|
8
8
|
|
9
9
|
`gem 'mailgun_email_validator'`
|
10
10
|
|
11
|
-
You'll need to add a
|
11
|
+
You'll need to add a `MAILGUN_PUBLIC_KEY` environmental variable to your system, for instance in your `~/.bash_profile`:
|
12
12
|
|
13
|
-
|
13
|
+
`export MAILGUN_PUBLIC_KEY='f23oifj3ojo2j3ofj32ijoj2iojf3iojoi2f32'`
|
14
14
|
|
15
15
|
Alternatively, you can configure mailgun with an initializer:
|
16
16
|
|
17
|
-
In
|
17
|
+
In `config/initializers/mailgun_email_validator.rb`:
|
18
18
|
|
19
|
-
|
19
|
+
`MailgunEmailValidator.mailgun_public_key = 'f23oifj3ojo2j3ofj32ijoj2iojf3iojoi2f32'`
|
20
20
|
|
21
21
|
*Note: This is not a real Mailgun public key*
|
22
22
|
|
@@ -25,12 +25,13 @@ To use mailgun_email_validator inside your models:
|
|
25
25
|
|
26
26
|
`validates_as_email_with_mailgun :email`
|
27
27
|
|
28
|
-
You can also specify many of the usual ActiveRecord validation options including
|
28
|
+
You can also specify many of the usual ActiveRecord validation options including `:on`, `:allow_nil`, `:allow_blank`, and `:message`.
|
29
29
|
|
30
30
|
|
31
31
|
There is also a helper method available on all models:
|
32
32
|
|
33
|
-
|
33
|
+
`MyModel#valid_email_with_mailgun?(email) => true/false`
|
34
|
+
|
34
35
|
## Contributing to mailgun_email_validator
|
35
36
|
|
36
37
|
Pull requests welcome.
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
1
2
|
require 'rest_client'
|
2
3
|
|
3
4
|
module MailgunEmailValidator
|
4
|
-
|
5
|
+
mattr_writer :mailgun_public_key, instance_writer: false
|
5
6
|
|
6
|
-
|
7
|
+
DEFAULT_VALIDATION_OPTIONS = {:on => :save, :allow_nil => false, :allow_blank => false, :message => nil}
|
7
8
|
|
8
9
|
def valid_email_with_mailgun?(email)
|
9
10
|
!! parsed_validation_response!(email)["is_valid"]
|
@@ -45,7 +46,8 @@ module MailgunEmailValidator
|
|
45
46
|
res = RestClient.get "https://api:#{mailgun_public_key}@api.mailgun.net/v2/address/validate", {params: {address: email}}
|
46
47
|
JSON.parse(res)
|
47
48
|
end
|
49
|
+
|
48
50
|
def mailgun_public_key
|
49
|
-
|
51
|
+
@@mailgun_public_key || ENV['MAILGUN_PUBLIC_KEY'] || raise("You need to supply your mailgun public api key")
|
50
52
|
end
|
51
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun_email_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Feldman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|