-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4216eda
commit 6c2e373
Showing
9 changed files
with
133 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
ruby_ares (0.1.0) | ||
ruby_ares (0.2.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'ostruct' | ||
|
||
module RubyAres | ||
class Base | ||
class << self | ||
def get(ico, object_class = OpenStruct) | ||
uri = URI("#{base_url}/#{ico}") | ||
|
||
response = Net::HTTP.get_response(uri) | ||
|
||
case response | ||
when Net::HTTPSuccess then | ||
JSON.parse(response.body, object_class: object_class) | ||
when Net::HTTPRedirection then | ||
location = response['location'] | ||
warn "redirected to #{location}" | ||
fetch(location, limit - 1) | ||
else | ||
raise RubyAres::Error.new( | ||
msg: "Request failed with #{response.code}", | ||
type: response.class.name, | ||
status: response.code, | ||
response: (JSON.parse(response.body) rescue response.body) | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module RubyAres | ||
class PublicRegister < Base | ||
COURT_CODES = { | ||
"MSPH" => "Městský soud v Praze", | ||
"KSPH" => "Krajský soud v Praze", | ||
"KSCB" => "Krajský soud v Českých Budějovicích", | ||
"KSTB" => "Krajský soud v Českých Budějovicích – pobočka v Táboře", | ||
"KSPL" => "Krajský soud v Plzni", | ||
"KSKV" => "Krajský soud v Plzni – pobočka v Karlových Varech", | ||
"KSUL" => "Krajský soud v Ústí nad Labem", | ||
"KSLB" => "Krajský soud v Ústí nad Labem – pobočka v Liberci", | ||
"KSHK" => "Krajský soud v Hradci Králové", | ||
"KSPA" => "Krajský soud v Hradci Králové – pobočka v Pardubicích", | ||
"KSBR" => "Krajský soud v Brně", | ||
"KSJI" => "Krajský soud v Brně – pobočka v Jihlavě", | ||
"KSZL" => "Krajský soud v Brně – pobočka ve Zlíně", | ||
"KSOS" => "Krajský soud v Ostravě", | ||
"KSOL" => "Krajský soud v Ostravě – pobočka v Olomouci", | ||
"VSPH" => "Vrchní soud v Praze", | ||
"VSOL" => "Vrchní soud v Olomouci", | ||
"NSCR" => "Nejvyšší soud České republiky", | ||
"MSp" => "Společný soud" | ||
}.freeze | ||
|
||
class << self | ||
def base_url | ||
'https://ares.gov.cz/ekonomicke-subjekty-v-be/rest/ekonomicke-subjekty-vr'.freeze | ||
end | ||
|
||
def file_mark(json) | ||
record = json.zaznamy.select { |pr| pr.primarniZaznam == true }.first.spisovaZnacka.select { |sz| !sz.datumVymazu }.first | ||
court_code = record.soud | ||
court_name = COURT_CODES[court_code] || court_code | ||
|
||
{ | ||
court_name: court_name, | ||
first_number: record.oddil, | ||
second_number: record.vlozka | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyAres | ||
VERSION = "0.1.0" | ||
VERSION = "0.2.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RubyAres::PublicRegister do | ||
let(:ico) { '26168685' } | ||
|
||
subject { RubyAres::PublicRegister.get(ico) } | ||
|
||
before do | ||
stub_request(:get, "#{RubyAres::PublicRegister.base_url}/#{ico}") | ||
.to_return( | ||
body: | ||
{ | ||
"icoId":"26168685", | ||
"zaznamy":[ | ||
{"rejstrik":"OR","primarniZaznam":true,"spisovaZnacka":[{"datumZapisu":"2000-04-05","soud":"MSPH","oddil":"B","vlozka":6493}]} | ||
] | ||
}.to_json | ||
) | ||
end | ||
|
||
describe 'get' do | ||
it 'returns result as OpenStruct' do | ||
expect(subject).to be_a(OpenStruct) | ||
expect(subject.icoId).to eq(ico) | ||
end | ||
|
||
context 'Hash structure' do | ||
subject { RubyAres::PublicRegister.get(ico, Hash) } | ||
|
||
it 'returns result as Hash' do | ||
expect(subject).to be_a(Hash) | ||
end | ||
end | ||
end | ||
|
||
describe 'file_mark' do | ||
it 'returns result as Hash' do | ||
expect(RubyAres::PublicRegister.file_mark(subject)).to eq({ | ||
court_name: RubyAres::PublicRegister::COURT_CODES['MSPH'], | ||
first_number: 'B', | ||
second_number: 6493 | ||
}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters