vat_number_validator 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/vat_number_validator.rb +7 -5
- data/vat_number_validator.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f71a631e6dc07ab612c1e57c685697872108dc
|
4
|
+
data.tar.gz: 1f198faa7e5c9dbe9650ba6113cbd33be55028d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9fc346a317af51e949308e7678ab57d430f6b936db078dbc2d94475a1979423128f112aea069ccdae336d20bb3fb84cc6036ed1d081e5e851704c30c5554b51
|
7
|
+
data.tar.gz: e83fdb4fb0ccbb4f416d7fc4ed50c7293be2b59b22a9286a0a2c35e8ce2057b1ffa83529ad2edee2250bc4d8b7ec80104792fa19cac1bb50081e48bcc146a451
|
data/lib/vat_number_validator.rb
CHANGED
@@ -4,10 +4,6 @@ class VatNumberValidator < ActiveModel::EachValidator
|
|
4
4
|
require 'vat_number_validator/configuration'
|
5
5
|
require 'vat_number_validator/errors'
|
6
6
|
|
7
|
-
include HTTParty
|
8
|
-
|
9
|
-
base_uri 'https://apilayer.net/api'
|
10
|
-
|
11
7
|
def validate_each(record, attribute, value)
|
12
8
|
unless valid?(value)
|
13
9
|
record.errors.add(attribute, :incorrect_vat_number_format)
|
@@ -16,8 +12,14 @@ class VatNumberValidator < ActiveModel::EachValidator
|
|
16
12
|
|
17
13
|
private
|
18
14
|
|
15
|
+
def base_uri
|
16
|
+
use_https = Configuration.use_https
|
17
|
+
protocol = use_https ? 'https' : 'http'
|
18
|
+
"#{protocol}://apilayer.net/api"
|
19
|
+
end
|
20
|
+
|
19
21
|
def valid?(value)
|
20
|
-
result =
|
22
|
+
result = HTTParty.get(base_uri + '/validate', http_options(value))
|
21
23
|
raise(APIError.new(result)) if result['success'] == false
|
22
24
|
result['valid']
|
23
25
|
end
|