mailchecker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mailchecker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 antho1404
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,29 @@
1
+ # Mailchecker
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mailchecker'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mailchecker
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,87 @@
1
+ require 'mailchecker/version'
2
+ require 'net/http'
3
+ require "uri"
4
+
5
+ module Mailchecker
6
+ module Rails
7
+ class Engine < ::Rails::Engine
8
+ end
9
+ end
10
+
11
+ mattr_accessor :url
12
+ @@url = "http://www.mail-checker.com/check"
13
+
14
+ mattr_accessor :token
15
+ @@token = nil
16
+
17
+ mattr_accessor :domain
18
+ @@domain = nil
19
+
20
+ def self.setup
21
+ yield self
22
+ end
23
+
24
+ def self.validate_email email
25
+ params = { email: email, token: Mailchecker.token, domain: Mailchecker.domain, format: :json }
26
+
27
+ uri = URI.parse Mailchecker.url + "?" + params.to_param
28
+ http = Net::HTTP.new uri.host, uri.port
29
+ request = Net::HTTP::Get.new uri.request_uri
30
+ response = http.request request
31
+
32
+ case response.code.to_i
33
+ when 200
34
+ nil
35
+ when 422
36
+ I18n.t :wrong_format, scope: [:mailchecker, :errors, :messages], default: 'the format is not valid (abc@example.com)'
37
+ when 502
38
+ I18n.t :wrong_gateway, scope: [:mailchecker, :errors, :messages], default: 'the domain is not responding'
39
+ when 406
40
+ I18n.t :temporary_email, scope: [:mailchecker, :errors, :messages], default: 'this kind of email is not valid (temporary email)'
41
+ when 400
42
+ raise "Some parameters are missing... did you add the right token in the init file or the domain is valid?"
43
+ else
44
+ raise "Please report this issue (probably a lack of a new functionality), the status code is #{response.code}"
45
+ end
46
+ end
47
+
48
+ def self.record_validation record, attr_name, value
49
+ error = Mailchecker::validate_email value.to_s
50
+ record.errors.add attr_name, error if error
51
+ end
52
+
53
+ module Validations
54
+ def self.mailchecker *attr_names
55
+ options = { on: :save, allow_nil: false, allow_blank: false }
56
+ options.update attr_names.pop if attr_names.last.is_a? Hash
57
+
58
+ validates_each(attr_names, options) do |record, attr_name, value|
59
+ Mailchecker.record_validation record, attr_name, value
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ if defined?(ActiveModel)
66
+ class MailCheckerValidator < ActiveModel::EachValidator
67
+ def validate_each record, attr_name, value
68
+ Mailchecker.record_validation record, attr_name, value
69
+ end
70
+ end
71
+
72
+ module ActiveModel::Validations::HelperMethods
73
+ def mailchecker *attr_names
74
+ validates_with MailCheckerValidator, _merge_attributes(attr_names)
75
+ end
76
+ end
77
+ else
78
+ if defined?(ActiveRecord)
79
+ class ActiveRecord::Base
80
+ extend ValidatesEmailFormatOf::Validations
81
+ end
82
+ end
83
+ end
84
+
85
+ Dir[File.join(File.dirname(__FILE__), "..", "locales", "*.yml")].each do |loc|
86
+ I18n.load_path << loc
87
+ end
@@ -0,0 +1,3 @@
1
+ module Mailchecker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mailchecker/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mailchecker"
8
+ gem.version = Mailchecker::VERSION
9
+ gem.authors = ["antho1404"]
10
+ gem.email = ["contact@anthonyestebe.com"]
11
+ gem.description = %q{This will validate your email using mail-checker.com web service, it will test for you the format, if the domain responds and if the email is not a temporary mail}
12
+ gem.summary = %q{The easiest way to validate your emails !}
13
+ gem.homepage = "http://www.mail-checker.com/"
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|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailchecker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - antho1404
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-12 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: This will validate your email using mail-checker.com web service, it
15
+ will test for you the format, if the domain responds and if the email is not a temporary
16
+ mail
17
+ email:
18
+ - contact@anthonyestebe.com
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/mailchecker.rb
29
+ - lib/mailchecker/version.rb
30
+ - mailchecker.gemspec
31
+ homepage: http://www.mail-checker.com/
32
+ licenses: []
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 1.8.24
52
+ signing_key:
53
+ specification_version: 3
54
+ summary: The easiest way to validate your emails !
55
+ test_files: []