mailgun_email_validator 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -1
- data/lib/mailgun_email_validator/validator.rb +19 -4
- data/lib/mailgun_email_validator/version.rb +1 -1
- metadata +17 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 923257bd247cdbb07d13deb99735b0a996ff995f
|
4
|
+
data.tar.gz: 6a838807bde81bdd7f514ede2b73f8bb7b083234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c10f09d58c9751243f37c18035964cdb81a79a2a6e9e5f02466ec3ba0ef24577592552ea6c8488ef672d93f36f122231a4fedf2846fe2186aa605ccca8d92146
|
7
|
+
data.tar.gz: 2184b04d3dd3d945ea47a2855673dc6b2c16750ddfa2c64cc9fc754511b1b7a9db10921910a28c41702f5ae2e885579c3e6af1f345269c7855b179278aa7d321
|
data/README.md
CHANGED
@@ -12,6 +12,12 @@ You'll need to add a ``MAILGUN_PUBLIC_KEY`` environmental variable to your syste
|
|
12
12
|
|
13
13
|
``export MAILGUN_PUBLIC_KEY='f23oifj3ojo2j3ofj32ijoj2iojf3iojoi2f32'``
|
14
14
|
|
15
|
+
Alternatively, you can configure mailgun with an initializer:
|
16
|
+
|
17
|
+
In ``config/initializers/mailgun_email_validator.rb``:
|
18
|
+
|
19
|
+
``MailgunEmailValidator::MAILGUN_PUBLIC_KEY = 'f23oifj3ojo2j3ofj32ijoj2iojf3iojoi2f32'``
|
20
|
+
|
15
21
|
*Note: This is not a real Mailgun public key*
|
16
22
|
|
17
23
|
|
@@ -21,6 +27,10 @@ To use mailgun_email_validator inside your models:
|
|
21
27
|
|
22
28
|
You can also specify many of the usual ActiveRecord validation options including ``:on``, ``:allow_nil``, ``:allow_blank``, and ``:message``.
|
23
29
|
|
30
|
+
|
31
|
+
There is also a helper method available on all models:
|
32
|
+
|
33
|
+
``MyModel#valid_email_with_mailgun?(email) => true/false``
|
24
34
|
## Contributing to mailgun_email_validator
|
25
35
|
|
26
36
|
Pull requests welcome.
|
@@ -36,4 +46,5 @@ Pull requests welcome.
|
|
36
46
|
|
37
47
|
## Credits
|
38
48
|
|
39
|
-
* Zach Feldman [@zachfeldman](http://zfeldman.com)
|
49
|
+
* Zach Feldman [@zachfeldman](http://zfeldman.com)
|
50
|
+
* Matt Walters [@mattwalters](https://github.com/mattwalters) (Added helper method, ability to config with an initializer.)
|
@@ -2,7 +2,13 @@ require 'rest_client'
|
|
2
2
|
|
3
3
|
module MailgunEmailValidator
|
4
4
|
DEFAULT_VALIDATION_OPTIONS = {:on => :save, :allow_nil => false, :allow_blank => false, :message => nil}
|
5
|
-
|
5
|
+
|
6
|
+
MAILGUN_PUBLIC_KEY = nil
|
7
|
+
|
8
|
+
def valid_email_with_mailgun?(email)
|
9
|
+
!! parsed_validation_response!(email)["is_valid"]
|
10
|
+
end
|
11
|
+
|
6
12
|
def validation_method(on)
|
7
13
|
case on
|
8
14
|
when :save then :validate
|
@@ -22,8 +28,7 @@ module MailgunEmailValidator
|
|
22
28
|
return if record.blank?
|
23
29
|
else
|
24
30
|
begin
|
25
|
-
|
26
|
-
parsed = JSON.parse(res)
|
31
|
+
parsed = parsed_validation_response!(value)
|
27
32
|
is_valid = !parsed["is_valid"].nil? ? parsed["is_valid"] : false
|
28
33
|
message = options[:message] ? options[:message] : "supplied email is invalid."
|
29
34
|
record.errors.add(attr, message) if !is_valid
|
@@ -33,4 +38,14 @@ module MailgunEmailValidator
|
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
36
|
-
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def parsed_validation_response!(email)
|
45
|
+
res = RestClient.get "https://api:#{mailgun_public_key}@api.mailgun.net/v2/address/validate", {params: {address: email}}
|
46
|
+
JSON.parse(res)
|
47
|
+
end
|
48
|
+
def mailgun_public_key
|
49
|
+
MAILGUN_PUBLIC_KEY || ENV['MAILGUN_PUBLIC_KEY'] || raise("You need to supply your mailgun public api key")
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailgun_email_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Feldman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rest-client
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: spectator-validates_email
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Ability to validate e-mails using the Mailgun API with a REGEX fallback.
|
@@ -87,11 +87,11 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- README.md
|
91
|
+
- lib/mailgun_email_validator.rb
|
90
92
|
- lib/mailgun_email_validator/railtie.rb
|
91
93
|
- lib/mailgun_email_validator/validator.rb
|
92
94
|
- lib/mailgun_email_validator/version.rb
|
93
|
-
- lib/mailgun_email_validator.rb
|
94
|
-
- README.md
|
95
95
|
homepage: http://github.com/zachfeldman/mailgun_email_validator
|
96
96
|
licenses:
|
97
97
|
- GPL-3
|
@@ -102,17 +102,17 @@ require_paths:
|
|
102
102
|
- lib
|
103
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- -
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.2.2
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: Ability to validate e-mails using the Mailgun API
|