validocno 0.0.1 → 0.0.2

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
  SHA512:
3
- data.tar.gz: 25bbddece6831e40a60e0eb6f22f9997844ad49b129f9adb303923d059cc801db30748d3c8455da930d1160f28175aa3bdaf205ab70be29dd4677900932a346c
4
- metadata.gz: 8535cc61da15947c2ae74b66edf66ab3c10cb45196c11a41177870334519d2d028b8d935e3137fd5d52029219adb19d803c8748bc2e9df111bb2d80fda0f1259
3
+ data.tar.gz: e304093ade6b07869240f13b2d965bc886afe6837287275c333abeadb5821cf1bf8585c0fbd6e4a340f63d12f383f89ee238257229a2f867112b0f593a72acef
4
+ metadata.gz: 8b8f554d4ec2eb480ff705872599f6394e32b5d07bf2389344f676c0f8a7c5e485922476b57d9d7688b1dd67bccf98fadf014612f3a222836e933a18de97f3a5
5
5
  SHA1:
6
- data.tar.gz: 52a602f7dfd4139430d88b238ac543e9c1acf426
7
- metadata.gz: fc104f1ef30312c70dc88f74ec4fabc1e1f5b87d
6
+ data.tar.gz: f74e88f86daa236c21f3dcc5e51fadc0588ff5c8
7
+ metadata.gz: 7df0320c190898d2d4c5829ab1d5015385134656
data/README.md CHANGED
@@ -19,9 +19,15 @@ Or install it yourself as:
19
19
  $ gem install validocno
20
20
 
21
21
  ## Usage
22
+ > require 'validocno'
22
23
 
23
- > document = Validoc.new "A1234567"
24
+ > document = Validocno::Validator.new 'A1234567'
24
25
  > document.valid?
26
+ => true
27
+
28
+ > document = Validocno::Validator.new 'A1234567890'
29
+ > document.valid?
30
+ => false
25
31
 
26
32
  ## Contributing
27
33
 
@@ -0,0 +1,18 @@
1
+ class HtmlParserIncluded < HTTParty::Parser
2
+ SupportedFormats.merge!('text/html' => :html)
3
+
4
+ def html
5
+ Nokogiri::HTML(body)
6
+ end
7
+ end
8
+
9
+ module Validocno
10
+ class Client
11
+ include HTTParty
12
+ parser HtmlParserIncluded
13
+
14
+ USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25'
15
+
16
+ headers 'Accept-Language' => 'en-US,en;q=0.5', 'User-Agent' => USER_AGENT
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module Validocno
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.2'
3
3
  end
data/lib/validocno.rb CHANGED
@@ -1,15 +1,45 @@
1
+
1
2
  $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
2
3
  $LOAD_PATH.include?(File.dirname(__FILE__)) ||
3
- $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
+ $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
5
 
5
6
  require 'rubygems'
6
7
  require 'httparty'
7
8
  require 'nokogiri'
8
9
 
9
10
  require 'validocno/version'
11
+ require 'validocno/http_client'
10
12
 
11
13
  module Validocno
12
- def self.valid?(doc_number = '')
13
- fail NotImplementedError
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
14
44
  end
15
45
  end
data/rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ # Ruby 1.8.7 needs the . on a chain of method calls at the end of a line.
2
+ Style/DotPosition:
3
+ EnforcedStyle: trailing
4
+
5
+ # Ruby 1.8.7 doesn't have the -> lambda
6
+ Style/Lambda:
7
+ Enabled: false
8
+
9
+ # Ruby 1.8.7 doesn't have 1.9 style hash syntax
10
+ Style/HashSyntax:
11
+ EnforcedStyle: hash_rockets
12
+
13
+ Documentation:
14
+ Enabled: false
@@ -0,0 +1 @@
1
+ require 'validocno'
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
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
14
+
15
+ end
16
+
17
+ describe '#valid?' do
18
+ it 'returns true when document with valid number provided' do
19
+ validator = Validocno::Validator.new('A1234567')
20
+ expect(validator).to be_valid
21
+ end
22
+
23
+ it 'returns false when document with invalid number provided' do
24
+ validator = Validocno::Validator.new('A123456789')
25
+ expect(validator).to_not be_valid
26
+ end
27
+ end
28
+ end
data/validocno.gemspec CHANGED
@@ -7,17 +7,17 @@ Gem::Specification.new do |spec|
7
7
  spec.name = 'validocno'
8
8
  spec.version = Validocno::VERSION
9
9
  spec.authors = ['Artem Pakk']
10
- spec.email = ['apakk@me.com']
11
- spec.summary = %q{Estonian ID card validator}
12
- spec.description = %q{Ruby gem to check validity of Estonian ID card}
13
- spec.homepage = ""
10
+ spec.email = ['artem.pakk@deskrock.ee']
11
+ spec.summary = 'Estonian ID card validator'
12
+ spec.description = 'Ruby gem to check validity of Estonian ID card'
13
+ spec.homepage = 'https://github.com/deskrock/validocno'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.test_files = spec.files.grep(/^(spec)\//)
19
18
  spec.require_paths = ['lib']
20
19
 
20
+ spec.required_ruby_version = '>= 1.8.7'
21
21
  spec.add_dependency 'httparty', '~> 0.11.0'
22
22
  spec.add_dependency 'nokogiri', '~> 1.5.10'
23
23
  spec.add_development_dependency 'bundler', '~> 1.7'
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.1
4
+ version: 0.0.2
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-01 00:00:00 Z
12
+ date: 2014-12-02 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -63,7 +63,7 @@ dependencies:
63
63
  name: rspec
64
64
  description: Ruby gem to check validity of Estonian ID card
65
65
  email:
66
- - apakk@me.com
66
+ - artem.pakk@deskrock.ee
67
67
  executables: []
68
68
 
69
69
  extensions: []
@@ -77,9 +77,13 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - lib/validocno.rb
80
+ - lib/validocno/http_client.rb
80
81
  - lib/validocno/version.rb
82
+ - rubocop.yml
83
+ - spec/spec_helper.rb
84
+ - spec/validocno_spec.rb
81
85
  - validocno.gemspec
82
- homepage: ""
86
+ homepage: https://github.com/deskrock/validocno
83
87
  licenses:
84
88
  - MIT
85
89
  metadata: {}
@@ -91,13 +95,14 @@ require_paths:
91
95
  - lib
92
96
  required_ruby_version: !ruby/object:Gem::Requirement
93
97
  requirements:
94
- - &id006
95
- - ">="
98
+ - - ">="
96
99
  - !ruby/object:Gem::Version
97
- version: "0"
100
+ version: 1.8.7
98
101
  required_rubygems_version: !ruby/object:Gem::Requirement
99
102
  requirements:
100
- - *id006
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: "0"
101
106
  requirements: []
102
107
 
103
108
  rubyforge_project:
@@ -105,5 +110,6 @@ rubygems_version: 2.0.14
105
110
  signing_key:
106
111
  specification_version: 4
107
112
  summary: Estonian ID card validator
108
- test_files: []
109
-
113
+ test_files:
114
+ - spec/spec_helper.rb
115
+ - spec/validocno_spec.rb