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
- #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(document) ⇒ Object
- #credit(document) ⇒ 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
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
122 123 124 |
# File 'lib/epics/client.rb', line 122 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 |
#C52(from, to) ⇒ Object
162 163 164 |
# File 'lib/epics/client.rb', line 162 def C52(from, to) download_and_unzip(Epics::C52, from, to) end |
#C53(from, to) ⇒ Object
166 167 168 |
# File 'lib/epics/client.rb', line 166 def C53(from, to) download_and_unzip(Epics::C53, from, to) end |
#C54(from, to) ⇒ Object
170 171 172 |
# File 'lib/epics/client.rb', line 170 def C54(from, to) download_and_unzip(Epics::C54, from, to) end |
#CCS(document) ⇒ Object
150 151 152 |
# File 'lib/epics/client.rb', line 150 def CCS(document) upload(Epics::CCS, document) end |
#CCT(document) ⇒ Object
146 147 148 |
# File 'lib/epics/client.rb', line 146 def CCT(document) upload(Epics::CCT, document) end |
#CD1(document) ⇒ Object
126 127 128 |
# File 'lib/epics/client.rb', line 126 def CD1(document) upload(Epics::CD1, document) end |
#CDB(document) ⇒ Object
130 131 132 |
# File 'lib/epics/client.rb', line 130 def CDB(document) upload(Epics::CDB, document) end |
#CDD(document) ⇒ Object
134 135 136 |
# File 'lib/epics/client.rb', line 134 def CDD(document) upload(Epics::CDD, document) end |
#CDS(document) ⇒ Object
138 139 140 |
# File 'lib/epics/client.rb', line 138 def CDS(document) upload(Epics::CDS, document) end |
#CDZ(document) ⇒ Object
142 143 144 |
# File 'lib/epics/client.rb', line 142 def CDZ(document) upload(Epics::CDZ, document) end |
#credit(document) ⇒ Object
81 82 83 |
# File 'lib/epics/client.rb', line 81 def credit(document) self.CCT(document) 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
174 175 176 |
# File 'lib/epics/client.rb', line 174 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
199 200 201 |
# File 'lib/epics/client.rb', line 199 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 119 120 |
# 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) bank = OpenSSL::PKey::RSA.new if bank.respond_to?(:set_key) bank.set_key(OpenSSL::BN.new(modulus, 2), OpenSSL::BN.new(exponent, 2), nil) else bank.n = OpenSSL::BN.new(modulus, 2) bank.e = OpenSSL::BN.new(exponent, 2) end self.keys["#{host_id.upcase}.#{type}"] = Epics::Key.new(bank) end [bank_x, bank_e] end |
#HTD ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/epics/client.rb', line 178 def HTD Nokogiri::XML(download(Epics::HTD)).tap do |htd| @iban ||= htd.at_xpath("//xmlns:AccountNumber[@international='true']", xmlns: "urn:org:ebics:H004").text @bic ||= htd.at_xpath("//xmlns:BankCode[@international='true']", xmlns: "urn:org:ebics:H004").text @name ||= htd.at_xpath("//xmlns:Name", xmlns: "urn:org:ebics:H004").text @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
195 196 197 |
# File 'lib/epics/client.rb', line 195 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
203 204 205 |
# File 'lib/epics/client.rb', line 203 def save_keys(path) File.write(path, dump_keys) end |
#STA(from = nil, to = nil) ⇒ Object
154 155 156 |
# File 'lib/epics/client.rb', line 154 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
158 159 160 |
# File 'lib/epics/client.rb', line 158 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 |