Class: Epics::Client
- Inherits:
-
Object
- Object
- Epics::Client
- Extended by:
- Forwardable
- Defined in:
- lib/epics/client.rb
Instance Attribute Summary collapse
- #bic ⇒ Object
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#host_id ⇒ Object
Returns the value of attribute host_id.
- #iban ⇒ Object
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#keys_content ⇒ Object
Returns the value of attribute keys_content.
-
#locale ⇒ Object
Returns the value of attribute locale.
- #name ⇒ Object
-
#partner_id ⇒ Object
Returns the value of attribute partner_id.
-
#passphrase ⇒ Object
Returns the value of attribute passphrase.
-
#product_name ⇒ Object
Returns the value of attribute product_name.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#x_509_certificates_content ⇒ Object
Returns the value of attribute x_509_certificates_content.
Class Method Summary collapse
Instance Method Summary collapse
- #a ⇒ Object
- #AZV(document) ⇒ Object
- #bank_e ⇒ Object
- #bank_x ⇒ Object
- #BKA(from, to) ⇒ Object
- #C2S(document) ⇒ Object
- #C52(from, to) ⇒ Object
- #C53(from, to) ⇒ Object
- #C54(from, to) ⇒ Object
- #C5N(from, to) ⇒ Object
- #CCS(document) ⇒ Object
- #CCT(document) ⇒ Object
- #CD1(document) ⇒ Object
- #CDB(document) ⇒ Object
- #CDD(document) ⇒ Object
- #CDS(document) ⇒ Object
- #CDZ(from = nil, to = nil) ⇒ Object
- #CIP(document) ⇒ Object
- #credit(document) ⇒ Object
- #CRZ(from = nil, to = nil) ⇒ Object
- #debit(document, type = :CDD) ⇒ Object
- #e ⇒ Object
- #FDL(format, from = nil, to = nil) ⇒ Object
- #FUL(document) ⇒ Object
- #HAA ⇒ Object
- #HAC(from = nil, to = nil) ⇒ Object
- #header_request ⇒ Object
- #HEV ⇒ Object
- #HIA ⇒ Object
- #HKD ⇒ Object
- #HPB ⇒ Object
- #HPD ⇒ Object
- #HTD ⇒ Object
- #INI ⇒ Object
- #ini_letter(bankname) ⇒ Object
-
#initialize(keys_content, passphrase, url, host_id, user_id, partner_id, options = {}) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #letter_renderer ⇒ Object
- #order_types ⇒ Object
- #PTK(from, to) ⇒ Object
- #save_ini_letter(bankname, path) ⇒ Object
- #save_keys(path) ⇒ Object
- #STA(from = nil, to = nil) ⇒ Object
- #statements(from, to, type = :STA) ⇒ Object
- #VMK(from = nil, to = nil) ⇒ Object
- #WSS ⇒ Object
- #x ⇒ Object
- #x_509_certificate(type) ⇒ Object
- #x_509_certificate_hash(type) ⇒ Object
- #XCT(document) ⇒ Object
- #XDS(document) ⇒ Object
- #XE2(document) ⇒ Object
- #XE3(document) ⇒ Object
- #Z01(from, to) ⇒ Object
- #Z52(from, to) ⇒ Object
- #Z53(from, to) ⇒ Object
- #Z54(from, to) ⇒ Object
Constructor Details
#initialize(keys_content, passphrase, url, host_id, user_id, partner_id, options = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/epics/client.rb', line 11 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 self.passphrase = passphrase 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 = [:locale] || Epics::DEFAULT_LOCALE self.product_name = [:product_name] || Epics::DEFAULT_PRODUCT_NAME self.debug_mode = !![:debug_mode] self.x_509_certificates_content = { a: [:x_509_certificate_a_content], x: [:x_509_certificate_x_content], e: [:x_509_certificate_e_content] } end |
Instance Attribute Details
#bic ⇒ Object
64 65 66 |
# File 'lib/epics/client.rb', line 64 def bic @bic ||= (self.HTD; @bic) end |
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def debug_mode @debug_mode end |
#host_id ⇒ Object
Returns the value of attribute host_id.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def host_id @host_id end |
#iban ⇒ Object
60 61 62 |
# File 'lib/epics/client.rb', line 60 def iban @iban ||= (self.HTD; @iban) end |
#keys ⇒ Object
Returns the value of attribute keys.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def keys @keys end |
#keys_content ⇒ Object
Returns the value of attribute keys_content.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def keys_content @keys_content end |
#locale ⇒ Object
Returns the value of attribute locale.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def locale @locale end |
#name ⇒ Object
56 57 58 |
# File 'lib/epics/client.rb', line 56 def name @name ||= (self.HTD; @name) end |
#partner_id ⇒ Object
Returns the value of attribute partner_id.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def partner_id @partner_id end |
#passphrase ⇒ Object
Returns the value of attribute passphrase.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def passphrase @passphrase end |
#product_name ⇒ Object
Returns the value of attribute product_name.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def product_name @product_name end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def url @url end |
#user_id ⇒ Object
Returns the value of attribute user_id.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def user_id @user_id end |
#x_509_certificates_content ⇒ Object
Returns the value of attribute x_509_certificates_content.
4 5 6 |
# File 'lib/epics/client.rb', line 4 def x_509_certificates_content @x_509_certificates_content end |
Class Method Details
.setup(passphrase, url, host_id, user_id, partner_id, keysize = 2048, options = {}) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/epics/client.rb', line 72 def self.setup(passphrase, url, host_id, user_id, partner_id, keysize = 2048, = {}) client = new(nil, passphrase, url, host_id, user_id, partner_id, ) client.keys = %w(A006 X002 E002).each_with_object({}) do |type, memo| memo[type] = Epics::Key.new( OpenSSL::PKey::RSA.generate(keysize) ) end client end |
Instance Method Details
#a ⇒ Object
40 41 42 |
# File 'lib/epics/client.rb', line 40 def a keys["A006"] end |
#AZV(document) ⇒ Object
144 145 146 |
# File 'lib/epics/client.rb', line 144 def AZV(document) upload(Epics::AZV, document) end |
#bank_e ⇒ Object
48 49 50 |
# File 'lib/epics/client.rb', line 48 def bank_e keys["#{host_id.upcase}.E002"] end |
#bank_x ⇒ Object
52 53 54 |
# File 'lib/epics/client.rb', line 52 def bank_x keys["#{host_id.upcase}.X002"] end |
#BKA(from, to) ⇒ Object
220 221 222 |
# File 'lib/epics/client.rb', line 220 def BKA(from, to) download_and_unzip(Epics::BKA, from: from, to: to) end |
#C2S(document) ⇒ Object
156 157 158 |
# File 'lib/epics/client.rb', line 156 def C2S(document) upload(Epics::C2S, document) end |
#C52(from, to) ⇒ Object
224 225 226 |
# File 'lib/epics/client.rb', line 224 def C52(from, to) download_and_unzip(Epics::C52, from: from, to: to) end |
#C53(from, to) ⇒ Object
228 229 230 |
# File 'lib/epics/client.rb', line 228 def C53(from, to) download_and_unzip(Epics::C53, from: from, to: to) end |
#C54(from, to) ⇒ Object
232 233 234 |
# File 'lib/epics/client.rb', line 232 def C54(from, to) download_and_unzip(Epics::C54, from: from, to: to) end |
#C5N(from, to) ⇒ Object
236 237 238 |
# File 'lib/epics/client.rb', line 236 def C5N(from, to) download_and_unzip(Epics::C5N, from: from, to: to) end |
#CCS(document) ⇒ Object
188 189 190 |
# File 'lib/epics/client.rb', line 188 def CCS(document) upload(Epics::CCS, document) end |
#CCT(document) ⇒ Object
180 181 182 |
# File 'lib/epics/client.rb', line 180 def CCT(document) upload(Epics::CCT, document) end |
#CD1(document) ⇒ Object
148 149 150 |
# File 'lib/epics/client.rb', line 148 def CD1(document) upload(Epics::CD1, document) end |
#CDB(document) ⇒ Object
152 153 154 |
# File 'lib/epics/client.rb', line 152 def CDB(document) upload(Epics::CDB, document) end |
#CDD(document) ⇒ Object
160 161 162 |
# File 'lib/epics/client.rb', line 160 def CDD(document) upload(Epics::CDD, document) end |
#CDS(document) ⇒ Object
172 173 174 |
# File 'lib/epics/client.rb', line 172 def CDS(document) upload(Epics::CDS, document) end |
#CDZ(from = nil, to = nil) ⇒ Object
212 213 214 |
# File 'lib/epics/client.rb', line 212 def CDZ(from = nil, to = nil) download_and_unzip(Epics::CDZ, from: from, to: to) end |
#CIP(document) ⇒ Object
184 185 186 |
# File 'lib/epics/client.rb', line 184 def CIP(document) upload(Epics::CIP, document) end |
#credit(document) ⇒ Object
98 99 100 |
# File 'lib/epics/client.rb', line 98 def credit(document) self.CCT(document) end |
#CRZ(from = nil, to = nil) ⇒ Object
216 217 218 |
# File 'lib/epics/client.rb', line 216 def CRZ(from = nil, to = nil) download_and_unzip(Epics::CRZ, from: from, to: to) end |
#debit(document, type = :CDD) ⇒ Object
102 103 104 |
# File 'lib/epics/client.rb', line 102 def debit(document, type = :CDD) self.public_send(type, document) end |
#e ⇒ Object
36 37 38 |
# File 'lib/epics/client.rb', line 36 def e keys["E002"] end |
#FDL(format, from = nil, to = nil) ⇒ Object
204 205 206 |
# File 'lib/epics/client.rb', line 204 def FDL(format, from = nil, to = nil) download(Epics::FDL, file_format: format, from: from, to: to ) end |
#FUL(document) ⇒ Object
196 197 198 |
# File 'lib/epics/client.rb', line 196 def FUL(document) upload(Epics::FUL, document) end |
#HAA ⇒ Object
256 257 258 |
# File 'lib/epics/client.rb', line 256 def HAA Nokogiri::XML(download(Epics::HAA)).at_xpath("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").content.split(/\s/) end |
#HAC(from = nil, to = nil) ⇒ Object
281 282 283 |
# File 'lib/epics/client.rb', line 281 def HAC(from = nil, to = nil) download(Epics::HAC, from: from, to: to) end |
#header_request ⇒ Object
94 95 96 |
# File 'lib/epics/client.rb', line 94 def header_request @header_request ||= Epics::HeaderRequest.new(self) end |
#HEV ⇒ Object
118 119 120 121 122 123 |
# File 'lib/epics/client.rb', line 118 def HEV res = post(url, Epics::HEV.new(self).to_xml).body res.doc.xpath("//xmlns:VersionNumber", xmlns: 'http://www.ebics.org/H000').each_with_object({}) do |node, versions| versions[node['ProtocolVersion']] = node.content end end |
#HIA ⇒ Object
110 111 112 |
# File 'lib/epics/client.rb', line 110 def HIA post(url, Epics::HIA.new(self).to_xml).body.ok? end |
#HPB ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/epics/client.rb', line 125 def HPB Nokogiri::XML(download(Epics::HPB)).xpath("//xmlns:PubKeyValue", xmlns: "urn:org:ebics:H004").each do |node| type = node.parent.last_element_child.content modulus = Base64.decode64(node.at_xpath(".//*[local-name() = 'Modulus']").content) exponent = Base64.decode64(node.at_xpath(".//*[local-name() = 'Exponent']").content) sequence = [] sequence << OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(modulus, 2)) sequence << OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(exponent, 2)) bank = OpenSSL::PKey::RSA.new(OpenSSL::ASN1::Sequence(sequence).to_der) self.keys["#{host_id.upcase}.#{type}"] = Epics::Key.new(bank) end [bank_x, bank_e] end |
#HTD ⇒ Object
260 261 262 263 264 265 266 267 |
# File 'lib/epics/client.rb', line 260 def HTD Nokogiri::XML(download(Epics::HTD)).tap do |htd| @iban ||= htd.at_xpath("//xmlns:AccountNumber[@international='true']", xmlns: "urn:org:ebics:H004").text rescue nil @bic ||= htd.at_xpath("//xmlns:BankCode[@international='true']", xmlns: "urn:org:ebics:H004").text rescue nil @name ||= htd.at_xpath("//xmlns:Name", xmlns: "urn:org:ebics:H004").text rescue nil @order_types ||= htd.search("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").map{|o| o.content.split(/\s/) }.delete_if{|o| o == ""}.flatten end.to_xml end |
#INI ⇒ Object
114 115 116 |
# File 'lib/epics/client.rb', line 114 def INI post(url, Epics::INI.new(self).to_xml).body.ok? end |
#ini_letter(bankname) ⇒ Object
85 86 87 |
# File 'lib/epics/client.rb', line 85 def ini_letter(bankname) letter_renderer.render(bankname) end |
#inspect ⇒ Object
29 30 31 32 33 34 |
# File 'lib/epics/client.rb', line 29 def inspect "#<#{self.class}:#{self.object_id} @keys=#{self.keys.keys}, @user_id=\"#{self.user_id}\", @partner_id=\"#{self.partner_id}\"" end |
#letter_renderer ⇒ Object
81 82 83 |
# File 'lib/epics/client.rb', line 81 def letter_renderer @letter_renderer ||= Epics::LetterRenderer.new(self) end |
#order_types ⇒ Object
68 69 70 |
# File 'lib/epics/client.rb', line 68 def order_types @order_types ||= (self.HTD; @order_types) end |
#PTK(from, to) ⇒ Object
277 278 279 |
# File 'lib/epics/client.rb', line 277 def PTK(from, to) download(Epics::PTK, from: from, to: to) end |
#save_ini_letter(bankname, path) ⇒ Object
89 90 91 92 |
# File 'lib/epics/client.rb', line 89 def save_ini_letter(bankname, path) File.write(path, ini_letter(bankname)) path end |
#save_keys(path) ⇒ Object
289 290 291 |
# File 'lib/epics/client.rb', line 289 def save_keys(path) File.write(path, dump_keys) end |
#STA(from = nil, to = nil) ⇒ Object
200 201 202 |
# File 'lib/epics/client.rb', line 200 def STA(from = nil, to = nil) download(Epics::STA, from: from, to: to) end |
#statements(from, to, type = :STA) ⇒ Object
106 107 108 |
# File 'lib/epics/client.rb', line 106 def statements(from, to, type = :STA) self.public_send(type, from: from, to: to) end |
#VMK(from = nil, to = nil) ⇒ Object
208 209 210 |
# File 'lib/epics/client.rb', line 208 def VMK(from = nil, to = nil) download(Epics::VMK, from: from, to: to) end |
#x ⇒ Object
44 45 46 |
# File 'lib/epics/client.rb', line 44 def x keys["X002"] end |
#x_509_certificate(type) ⇒ Object
293 294 295 296 297 |
# File 'lib/epics/client.rb', line 293 def x_509_certificate(type) content = x_509_certificates_content[type.to_sym] return if content.nil? || content.empty? Epics::X509Certificate.new(content) end |
#x_509_certificate_hash(type) ⇒ Object
299 300 301 302 303 304 |
# File 'lib/epics/client.rb', line 299 def x_509_certificate_hash(type) content = x_509_certificates_content[type.to_sym] return if content.nil? || content.empty? cert = OpenSSL::X509::Certificate.new(content) Digest::SHA256.hexdigest(cert.to_der).upcase end |
#XCT(document) ⇒ Object
192 193 194 |
# File 'lib/epics/client.rb', line 192 def XCT(document) upload(Epics::XCT, document) end |
#XDS(document) ⇒ Object
176 177 178 |
# File 'lib/epics/client.rb', line 176 def XDS(document) upload(Epics::XDS, document) end |
#XE2(document) ⇒ Object
164 165 166 |
# File 'lib/epics/client.rb', line 164 def XE2(document) upload(Epics::XE2, document) end |
#XE3(document) ⇒ Object
168 169 170 |
# File 'lib/epics/client.rb', line 168 def XE3(document) upload(Epics::XE3, document) end |
#Z01(from, to) ⇒ Object
240 241 242 |
# File 'lib/epics/client.rb', line 240 def Z01(from, to) download_and_unzip(Epics::Z01, from: from, to: to) end |
#Z52(from, to) ⇒ Object
244 245 246 |
# File 'lib/epics/client.rb', line 244 def Z52(from, to) download_and_unzip(Epics::Z52, from: from, to: to) end |