validocno 0.0.2 → 0.0.3

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
- SHA512:
3
- data.tar.gz: e304093ade6b07869240f13b2d965bc886afe6837287275c333abeadb5821cf1bf8585c0fbd6e4a340f63d12f383f89ee238257229a2f867112b0f593a72acef
4
- metadata.gz: 8b8f554d4ec2eb480ff705872599f6394e32b5d07bf2389344f676c0f8a7c5e485922476b57d9d7688b1dd67bccf98fadf014612f3a222836e933a18de97f3a5
5
2
  SHA1:
6
- data.tar.gz: f74e88f86daa236c21f3dcc5e51fadc0588ff5c8
7
- metadata.gz: 7df0320c190898d2d4c5829ab1d5015385134656
3
+ metadata.gz: 39e93c3f4784161ad642f67ef31d5c01097e42a8
4
+ data.tar.gz: b52f0bcc45b4ce28c05c2042d5b9fe1fb3ae5440
5
+ SHA512:
6
+ metadata.gz: 0248dd8e7065aa7d53787eef3007ad7fad74e85cd01fa348f37906b4acecfaabb9067fe6729d5f3439b2198d1a558cabd725f4f93127b534da592dea14180a92
7
+ data.tar.gz: fe920d230f9cb9383f7982a40a0846870d8f21ccd83c876a8aba1f8bd5124b7d9210ef57573e728290b967bc3533dea1121f487f21f4973a3c4dee5fa382a0c2
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
- -format documentation
data/README.md CHANGED
@@ -21,12 +21,10 @@ Or install it yourself as:
21
21
  ## Usage
22
22
  > require 'validocno'
23
23
 
24
- > document = Validocno::Validator.new 'A1234567'
25
- > document.valid?
24
+ > Validocno.valid?('A1234567')
26
25
  => true
27
26
 
28
- > document = Validocno::Validator.new 'A1234567890'
29
- > document.valid?
27
+ > Validocno.valid?('A1234567890')
30
28
  => false
31
29
 
32
30
  ## Contributing
@@ -0,0 +1,33 @@
1
+ module Validocno
2
+ class Validator
3
+ CONTROL_URI = 'http://politsei.ee/et/teenused/e-paringud/dokumendi-kehtivuse-kontroll/'
4
+
5
+ def initialize(doc_number)
6
+ @doc_number = doc_number
7
+ @csrf_token = csrf_token
8
+ end
9
+
10
+ def csrf_token
11
+ response = Validocno::Client.get(CONTROL_URI)
12
+ response.at_css('#content1left form input[name="csrf"]')['value']
13
+ end
14
+
15
+ def response_string
16
+ options = {
17
+ :query => {
18
+ :cmd => 'request',
19
+ :csrf => @csrf_token,
20
+ :docNumber => @doc_number
21
+ }
22
+ }
23
+
24
+ response = Validocno::Client.post(CONTROL_URI, options)
25
+ response.at_css('#content1left').children.last.text.strip.to_s
26
+ end
27
+
28
+ def valid?
29
+ return true if response_string.match(/on kehtiv/)
30
+ false
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module Validocno
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/validocno.rb CHANGED
@@ -7,39 +7,13 @@ require 'rubygems'
7
7
  require 'httparty'
8
8
  require 'nokogiri'
9
9
 
10
+ require 'validocno/validator'
10
11
  require 'validocno/version'
11
12
  require 'validocno/http_client'
12
13
 
13
14
  module Validocno
14
- class Validator
15
- CONTROL_URI = 'http://politsei.ee/et/teenused/e-paringud/dokumendi-kehtivuse-kontroll/'
16
-
17
- def initialize(doc_number)
18
- @doc_number = doc_number
19
- @csrf_token = csrf_token
20
- end
21
-
22
- def csrf_token
23
- response = Validocno::Client.get(CONTROL_URI)
24
- response.at_css('#content1left form input[name="csrf"]')['value']
25
- end
26
-
27
- def response_string
28
- options = {
29
- :query => {
30
- :cmd => 'request',
31
- :csrf => @csrf_token,
32
- :docNumber => @doc_number
33
- }
34
- }
35
-
36
- response = Validocno::Client.post(CONTROL_URI, options)
37
- response.at_css('#content1left').children.last.text.strip.to_s
38
- end
39
-
40
- def valid?
41
- return true if response_string.match(/on kehtiv/)
42
- false
43
- end
15
+ def self.valid?(doc_number)
16
+ validator = Validocno::Validator.new(doc_number)
17
+ validator.valid?
44
18
  end
