vat_number_validator 0.0.2 → 0.0.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9328a1ef6c901e4c3b819fcf6cfdeb638c8f6f1a
|
4
|
+
data.tar.gz: 7d858bf4fe1a85ed3a76ed0340c55a62fbd1a126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1324c8560f663ecca55c7e26a3e8f18be90c629006fb26a72d48c5cc452a886c8b021cbbde2e2929cb1465505f1150164f9ccff947aff2b160395aa7bdb985c
|
7
|
+
data.tar.gz: a2707a829eeee18aed335c3207b6a3c35e75ec5f19494d175b4b6f1931dd91e3d62107e1f9c724ce8288ef2b21c75c9f3bcaad7fc5c597272175f831b1c3e41e
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class VatNumberValidator
|
2
2
|
class APIError < StandardError
|
3
3
|
def initialize(result)
|
4
|
-
|
4
|
+
code = result['error']['code']
|
5
|
+
message = case code
|
5
6
|
when 101
|
6
7
|
'invalid/missing access_key'
|
7
8
|
when 104
|
@@ -11,7 +12,7 @@ class VatNumberValidator
|
|
11
12
|
when 102
|
12
13
|
'inactive user'
|
13
14
|
else
|
14
|
-
"vatlayer API error code #{
|
15
|
+
"vatlayer API error code #{code}"
|
15
16
|
end
|
16
17
|
super(message)
|
17
18
|
end
|
data/lib/vat_number_validator.rb
CHANGED
@@ -6,7 +6,7 @@ class VatNumberValidator < ActiveModel::EachValidator
|
|
6
6
|
|
7
7
|
include HTTParty
|
8
8
|
|
9
|
-
base_uri '
|
9
|
+
base_uri 'https://apilayer.net/api'
|
10
10
|
|
11
11
|
def validate_each(record, attribute, value)
|
12
12
|
unless valid?(value)
|
@@ -18,7 +18,7 @@ class VatNumberValidator < ActiveModel::EachValidator
|
|
18
18
|
|
19
19
|
def valid?(value)
|
20
20
|
result = self.class.get('/validate', http_options(value))
|
21
|
-
raise(
|
21
|
+
raise(APIError.new(result)) if result['success'] == false
|
22
22
|
result['valid']
|
23
23
|
end
|
24
24
|
|