validates-correios-cep 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb20df2b7029387821c5993e1454d0eeaa2cb52b
4
+ data.tar.gz: 6613876482cdfba84d3b1da856d91ffc07f72cc9
5
+ SHA512:
6
+ metadata.gz: 6a0f49bf0ad5b029a84644b5e4106d91a6ac354751dd7b8017866bed389cf9c065085ba72769bc7285ce2da2014a9c4f8301b314469b9165506e83642e0e00c9
7
+ data.tar.gz: 759c2a4ec6508f18e788a84cd7c25219e88a707675cd723a06064438f0397f5c008fe1ec51ea80e2e0bf5df366f75cc23648efdec21f46184a4af8a4ffef4864
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ sftp-config.json
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Pedro Furtado
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # validates-correios-cep
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/validates-correios-cep.svg)](https://badge.fury.io/rb/validates-correios-cep)
4
+ [![Gem](https://img.shields.io/gem/dt/validates-correios-cep.svg)]()
5
+ [![license](https://img.shields.io/github/license/pedrofurtado/validates-correios-cep.svg)]()
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'validates-correios-cep'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install validates-correios-cep
22
+
23
+ ## Usage
24
+
25
+ ### ActiveRecord models
26
+ ```ruby
27
+ class Person < ActiveRecord::Base
28
+ validates :my_attribute, correios_cep: true
29
+
30
+ # or
31
+
32
+ validates_correios_cep_of :my_attribute
33
+ end
34
+ ```
35
+
36
+ ### Plain Old Ruby Objects
37
+ ```ruby
38
+ class Person
39
+ include ActiveModel::Model
40
+
41
+ validates :my_attribute, correios_cep: true
42
+
43
+ # or
44
+
45
+ validates_correios_cep_of :my_attribute
46
+ end
47
+ ```
48
+
49
+ ## I18n
50
+
51
+ To customize your error messages you can create a locale file like this:
52
+
53
+ ```yaml
54
+ en:
55
+ correios_cep:
56
+ errors:
57
+ messages:
58
+ not_exists: '%{zipcode} is not a existent Brazilian zipcode'
59
+ connection_failed: 'failure on connection with Brazilian Correios API'
60
+ invalid: '%{zipcode} is not a valid Brazilian zipcode'
61
+ timeouted: 'timeout with Brazilian Correios API'
62
+ ```
63
+
64
+ The %{zipcode} contains the zipcode value, filled by user.
65
+
66
+ ## Something wrong with the translations? Contribute it!
67
+
68
+ Send a pull request! Fix the translations or create it for some missing locale. Help us to improves the quality of translations!
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,8 @@
1
+ de:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} es ist nicht eine bestehende brasilianische Postleitzahl'
6
+ connection_failed: 'fehler bei der API der Post in Brasilien verbinden'
7
+ invalid: '%{zipcode} es ist keine gültige brasilianische Postleitzahl'
8
+ timeouted: 'timeout-Antwort mit dem Beitrag API'
@@ -0,0 +1,8 @@
1
+ en:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} is not a existent Brazilian zipcode'
6
+ connection_failed: 'failure on connection with Brazilian Correios API'
7
+ invalid: '%{zipcode} is not a valid Brazilian zipcode'
8
+ timeouted: 'timeout with Brazilian Correios API'
@@ -0,0 +1,8 @@
1
+ es:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} no es una código postal brasileño existente'
6
+ connection_failed: 'no se pudo conectar a la API de Correos en Brasil'
7
+ invalid: '%{zipcode} no es un código postal brasileño válido'
8
+ timeouted: 'tiempo agotado de respuesta de salida a la API de Correos en Brasil'
@@ -0,0 +1,8 @@
1
+ fr:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} il est pas un code postal brésilien existant'
6
+ connection_failed: "impossible de se connecter à l'API du bureau de poste au Brésil"
7
+ invalid: '%{zipcode} il est pas un code postal valide brésilien'
8
+ timeouted: "réponse du délai d'attente avec l'API Poster"
@@ -0,0 +1,8 @@
1
+ it:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} non è un codice postale brasiliano esistente'
6
+ connection_failed: 'impossibile connettersi alle API delle Poste in Brasile'
7
+ invalid: '%{zipcode} non è un codice postale brasiliano valida'
8
+ timeouted: "timeout con l'API Posta"
@@ -0,0 +1,8 @@
1
+ pt-BR:
2
+ correios_cep:
3
+ errors:
4
+ messages:
5
+ not_exists: '%{zipcode} não é um CEP existente'
6
+ connection_failed: 'falha na conexão com a API dos Correios'
7
+ invalid: '%{zipcode} não é um CEP válido'
8
+ timeouted: 'tempo esgotado de resposta com a API dos Correios'
@@ -0,0 +1,3 @@
1
+ require 'validates-correios-cep/version'
2
+ require 'validates-correios-cep/engine'
3
+ require 'validates-correios-cep/activemodel'
@@ -0,0 +1,30 @@
1
+ require 'correios-cep'
2
+ require 'active_model'
3
+
4
+ module ActiveModel
5
+ module Validations
6
+ class CorreiosCepValidator < EachValidator
7
+ CORREIOS_CEP_I18N_SCOPE = 'correios_cep.errors.messages'
8
+
9
+ def validate_each(record, attribute, value)
10
+ error_message_scope = begin
11
+ "#{CORREIOS_CEP_I18N_SCOPE}.not_exists" if Correios::CEP::AddressFinder.get(value).blank?
12
+ rescue EOFError
13
+ "#{CORREIOS_CEP_I18N_SCOPE}.connection_failed"
14
+ rescue ArgumentError
15
+ "#{CORREIOS_CEP_I18N_SCOPE}.invalid"
16
+ rescue Net::OpenTimeout
17
+ "#{CORREIOS_CEP_I18N_SCOPE}.timeouted"
18
+ end
19
+
20
+ record.errors.add(attribute, error_message_scope, zipcode: value) if error_message_scope.present?
21
+ end
22
+ end
23
+
24
+ module HelperMethods
25
+ def validates_correios_cep_of(*attributes)
26
+ validates_with CorreiosCepValidator, _merge_attributes(attributes)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+
3
+ module ValidatesCorreiosCep
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module ValidatesCorreiosCep
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'validates-correios-cep/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'validates-correios-cep'
8
+ spec.version = ValidatesCorreiosCep::VERSION
9
+ spec.authors = ['Pedro Furtado']
10
+ spec.email = ['pedro.felipe.furtado@usp.br']
11
+
12
+ spec.summary = %q{Brazilian zipcode validations for ActiveRecord, integrated with correios-cep gem.}
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/pedrofurtado/validates-correios-cep'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'rails'
21
+ spec.add_dependency 'activemodel'
22
+ spec.add_dependency 'correios-cep'
23
+
24
+ spec.add_development_dependency 'bundler'
25
+ spec.add_development_dependency 'rake'
26
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: validates-correios-cep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pedro Furtado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-05-01 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
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: correios-cep
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: bundler
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: rake
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: Brazilian zipcode validations for ActiveRecord, integrated with correios-cep
84
+ gem.
85
+ email:
86
+ - pedro.felipe.furtado@usp.br
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - config/locales/de.yml
97
+ - config/locales/en.yml
98
+ - config/locales/es.yml
99
+ - config/locales/fr.yml
100
+ - config/locales/it.yml
101
+ - config/locales/pt-BR.yml
102
+ - lib/validates-correios-cep.rb
103
+ - lib/validates-correios-cep/activemodel.rb
104
+ - lib/validates-correios-cep/engine.rb
105
+ - lib/validates-correios-cep/version.rb
106
+ - validates-correios-cep.gemspec
107
+ homepage: https://github.com/pedrofurtado/validates-correios-cep
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Brazilian zipcode validations for ActiveRecord, integrated with correios-cep
131
+ gem.
132
+ test_files: []