justicecz 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e4c1aa2fe3b0953dc713f9f5a4da6f0846531880
4
+ data.tar.gz: 9d707f1f30b468cf1fe184f2bf9cb1469b42b2f4
5
+ SHA512:
6
+ metadata.gz: 0c03b3042bc2ef13344dbf194dca7ccf18b1fe2ae0ad81c1e8ea0a85387538a515f15bdf176d59464f43775815a1c729a6eb3e5f2c58e61bd3a1fee61bfb1c0b
7
+ data.tar.gz: 94d58017c27d44702e9ddfa3cf2c3fed028235bbe324e1dfc39682cf7ed2c500a917173a6316ff33743de8f1491396750e0493f6c9f1d88cedc34c0edf9ae045
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'db/**/*'
5
+ - 'bin/**/*'
6
+ - 'app/views/contacts/*.json.jbuilder'
7
+ - 'config/**/*'
8
+ CacheRootDirectory: '../../tmp'
9
+
10
+ Rails:
11
+ Enabled: true
12
+
13
+ Style/FrozenStringLiteralComment:
14
+ Enabled: false
15
+
16
+ Style/GuardClause:
17
+ Enabled: false
18
+
19
+ Style/WordArray:
20
+ MinSize: 3
21
+
22
+ Style/SymbolProc:
23
+ IgnoredMethods: validate
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/AndOr:
29
+ EnforcedStyle: conditionals
30
+
31
+ Metrics/LineLength:
32
+ Max: 89
33
+
34
+ Style/AlignHash:
35
+ EnforcedLastArgumentHashStyle: 'ignore_implicit'
36
+
37
+ Style/AlignParameters:
38
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ justicecz
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.10.6
6
+ after_success: bundle exec codeclimate-test-reporter
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in justicecz.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Andrej Antas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Justicecz
2
+
3
+ [![Build Status](https://travis-ci.org/redrick/justicecz.svg?branch=master)](https://travis-ci.org/redrick/justicecz)
4
+
5
+ COMMING SOON
6
+
7
+ SDK for accessing data from [justice.cz](https://or.justice.cz/ias/ui/rejstrik-$firma)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'justicecz'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install justicecz
22
+
23
+ ## Usage
24
+
25
+ In this first version you can query justice.cz looking for specific ICO:
26
+
27
+ ```ruby
28
+ Justicecz::Query.query(ico: '04564634')
29
+ ```
30
+
31
+ Which will give you nicely formatted Hash for further processing:
32
+
33
+ ```
34
+ {
35
+ "Název subjektu:" => "autokosmetika s.r.o.",
36
+ "IČO:" => "04564634",
37
+ "Spisová značka:" => "C 249833 vedená u Městského soudu v Praze",
38
+ "Den zápisu:" => "13. listopadu 2015",
39
+ "Sídlo:" => "Jičínská 226/17, Žižkov, 130 00 Praha 3"
40
+ }
41
+ ```
42
+
43
+
44
+ ## Thanks
45
+
46
+ [Tomas Dvorak](https://github.com/todvora) for his article on problems with [justice.cz](https://www.tomas-dvorak.cz/posts/nacitani-dat-z-obchodniho-rejstriku-justicecz/)
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/[my-github-username]/justicecz/fork )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'irb'
4
+ require 'irb/completion'
5
+
6
+ require 'bundler/setup'
7
+ require 'justicecz'
8
+
9
+ IRB.start
data/justicecz.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'justicecz/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'justicecz'
8
+ spec.version = Justicecz::VERSION
9
+ spec.authors = ['Andrej Antas']
10
+ spec.email = ['andrej@antas.cz']
11
+ spec.summary = 'SDK for quering or.justice.cz'
12
+ spec.description = 'SDK for quering or.justice.cz'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
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)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'rubocop'
26
+ spec.add_development_dependency 'vcr'
27
+ spec.add_development_dependency 'codeclimate-test-reporter'
28
+
29
+ spec.add_runtime_dependency 'nokogiri'
30
+ spec.add_runtime_dependency 'faraday'
31
+ end
@@ -0,0 +1,15 @@
1
+ module Justicecz
2
+ class Connection
3
+ URL = 'https://or.justice.cz'.freeze
4
+
5
+ def initialize
6
+ @connection = ::Faraday.new(url: URL) do |faraday|
7
+ faraday.adapter Faraday.default_adapter
8
+ end
9
+ end
10
+
11
+ def get(uri)
12
+ @connection.get(uri)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ module Justicecz
2
+ module Entities
3
+ class Company
4
+ ATTRIBUTES = %i(title misc ico file_number registered_at residence)
5
+
6
+ attr_accessor(*ATTRIBUTES)
7
+
8
+ def initialize(params = {})
9
+ return if params.empty?
10
+ params.each do |k, v|
11
+ self.public_send("#{k}=", v)
12
+ end
13
+ end
14
+
15
+ ATTRIBUTES.each do |attr|
16
+ define_method "#{attr}_full" do
17
+ key = ::Justicecz::Misc::ParamsLookup.by_key(attr)
18
+ "#{key}: #{self.public_send(attr)}"
19
+ end
20
+ end
21
+
22
+ ATTRIBUTES.each do |attr|
23
+ define_method "#{attr}_header" do
24
+ ::Justicecz::Misc::ParamsLookup.by_key(attr)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ module Justicecz
2
+ module Entities
3
+ class List
4
+ attr_accessor :items
5
+
6
+ def initialize(items = nil)
7
+ @items = items || []
8
+ end
9
+
10
+ def <<(company)
11
+ items << company
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module Justicecz
2
+ module Html
3
+ class ResultLine
4
+ def initialize(result_line)
5
+ @result_line = result_line
6
+ @company = ::Justicecz::Entities::Company.new
7
+ end
8
+
9
+ def self.line(result_line)
10
+ new(result_line).line
11
+ end
12
+
13
+ def line
14
+ return nil if headers.empty?
15
+ parse_line
16
+ @company
17
+ end
18
+
19
+ private
20
+
21
+ def parse_line
22
+ headers.each_with_index do |element, index|
23
+ header = to_header(element)
24
+ key = ::Justicecz::Misc::ParamsLookup.by_value(header)
25
+ data = element.next_element
26
+ @company.public_send("#{key}=", to_data(data))
27
+ end
28
+ end
29
+
30
+ def to_header(element)
31
+ element.children.text.gsub(/:$/, '')
32
+ end
33
+
34
+ def to_data(element)
35
+ data = element.children.map(&:text).map do |text|
36
+ text.gsub(/\t|\n/, '').strip
37
+ end.reject(&:empty?)
38
+ @company.misc = data.slice(1..-1).join(', ') if data.slice(1..-1).count.positive?
39
+ data.first
40
+ end
41
+
42
+ def headers
43
+ @result_line.search('th')
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ module Justicecz
2
+ module Html
3
+ class ResultList
4
+ def initialize(body)
5
+ @body = body
6
+ end
7
+
8
+ def self.collection(body)
9
+ new(body).collection
10
+ end
11
+
12
+ def collection
13
+ @body.search('li.result table.result-details')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ module Justicecz
2
+ class HtmlParser
3
+ def initialize(body)
4
+ @body = ::Nokogiri::HTML(body)
5
+ @collection = ::Justicecz::Entities::List.new
6
+ end
7
+
8
+ def self.parse(body)
9
+ new(body).parse
10
+ end
11
+
12
+ def parse
13
+ parse_response
14
+ @collection
15
+ end
16
+
17
+ private
18
+
19
+ def result_collection
20
+ Justicecz::Html::ResultList.collection(@body)
21
+ end
22
+
23
+ def parse_response
24
+ result_collection.each do |result|
25
+ next unless Justicecz::Html::ResultLine.line(result)
26
+ @collection << Justicecz::Html::ResultLine.line(result)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module Justicecz
2
+ module Misc
3
+ class ParamsLookup
4
+ PARAMS_MAP = {
5
+ title: 'Název subjektu',
6
+ misc: 'Ostatní informace',
7
+ ico: 'IČO',
8
+ file_number: 'Spisová značka',
9
+ registered_at: 'Den zápisu',
10
+ residence: 'Sídlo'
11
+ }
12
+
13
+ def self.by_key(key)
14
+ PARAMS_MAP[key]
15
+ end
16
+
17
+ def self.by_value(value)
18
+ PARAMS_MAP.key(value)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ module Justicecz
2
+ class Query
3
+ def initialize(query_params)
4
+ @query_params = query_params
5
+ end
6
+
7
+ def self.query(ico)
8
+ new(ico).query
9
+ end
10
+
11
+ def query
12
+ parse_response
13
+ end
14
+
15
+ private
16
+
17
+ def parse_response
18
+ HtmlParser.parse(response.body)
19
+ end
20
+
21
+ def connection
22
+ Connection.new
23
+ end
24
+
25
+ def response
26
+ connection.get "/ias/ui/rejstrik-$firma?#{formatted_query_params}"
27
+ end
28
+
29
+ def formatted_query_params
30
+ query = [].tap do |query_array|
31
+ @query_params.each do |key, value|
32
+ query_array << "#{key}=#{value}"
33
+ end
34
+ end
35
+ query.join('&')
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ module Justicecz
2
+ VERSION = '0.1.1'.freeze
3
+ end
data/lib/justicecz.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'justicecz/version'
2
+
3
+ require 'faraday'
4
+ require 'nokogiri'
5
+
6
+ require 'justicecz/html/result_list'
7
+ require 'justicecz/html/result_line'
8
+
9
+ require 'justicecz/entities/list'
10
+ require 'justicecz/entities/company'
11
+
12
+ require 'justicecz/misc/params_lookup'
13
+
14
+ require 'justicecz/connection'
15
+ require 'justicecz/html_parser'
16
+ require 'justicecz/query'
17
+
18
+ module Justicecz
19
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'justicecz'
3
+ require 'faraday'
4
+ require 'nokogiri'
5
+ require 'vcr'
6
+
7
+ require 'simplecov'
8
+ SimpleCov.start
9
+
10
+ VCR.configure do |config|
11
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
12
+ config.hook_into :faraday
13
+ config.default_cassette_options = { record: :once }
14
+ config.before_record { |i| i.response.body.force_encoding 'UTF-8' }
15
+ config.before_record do |i|
16
+ i.request.headers.clear
17
+ save_headers = %w(Total Per-Page Link Content-Type Content-Length)
18
+ i.response.headers.select! { |key| save_headers.include? key }
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: justicecz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Andrej Antas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: codeclimate-test-reporter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: SDK for quering or.justice.cz
140
+ email:
141
+ - andrej@antas.cz
142
+ executables:
143
+ - console
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rubocop.yml"
149
+ - ".ruby-gemset"
150
+ - ".ruby-version"
151
+ - ".travis.yml"
152
+ - Gemfile
153
+ - LICENSE.txt
154
+ - README.md
155
+ - Rakefile
156
+ - bin/console
157
+ - justicecz.gemspec
158
+ - lib/justicecz.rb
159
+ - lib/justicecz/connection.rb
160
+ - lib/justicecz/entities/company.rb
161
+ - lib/justicecz/entities/list.rb
162
+ - lib/justicecz/html/result_line.rb
163
+ - lib/justicecz/html/result_list.rb
164
+ - lib/justicecz/html_parser.rb
165
+ - lib/justicecz/misc/params_lookup.rb
166
+ - lib/justicecz/query.rb
167
+ - lib/justicecz/version.rb
168
+ - spec/connection_spec.rb
169
+ - spec/entities/company_spec.rb
170
+ - spec/entities/list_spec.rb
171
+ - spec/html/result_line_spec.rb
172
+ - spec/html/result_list_spec.rb
173
+ - spec/html_parser._spec.rb
174
+ - spec/misc/params_lookup_spec.rb
175
+ - spec/query_spec.rb
176
+ - spec/spec_helper.rb
177
+ homepage: ''
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.8
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: SDK for quering or.justice.cz
201
+ test_files:
202
+ - spec/connection_spec.rb
203
+ - spec/entities/company_spec.rb
204
+ - spec/entities/list_spec.rb
205
+ - spec/html/result_line_spec.rb
206
+ - spec/html/result_list_spec.rb
207
+ - spec/html_parser._spec.rb
208
+ - spec/misc/params_lookup_spec.rb
209
+ - spec/query_spec.rb
210
+ - spec/spec_helper.rb