45
19
  end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validocno::Validator do
4
+ let(:doc_number) { 'A1234567' }
5
+ let(:validator) { Validocno::Validator.new(doc_number) }
6
+
7
+ describe '.new' do
8
+ it 'initializes with a document number' do
9
+ expect(validator).to be
10
+ expect { validator }.to_not raise_error
11
+ end
12
+
13
+ it 'raises an error without a document number' do
14
+ expect { Validocno::Validator.new }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'sets csrf_token instance variable' do
18
+ expect(validator.csrf_token).to_not be_nil
19
+ end
20
+
21
+ end
22
+
23
+ describe '#valid?' do
24
+ let(:invalid_doc_number) { 'A1234567890' }
25
+ let(:invalid_validator) { Validocno::Validator.new(invalid_doc_number) }
26
+
27
+ it 'returns true when document with valid number provided' do
28
+ expect(validator).to be_valid
29
+ end
30
+
31
+ it 'returns false when document with invalid number provided' do
32
+ expect(invalid_validator).to_not be_valid
33
+ end
34
+ end
35
+ end
@@ -1,28 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Validocno::Validator do
4
- describe '#initialize' do
5
- it 'initializes new Validator object with document number' do
6
- validator = Validocno::Validator.new('A1234567')
7
- expect(validator).to be
8
- end
9
-
10
- it 'sets csrf_token instance variable' do
11
- validator = Validocno::Validator.new('A1234567')
12
- expect(validator.csrf_token).to_not be_nil
13
- end
3
+ describe Validocno do
4
+ describe '.valid?' do
5
+ let(:valid_doc_number) { 'A1234567' }
6
+ let(:invalid_doc_number) { 'A1234567890' }
14
7
 
15
- end
16
-
17
- describe '#valid?' do
18
8
  it 'returns true when document with valid number provided' do
19
- validator = Validocno::Validator.new('A1234567')
20
- expect(validator).to be_valid
9
+ expect(Validocno.valid?(valid_doc_number)).to be true
21
10
  end
22
11
 
23
12
  it 'returns false when document with invalid number provided' do
24
- validator = Validocno::Validator.new('A123456789')
25
- expect(validator).to_not be_valid
13
+ expect(Validocno.valid?(invalid_doc_number)).to be false
14
+ end
15
+
16
+ it 'raises an error without a document number' do
17
+ expect { Validocno.valid? }.to raise_error(ArgumentError)
26
18
  end
27
19
  end
28
20
  end
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Pakk
@@ -72,15 +72,18 @@ extra_rdoc_files: []
72
72
 
73
73
  files:
74
74
  - .gitignore
75
+ - .rspec
75
76
  - Gemfile
76
77
  - LICENSE
77
78
  - README.md
78
79
  - Rakefile
79
80
  - lib/validocno.rb
80
81
  - lib/validocno/http_client.rb
82
+ - lib/validocno/validator.rb
81
83
  - lib/validocno/version.rb
82
84
  - rubocop.yml
83
85
  - spec/spec_helper.rb
86
+ - spec/validator_spec.rb
84
87
  - spec/validocno_spec.rb
85
88
  - validocno.gemspec
86
89
  homepage: https://github.com/deskrock/validocno
@@ -112,4 +115,5 @@ specification_version: 4
112
115
  summary: Estonian ID card validator
113
116
  test_files:
114
117
  - spec/spec_helper.rb
118
+ - spec/validator_spec.rb
115
119
  - spec/validocno_spec.rb