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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39e93c3f4784161ad642f67ef31d5c01097e42a8
4
- data.tar.gz: b52f0bcc45b4ce28c05c2042d5b9fe1fb3ae5440
3
+ metadata.gz: 1c3dcc97a6fc2dbf8e31d24f40a1ccd292f3e006
4
+ data.tar.gz: 2d0e220cae2235931d5fe2f4ae1aeebef279b9bf
5
5
  SHA512:
6
- metadata.gz: 0248dd8e7065aa7d53787eef3007ad7fad74e85cd01fa348f37906b4acecfaabb9067fe6729d5f3439b2198d1a558cabd725f4f93127b534da592dea14180a92
7
- data.tar.gz: fe920d230f9cb9383f7982a40a0846870d8f21ccd83c876a8aba1f8bd5124b7d9210ef57573e728290b967bc3533dea1121f487f21f4973a3c4dee5fa382a0c2
6
+ metadata.gz: ec4aa02e190faba1fce5ff17005633cd56cf7600b175110aad2fb44277584b9eb0beb5adf4e62a2a8ddd7b0862c3c01a1cff8281be9832cd0927d170d5a4da55
7
+ data.tar.gz: dd00d4950ad63e9b2db3b236b288982aec051b04b3ee739dad9838d5b693d0e7db53505b2e1e4b7053302acf25d8b2e50970294f8712fcefbe9aa7a557843c72
@@ -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.at_css('#content1left form input[name="csrf"]')['value']
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.at_css('#content1left').children.last.text.strip.to_s
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(/on kehtiv/)
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
@@ -1,3 +1,3 @@
1
1
  module Validocno
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/validocno.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
3
2
  $LOAD_PATH.include?(File.dirname(__FILE__)) ||
4
3
  $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
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.3
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-02 00:00:00 Z
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