mailchecker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Mailchecker
2
2
 
3
- TODO: Write a gem description
3
+ Simply validate your email in 3 steps using Mail-checker web service (http://www.mail-checker.com).
4
+ - Validate the format of your email
5
+ - Validate if the domain is responding
6
+ - Validate if the email is not a temporary mail (like yopmail or others...)
7
+
8
+ This will be very helpful when you have to contact your users and you want to avoid errors causing lack of communication or want to block "spamboxes"
4
9
 
5
10
  ## Installation
6
11
 
@@ -18,7 +23,30 @@ Or install it yourself as:
18
23
 
19
24
  ## Usage
20
25
 
21
- TODO: Write usage instructions here
26
+ Register your application in Mail-checker.com (http://www.mail-checker.com/apps/new).
27
+ Generate the config file for the gem
28
+
29
+ $ rails generate mailchecker:install
30
+
31
+ Update the file (config/initializers/mailchecker.rb) with the values of your registered application (token and domain)
32
+
33
+ Now you have two ways to do the validation:
34
+
35
+ On the server side:
36
+
37
+ Add in your model the validation of your attribute for the email (hopefully email)
38
+
39
+ class User < ActiveRecord::Base
40
+ mailchecker :email
41
+ end
42
+
43
+ On the client side:
44
+
45
+ Call the javascript lib on your email fields and do the stuff you need on the generated file
46
+
47
+ $ rails generate mailchecker:assets
48
+
49
+ Of course you can do the validation on the both side if you want
22
50
 
23
51
  ## Contributing
24
52
 
@@ -0,0 +1,13 @@
1
+ module Mailchecker
2
+ module Generators
3
+ class AssetsGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Create the javascript file to make the validation in client side."
7
+
8
+ def copy_javascript
9
+ template "assets/mailchecker.js.coffee.erb", "app/assets/javascripts/mailchecker_client.js.coffee.erb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module Mailchecker
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("../../templates", __FILE__)
5
+
6
+ desc "Creates a Mail-checker initializer and copy locale files to your application."
7
+
8
+ def copy_initializer
9
+ template "mailchecker.rb", "config/initializers/mailchecker.rb"
10
+ end
11
+
12
+ def copy_locales
13
+ copy_file "../../../locales/en.yml", "config/locales/mailchecker.en.yml"
14
+ copy_file "../../../locales/fr.yml", "config/locales/mailchecker.fr.yml"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ #= require mailchecker
2
+
3
+ $("input[type=email]").mail_checker '<%= Mailchecker.token %>',
4
+ success: -> console.log "email #{$(this).val()} is valid" # do what you whant when it's ok
5
+ invalid_format: -> console.error "format of #{$(this).val()} isn't valid" # do what you whant when the format is not good
6
+ invalid_domain: -> console.error "domain of #{$(this).val()} is not responding" # do what you whant when the domain is not responding
7
+ temporary_mail: -> console.error "email #{$(this).val()} is a temporary mail" # do what you whant when it's a temporary mail
@@ -0,0 +1,6 @@
1
+ Mailchecker.setup do |config|
2
+ # Here you need to declare your token key and your application domain
3
+ # to have this, please register your application on http://www.mail-checker.com
4
+ config.token = "your_token_key"
5
+ config.domain = "your_app_domain"
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Mailchecker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,7 @@
1
+ en:
2
+ mailchecker:
3
+ errors:
4
+ messages:
5
+ wrong_format: "the format is not valid (abc@example.com)"
6
+ wrong_gateway: "the domain is not responding"
7
+ temporary_email: "this kind of email is not valid (temporary email)"
@@ -0,0 +1,7 @@
1
+ fr:
2
+ mailchecker:
3
+ errors:
4
+ messages:
5
+ wrong_format: "le format n'est pas valide (abc@exemple.com)"
6
+ wrong_gateway: "le domaine ne répond pas"
7
+ temporary_email: "ce type d'email n'est pas valide (email temporaire)"
@@ -0,0 +1,42 @@
1
+ $.fn.mail_checker = (token, options) ->
2
+ if typeof token is 'object'
3
+ options = token
4
+ token = null
5
+
6
+ defaults =
7
+ token: null
8
+ trigger_on: "change"
9
+ success: () ->
10
+ invalid_format: () ->
11
+ invalid_domain: () ->
12
+ temporary_mail: () ->
13
+ error: (error) -> console.error(error)
14
+
15
+ domain = document.domain.match /([^.]+)\.[^.]+.?$/
16
+
17
+ domain = domain[0] if domain and domain.length > 0
18
+ options = $.extend {}, defaults, options
19
+
20
+ unless token
21
+ token = options.token
22
+ unless token
23
+ console.error "Missing token parameter"
24
+ return
25
+
26
+ $(this).bind options.trigger_on, ->
27
+ _this = this
28
+ data =
29
+ token: token
30
+ domain: domain
31
+ email: $(this).val()
32
+ $.ajax
33
+ url: "<%= Mailchecker.url %>"
34
+ data: data
35
+ dataType: "json"
36
+ complete: (jqXHR, textStatus) ->
37
+ options.success.apply(_this) if jqXHR.status is 200
38
+ options.invalid_format.apply(_this) if jqXHR.status is 422
39
+ options.invalid_domain.apply(_this) if jqXHR.status is 502
40
+ options.temporary_mail.apply(_this) if jqXHR.status is 406
41
+ options.error.apply(_this, [$.parseJSON(jqXHR.responseText).error]) if jqXHR.status is 400
42
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailchecker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,9 +25,16 @@ files:
25
25
  - LICENSE.txt
26
26
  - README.md
27
27
  - Rakefile
28
+ - lib/generators/mailchecker/assets_generator.rb
29
+ - lib/generators/mailchecker/install_generator.rb
30
+ - lib/generators/templates/assets/mailchecker.js.coffee.erb
31
+ - lib/generators/templates/mailchecker.rb
28
32
  - lib/mailchecker.rb
29
33
  - lib/mailchecker/version.rb
34
+ - locales/en.yml
35
+ - locales/fr.yml
30
36
  - mailchecker.gemspec
37
+ - vendor/assets/javascripts/mailchecker.js.coffee.erb
31
38
  homepage: http://www.mail-checker.com/
32
39
  licenses: []
33
40
  post_install_message: