Skip to content

Instantly share code, notes, and snippets.

@kubicek
Created June 28, 2016 00:36
Show Gist options
  • Save kubicek/5459530c3ff218e0ec1fb8bafdcbdffc to your computer and use it in GitHub Desktop.
Save kubicek/5459530c3ff218e0ec1fb8bafdcbdffc to your computer and use it in GitHub Desktop.
Klient pro získání LV z katastru
$:.unshift File.dirname(__FILE__)
require 'savon'
require 'base64'
module Savon
class Response
def xml
@http.body.split("\r\n\r\n")[1].split("--uuid:")[0]
end
end
end
client = Savon.client(
encoding: "UTF-8",
:wsdl => "https://katastr.cuzk.cz/trial/dokumentace/ws23/wsdp/sestavy_v23.wsdl",
wsse_auth: ["WSTESTB", "WSHESLOB"],
namespaces: { "xmlns:stype"=>"http://katastr.cuzk.cz/sestavy/types/v2.3" },
:open_timeout => 60,
:read_timeout => 60,
:log => false
)
def fetch(client, id)
puts "fetch"
response = client.call(:vrat_sestavu, message: {idSestavy: id })
fmt = response.body[:generuj_sestavu_response][:report_list][:report][:format]
body = Base64.decode64(response.body[:generuj_sestavu_response][:report_list][:report][:soubor_sestavy])
File.open("#{id}.#{fmt}","w"){|f| f<< body}
body
end
puts "generuj_evidenci_prav_pro_osobu"
response = client.call(:generuj_evidenci_prav_pro_osobu, message: {typ: "OFO", nazev: "Giňa Karel", "rcIco": "7407274919", format: "xml", cisloJednaci: "UFFF", ucelKod: "1" })
id = response.body[:generuj_sestavu_response][:report_list][:report][:id]
sleep(3)
lvs = fetch(client, id).scan(/<TEL_ID>(.+?)<\/TEL_ID>/)
lvs.each{|lv|
puts "generuj_lv"
response = client.call(:generuj_lv, message: {lvId: lv, format: 'xml', cisloJednaci: "UFFF", ucelKod: "1" })
response = client.call(:generuj_lv, message: {lvId: lv, format: 'pdf', cisloJednaci: "UFFF", ucelKod: "1" })
}
sleep(3)
response = client.call(:seznam_sestav)
response.body[:generuj_sestavu_response][:report_list][:report].each{|report|
fetch(client, report[:id])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment