vat_number_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: 5a8f734b0459697644ea94771a7193655de318f6
4
+ data.tar.gz: 2cb8d0188487bbd1cc2967f0de8d5113e3b975ee
5
+ SHA512:
6
+ metadata.gz: 9aa4ed9bf6d34329a86aa52a56c768273ca42be844d8b1a9c7257dd33fb6660c617a4029d246eb01a21e3a0b1e3a88a53c4e2701ba27c1e9e58b0aa68be89389
7
+ data.tar.gz: cde35920220ca182bfbf07180cc10ec389bcba3a16c0c1ea8e3b265eea799adb8933fff471df8bb6c1f32adcbec0f93073bbc8f10fd240e1d0012d0c757f3354
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /vendor/bundle
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 efigence
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,34 @@
1
+ require 'httparty'
2
+ require 'pry'
3
+
4
+ class VatNumberValidator < ActiveModel::EachValidator
5
+ require 'vat_number_validator/configuration'
6
+ require 'vat_number_validator/errors'
7
+
8
+ include HTTParty
9
+
10
+ base_uri 'http://apilayer.net/api'
11
+
12
+ def validate_each(record, attribute, value)
13
+ unless valid?(value)
14
+ record.errors.add(attribute, :incorrect_vat_number_format)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def valid?(value)
21
+ result = self.class.get('/validate', http_options(value))
22
+ raise(VatlayerError.new(result)) if result['success'] == false
23
+ result['valid']
24
+ end
25
+
26
+ def http_options(value)
27
+ {
28
+ query: {
29
+ access_key: Configuration.access_key,
30
+ vat_number: value
31
+ }
32
+ }
33
+ end
34
+ end
@@ -0,0 +1,9 @@
1
+ require 'confiture'
2
+
3
+ class VatNumberValidator
4
+ class Configuration
5
+ include Confiture::Configuration
6
+
7
+ confiture_allowed_keys(:access_key)
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ class VatNumberValidator
2
+ class APIError < StandardError
3
+ def initialize(result)
4
+ message = case result['code']
5
+ when 101
6
+ 'invalid/missing access_key'
7
+ when 104
8
+ 'usage limit reached'
9
+ when 105
10
+ 'https access restricted'
11
+ when 102
12
+ 'inactive user'
13
+ else
14
+ "vatlayer API error code #{result['code']}"
15
+ end
16
+ super(message)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'vat_number_validator'
3
+ s.version = '0.0.1'
4
+ s.authors = 'Marek Lipka'
5
+ s.summary = 'Vat number validator'
6
+ s.description = 'Vat number validator for Rails 3+ using vatlayer.com API'
7
+ s.email = 'mlipka@artegence.com'
8
+ s.files = `git ls-files`.split("\n")
9
+ s.homepage = 'https://github.com/efigence/vat_number_validator'
10
+ s.license = 'MIT'
11
+
12
+ s.require_paths = %w(lib)
13
+
14
+ s.add_dependency('activemodel', '>= 3')
15
+ s.add_dependency('confiture', '~> 0.1.4')
16
+ s.add_dependency('httparty', '~> 0.13.5')
17
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vat_number_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Marek Lipka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: confiture
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.5
55
+ description: Vat number validator for Rails 3+ using vatlayer.com API
56
+ email: mlipka@artegence.com
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - LICENSE
63
+ - lib/vat_number_validator.rb
64
+ - lib/vat_number_validator/configuration.rb
65
+ - lib/vat_number_validator/errors.rb
66
+ - vat_number_validator.gemspec
67
+ homepage: https://github.com/efigence/vat_number_validator
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Vat number validator
91
+ test_files: []