mailgun_email_validator 0.0.1

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: c94647169b8b8b838a54f6500d51ec911dc1663b
4
+ data.tar.gz: 77cc1bd9cff8538baa022226e6b5d61af906e4a3
5
+ SHA512:
6
+ metadata.gz: 31e8d500a4f3b12045fac399b1f88a3af613d3da561cc947306fd26e9d6596909963b1e5fa35e3b002588411bea7bf6b13f6203d0ecb1ebbe4efb1924e434387
7
+ data.tar.gz: 9a39cdab91bd17841504851620406ef202944ba85069bf0b3541eec2afbf45190802ed5b30558f9b797b58a07305feca9cdd4f8f4573a5a5833e65a5c20c623e
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # mailgun_email_validator
2
+
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
+
5
+ ## Usage
6
+
7
+ Add the gem to your Rails project's Gemfile, then bundle install to get started.
8
+
9
+ `gem 'mailgun_email_validator'`
10
+
11
+ You'll need to add a ``MAILGUN_PUBLIC_KEY`` environmental variable to your system, for instance in your ``~/.bash_profile``:
12
+
13
+ ``export MAILGUN_PUBLIC_KEY='f23oifj3ojo2j3ofj32ijoj2iojf3iojoi2f32'``
14
+
15
+ *Note: This is not a real Mailgun public key*
16
+
17
+
18
+ To use mailgun_email_validator inside your models:
19
+
20
+ `validates_as_email_with_mailgun :email`
21
+
22
+ You can also specify many of the usual ActiveRecord validation options including ``:on``, ``:allow_nil``, ``:allow_blank``, and ``:message``.
23
+
24
+ ## Contributing to mailgun_email_validator
25
+
26
+ Pull requests welcome.
27
+
28
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
29
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
30
+ * Fork the project.
31
+ * Start a feature/bugfix branch.
32
+ * Commit and push until you are happy with your contribution.
33
+ * Make sure to add tests for it. This is important so we don't break it in a future version unintentionally.
34
+ * Send in a pull request!
35
+
36
+
37
+ ## Credits
38
+
39
+ * Zach Feldman [@zachfeldman](http://zfeldman.com)
@@ -0,0 +1,8 @@
1
+ require "mailgun_email_validator/validator"
2
+ module MailgunEmailValidator
3
+ class Railtie < Rails::Railtie
4
+ initializer "mailgun_email_validator.validator" do
5
+ ActiveRecord::Base.extend MailgunEmailValidator
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,36 @@
1
+ require 'rest_client'
2
+
3
+ module MailgunEmailValidator
4
+ DEFAULT_VALIDATION_OPTIONS = {:on => :save, :allow_nil => false, :allow_blank => false, :message => nil}
5
+
6
+ def validation_method(on)
7
+ case on
8
+ when :save then :validate
9
+ when :create then :validate_on_create
10
+ when :update then :validate_on_update
11
+ end
12
+ end
13
+
14
+ def validates_as_email_with_mailgun(*attrs)
15
+ options = DEFAULT_VALIDATION_OPTIONS
16
+ options.update(attrs.extract_options!.symbolize_keys)
17
+
18
+ send(validation_method(options[:on]), options) do |record, attr, value|
19
+ if options[:allow_nil]
20
+ return if record.nil?
21
+ elsif options[:allow_blank]
22
+ return if record.blank?
23
+ else
24
+ begin
25
+ res = RestClient.get "https://api:#{ENV['MAILGUN_PUBLIC_KEY']}@api.mailgun.net/v2/address/validate", {params: {address: value}}
26
+ parsed = JSON.parse(res)
27
+ is_valid = !parsed["is_valid"].nil? ? parsed["is_valid"] : false
28
+ message = options[:message] ? options[:message] : "supplied email is invalid."
29
+ record.errors.add(attr, message) if !is_valid
30
+ rescue
31
+ validates record, email: true
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module MailgunEmailValidator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'mailgun_email_validator/railtie' if defined?(Rails)
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailgun_email_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zach Feldman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: spectator-validates_email
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ability to validate e-mails using the Mailgun API with a REGEX fallback.
84
+ email:
85
+ - zachfeldman@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/mailgun_email_validator/railtie.rb
91
+ - lib/mailgun_email_validator/validator.rb
92
+ - lib/mailgun_email_validator/version.rb
93
+ - lib/mailgun_email_validator.rb
94
+ - README.md
95
+ homepage: http://github.com/zachfeldman/mailgun_email_validator
96
+ licenses:
97
+ - GPL-3
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Ability to validate e-mails using the Mailgun API
119
+ test_files: []