Class: Epics::Client
- Inherits:
-
Object
- Object
- Epics::Client
- Extended by:
- Forwardable
- Defined in:
- lib/epics/client.rb
Instance Attribute Summary collapse
- #bic ⇒ Object
-
#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.
- #name ⇒ Object
-
#partner_id ⇒ Object
Returns the value of attribute partner_id.
-
#passphrase ⇒ Object
Returns the value of attribute passphrase.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #a ⇒ Object
- #AZV(document) ⇒ Object
- #bank_e ⇒ Object
- #bank_x ⇒ Object
- #C2S(document) ⇒ Object
- #C52(from, to) ⇒ Object
- #C53(from, to) ⇒ Object
- #C54(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
- #credit(document) ⇒ Object
- #CRZ(from = nil, to = nil) ⇒ Object
- #debit(document, type = :CDD) ⇒ Object
- #e ⇒ Object
- #HAA ⇒ Object
- #HAC(from = nil, to = nil) ⇒ 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) ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ 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
- #x ⇒ Object
- #XCT(document) ⇒ Object
- #XDS(document) ⇒ Object
- #XE2(document) ⇒ Object
- #XE3(document) ⇒ 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) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 |
# File 'lib/epics/client.rb', line 9 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 end |
Instance Attribute Details
#bic ⇒ Object
54 55 56 |
# File 'lib/epics/client.rb', line 54 def bic @bic ||= (self.HTD; @bic) 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
50 51 52 |
# File 'lib/epics/client.rb', line 50 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 |
#name ⇒ Object
46 47 48 |
# File 'lib/epics/client.rb', line 46 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 |
#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 |
Class Method Details
.setup(passphrase, url, host_id, user_id, partner_id, keysize = 2048) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/epics/client.rb', line 62 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
30 31 32 |
# File 'lib/epics/client.rb', line 30 def a keys["A006"] end |
#AZV(document) ⇒ Object
120 121 122 |
# File 'lib/epics/client.rb', line 120 def AZV(document) upload(Epics::AZV, document) end |
#bank_e ⇒ Object
38 39 40 |
# File 'lib/epics/client.rb', line 38 def bank_e keys["#{host_id.upcase}.E002"] end |
#bank_x ⇒ Object
42 43 44 |
# File 'lib/epics/client.rb', line 42 def bank_x keys["#{host_id.upcase}.X002"] end |
#C2S(document) ⇒ Object
132 133 134 |
# File 'lib/epics/client.rb', line 132 def C2S(document) upload(Epics::C2S, document) end |
#C52(from, to) ⇒ Object
184 185 186 |
# File 'lib/epics/client.rb', line 184 def C52(from, to) download_and_unzip(Epics::C52, from, to) end |
#C53(from, to) ⇒ Object
188 189 190 |
# File 'lib/epics/client.rb', line 188 def C53(from, to) download_and_unzip(Epics::C53, from, to) end |
#C54(from, to) ⇒ Object
192 193 194 |
# File 'lib/epics/client.rb', line 192 def C54(from, to) download_and_unzip(Epics::C54, from, to) end |
#CCS(document) ⇒ Object
160 161 162 |
# File 'lib/epics/client.rb', line 160 def CCS(document) upload(Epics::CCS, document) end |
#CCT(document) ⇒ Object
156 157 158 |
# File 'lib/epics/client.rb', line 156 def CCT(document) upload(Epics::CCT, document) end |
#CD1(document) ⇒ Object
124 125 126 |
# File 'lib/epics/client.rb', line 124 def CD1(document) upload(Epics::CD1, document) end |
#CDB(document) ⇒ Object
128 129 130 |
# File 'lib/epics/client.rb', line 128 def CDB(document) upload(Epics::CDB, document) end |
#CDD(document) ⇒ Object
136 137 138 |
# File 'lib/epics/client.rb', line 136 def CDD(document) upload(Epics::CDD, document) end |
#CDS(document) ⇒ Object
148 149 150 |
# File 'lib/epics/client.rb', line 148 def CDS(document) upload(Epics::CDS, document) end |
#CDZ(from = nil, to = nil) ⇒ Object
176 177 178 |
# File 'lib/epics/client.rb', line 176 def CDZ(from = nil, to = nil) download_and_unzip(Epics::CDZ, from, to) end |
#credit(document) ⇒ Object
81 82 83 |
# File 'lib/epics/client.rb', line 81 def credit(document) self.CCT(document) end |
#CRZ(from = nil, to = nil) ⇒ Object
180 181 182 |
# File 'lib/epics/client.rb', line 180 def CRZ(from = nil, to = nil) download_and_unzip(Epics::CRZ, from, to) end |
#debit(document, type = :CDD) ⇒ Object
85 86 87 |
# File 'lib/epics/client.rb', line 85 def debit(document, type = :CDD) self.public_send(type, document) end |
#e ⇒ Object
26 27 28 |
# File 'lib/epics/client.rb', line 26 def e keys["E002"] end |
#HAA ⇒ Object
208 209 210 |
# File 'lib/epics/client.rb', line 208 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
233 234 235 |
# File 'lib/epics/client.rb', line 233 def HAC(from = nil, to = nil) download(Epics::HAC, from, to) end |
#HIA ⇒ Object
93 94 95 |
# File 'lib/epics/client.rb', line 93 def HIA post(url, Epics::HIA.new(self).to_xml).body.ok? end |
#HPB ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/epics/client.rb', line 101 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
212 213 214 215 216 217 218 219 |
# File 'lib/epics/client.rb', line 212 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
97 98 99 |
# File 'lib/epics/client.rb', line 97 def INI post(url, Epics::INI.new(self).to_xml).body.ok? end |
#ini_letter(bankname) ⇒ Object
71 72 73 74 |
# File 'lib/epics/client.rb', line 71 def ini_letter(bankname) raw = File.read(File.join(File.dirname(__FILE__), '../letter/', 'ini.erb')) ERB.new(raw).result(binding) end |
#inspect ⇒ Object
19 20 21 22 23 24 |
# File 'lib/epics/client.rb', line 19 def inspect "#<#{self.class}:#{self.object_id} @keys=#{self.keys.keys}, @user_id=\"#{self.user_id}\", @partner_id=\"#{self.partner_id}\"" end |
#order_types ⇒ Object
58 59 60 |
# File 'lib/epics/client.rb', line 58 def order_types @order_types ||= (self.HTD; @order_types) end |
#PTK(from, to) ⇒ Object
229 230 231 |
# File 'lib/epics/client.rb', line 229 def PTK(from, to) download(Epics::PTK, from, to) end |
#save_ini_letter(bankname, path) ⇒ Object
76 77 78 79 |
# File 'lib/epics/client.rb', line 76 def save_ini_letter(bankname, path) File.write(path, ini_letter(bankname)) path end |
#save_keys(path) ⇒ Object
237 238 239 |
# File 'lib/epics/client.rb', line 237 def save_keys(path) File.write(path, dump_keys) end |
#STA(from = nil, to = nil) ⇒ Object
168 169 170 |
# File 'lib/epics/client.rb', line 168 def STA(from = nil, to = nil) download(Epics::STA, from, to) end |
#statements(from, to, type = :STA) ⇒ Object
89 90 91 |
# File 'lib/epics/client.rb', line 89 def statements(from, to, type = :STA) self.public_send(type, from, to) end |
#VMK(from = nil, to = nil) ⇒ Object
172 173 174 |
# File 'lib/epics/client.rb', line 172 def VMK(from = nil, to = nil) download(Epics::VMK, from, to) end |
#x ⇒ Object
34 35 36 |
# File 'lib/epics/client.rb', line 34 def x keys["X002"] end |
#XCT(document) ⇒ Object
164 165 166 |
# File 'lib/epics/client.rb', line 164 def XCT(document) upload(Epics::XCT, document) end |
#XDS(document) ⇒ Object
152 153 154 |
# File 'lib/epics/client.rb', line 152 def XDS(document) upload(Epics::XDS, document) end |
#XE2(document) ⇒ Object
140 141 142 |
# File 'lib/epics/client.rb', line 140 def XE2(document) upload(Epics::XE2, document) end |
#XE3(document) ⇒ Object
144 145 146 |
# File 'lib/epics/client.rb', line 144 def XE3(document) upload(Epics::XE3, document) end |
#Z52(from, to) ⇒ Object
196 197 198 |
# File 'lib/epics/client.rb', line 196 def Z52(from, to) download_and_unzip(Epics::Z52, from, to) end |