validocno 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/validocno/validator.rb +35 -3
- data/lib/validocno/version.rb +1 -1
- data/lib/validocno.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3dcc97a6fc2dbf8e31d24f40a1ccd292f3e006
|
4
|
+
data.tar.gz: 2d0e220cae2235931d5fe2f4ae1aeebef279b9bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec4aa02e190faba1fce5ff17005633cd56cf7600b175110aad2fb44277584b9eb0beb5adf4e62a2a8ddd7b0862c3c01a1cff8281be9832cd0927d170d5a4da55
|
7
|
+
data.tar.gz: dd00d4950ad63e9b2db3b236b288982aec051b04b3ee739dad9838d5b693d0e7db53505b2e1e4b7053302acf25d8b2e50970294f8712fcefbe9aa7a557843c72
|
data/lib/validocno/validator.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Validocno
|
2
2
|
class Validator
|
3
|
+
# Set strings to UTF-8 mode
|
4
|
+
$KCODE = 'UTF-8'
|
5
|
+
|
3
6
|
CONTROL_URI = 'http://politsei.ee/et/teenused/e-paringud/dokumendi-kehtivuse-kontroll/'
|
4
7
|
|
5
8
|
def initialize(doc_number)
|
@@ -9,7 +12,15 @@ module Validocno
|
|
9
12
|
|
10
13
|
def csrf_token
|
11
14
|
response = Validocno::Client.get(CONTROL_URI)
|
12
|
-
response
|
15
|
+
check_response(response)
|
16
|
+
|
17
|
+
node = response.at_css('form[name="reqForm"] input[name="csrf"]')
|
18
|
+
|
19
|
+
if node.nil? || node['value'].nil?
|
20
|
+
fail StandardError, 'CSRF token was not found on page'
|
21
|
+
else
|
22
|
+
node['value']
|
23
|
+
end
|
13
24
|
end
|
14
25
|
|
15
26
|
def response_string
|
@@ -22,12 +33,33 @@ module Validocno
|
|
22
33
|
}
|
23
34
|
|
24
35
|
response = Validocno::Client.post(CONTROL_URI, options)
|
25
|
-
response
|
36
|
+
check_response(response)
|
37
|
+
|
38
|
+
node = response.at_css('#content1left')
|
39
|
+
|
40
|
+
if node.nil? || node.children.empty?
|
41
|
+
fail StandardError, 'Cannot parse document status string.'
|
42
|
+
else
|
43
|
+
node.children.last.text.strip
|
44
|
+
end
|
26
45
|
end
|
27
46
|
|
28
47
|
def valid?
|
29
|
-
return true if response_string.match(
|
48
|
+
return true if response_string.match(response_strings[:valid])
|
30
49
|
false
|
31
50
|
end
|
51
|
+
|
52
|
+
def response_strings
|
53
|
+
{
|
54
|
+
:valid => "Dokument #{@doc_number} on kehtiv.",
|
55
|
+
:expired => "Dokument #{@doc_number} on kehtetu.",
|
56
|
+
:invalid => "Dokumenti #{@doc_number} ei ole välja antud."
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def check_response(response)
|
61
|
+
return true if response.code == 200
|
62
|
+
fail StandardError, "#{response.code}: #{response.message}"
|
63
|
+
end
|
32
64
|
end
|
33
65
|
end
|
data/lib/validocno/version.rb
CHANGED
data/lib/validocno.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validocno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Pakk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-03 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: &id001 !ruby/object:Gem::Requirement
|