lib/epics/client.rb in epics-2.4.0 vs lib/epics/client.rb in epics-2.5.0
- old
+ new
@@ -1,10 +1,11 @@
class Epics::Client
extend Forwardable
attr_accessor :passphrase, :url, :host_id, :user_id, :partner_id, :keys, :keys_content
attr_writer :iban, :bic, :name
+ attr_accessor :locale
def_delegators :connection, :post
def initialize(keys_content, passphrase, url, host_id, user_id, partner_id)
self.keys_content = keys_content.respond_to?(:read) ? keys_content.read : keys_content if keys_content
@@ -12,10 +13,11 @@
self.keys = extract_keys if keys_content
self.url = url
self.host_id = host_id
self.user_id = user_id
self.partner_id = partner_id
+ self.locale = :de
end
def inspect
"#<#{self.class}:#{self.object_id}
@keys=#{self.keys.keys},
@@ -66,30 +68,37 @@
end
client
end
+ def letter_renderer
+ @letter_renderer ||= Epics::LetterRenderer.new(self)
+ end
+
def ini_letter(bankname)
- raw = File.read(File.join(File.dirname(__FILE__), '../letter/', 'ini.erb'))
- ERB.new(raw).result(binding)
+ letter_renderer.render(bankname)
end
def save_ini_letter(bankname, path)
File.write(path, ini_letter(bankname))
path
end
+ def header_request
+ @header_request ||= Epics::HeaderRequest.new(self)
+ end
+
def credit(document)
self.CCT(document)
end
def debit(document, type = :CDD)
self.public_send(type, document)
end
def statements(from, to, type = :STA)
- self.public_send(type, from, to)
+ self.public_send(type, from: from, to: to)
end
def HIA
post(url, Epics::HIA.new(self).to_xml).body.ok?
end
@@ -164,47 +173,51 @@
def XCT(document)
upload(Epics::XCT, document)
end
def STA(from = nil, to = nil)
- download(Epics::STA, from, to)
+ download(Epics::STA, from: from, to: to)
end
def VMK(from = nil, to = nil)
- download(Epics::VMK, from, to)
+ download(Epics::VMK, from: from, to: to)
end
def CDZ(from = nil, to = nil)
- download_and_unzip(Epics::CDZ, from, to)
+ download_and_unzip(Epics::CDZ, from: from, to: to)
end
def CRZ(from = nil, to = nil)
- download_and_unzip(Epics::CRZ, from, to)
+ download_and_unzip(Epics::CRZ, from: from, to: to)
end
def C52(from, to)
- download_and_unzip(Epics::C52, from, to)
+ download_and_unzip(Epics::C52, from: from, to: to)
end
def C53(from, to)
- download_and_unzip(Epics::C53, from, to)
+ download_and_unzip(Epics::C53, from: from, to: to)
end
def C54(from, to)
- download_and_unzip(Epics::C54, from, to)
+ download_and_unzip(Epics::C54, from: from, to: to)
end
+ def C5N(from, to)
+ download_and_unzip(Epics::C5N, from: from, to: to)
+ end
+
def Z52(from, to)
- download_and_unzip(Epics::Z52, from, to)
+ download_and_unzip(Epics::Z52, from: from, to: to)
end
def Z53(from, to)
- download_and_unzip(Epics::Z53, from, to)
+ download_and_unzip(Epics::Z53, from: from, to: to)
end
def Z54(from, to)
- download_and_unzip(Epics::Z54, from, to)
+ download_and_unzip(Epics::Z54, from: from, to: to)
end
def HAA
Nokogiri::XML(download(Epics::HAA)).at_xpath("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").content.split(/\s/)
end
@@ -225,17 +238,21 @@
def HKD
download(Epics::HKD)
end
def PTK(from, to)
- download(Epics::PTK, from, to)
+ download(Epics::PTK, from: from, to: to)
end
def HAC(from = nil, to = nil)
- download(Epics::HAC, from, to)
+ download(Epics::HAC, from: from, to: to)
end
+ def WSS
+ download(Epics::WSS)
+ end
+
def save_keys(path)
File.write(path, dump_keys)
end
private
@@ -250,24 +267,24 @@
res = post(url, order.to_transfer_xml).body
return res.transaction_id, [res.order_id, order_id].detect { |id| id.to_s.chars.any? }
end
- def download(order_type, *args)
- document = order_type.new(self, *args)
+ def download(order_type, *args, **options)
+ document = order_type.new(self, *args, **options)
res = post(url, document.to_xml).body
document.transaction_id = res.transaction_id
if res.segmented? && res.last_segment?
post(url, document.to_receipt_xml).body
end
res.order_data
end
- def download_and_unzip(order_type, *args)
+ def download_and_unzip(order_type, *args, **options)
[].tap do |entries|
- Zip::File.open_buffer(StringIO.new(download(order_type, *args))).each do |zipfile|
+ Zip::File.open_buffer(StringIO.new(download(order_type, *args, **options))).each do |zipfile|
entries << zipfile.get_input_stream.read
end
end
end