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
- #bank_e ⇒ Object
- #bank_x ⇒ Object
- #C52(from, to) ⇒ Object
- #C53(from, to) ⇒ Object
- #C54(from, to) ⇒ Object
- #CCT(document) ⇒ Object
- #CD1(document) ⇒ Object
- #CDD(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
- #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
58 59 60 61 62 63 64 65 |
# File 'lib/epics/client.rb', line 58 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 |
#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
138 139 140 |
# File 'lib/epics/client.rb', line 138 def C52(from, to) download_and_unzip(Epics::C52, from, to) end |
#C53(from, to) ⇒ Object
142 143 144 |
# File 'lib/epics/client.rb', line 142 def C53(from, to) download_and_unzip(Epics::C53, from, to) end |
#C54(from, to) ⇒ Object
146 147 148 |
# File 'lib/epics/client.rb', line 146 def C54(from, to) download_and_unzip(Epics::C54, from, to) end |
#CCT(document) ⇒ Object
126 127 128 |
# File 'lib/epics/client.rb', line 126 def CCT(document) upload(Epics::CCT, document) end |
#CD1(document) ⇒ Object
118 119 120 |
# File 'lib/epics/client.rb', line 118 def CD1(document) upload(Epics::CD1, document) end |
#CDD(document) ⇒ Object
122 123 124 |
# File 'lib/epics/client.rb', line 122 def CDD(document) upload(Epics::CDD, document) end |
#credit(document) ⇒ Object
77 78 79 |
# File 'lib/epics/client.rb', line 77 def credit(document) self.CCT(document) end |
#debit(document, type = :CDD) ⇒ Object
81 82 83 |
# File 'lib/epics/client.rb', line 81 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
150 151 152 |
# File 'lib/epics/client.rb', line 150 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
174 175 176 |
# File 'lib/epics/client.rb', line 174 def HAC(from = nil, to = nil) download(Epics::HAC, from, to) end |
#HIA ⇒ Object
89 90 91 |
# File 'lib/epics/client.rb', line 89 def HIA post(url, Epics::HIA.new(self).to_xml).body.ok? end |
#HPB ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/epics/client.rb', line 97 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
154 155 156 157 158 159 160 |
# File 'lib/epics/client.rb', line 154 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 end.to_xml end |
#INI ⇒ Object
93 94 95 |
# File 'lib/epics/client.rb', line 93 def INI post(url, Epics::INI.new(self).to_xml).body.ok? end |
#ini_letter(bankname) ⇒ Object
67 68 69 70 |
# File 'lib/epics/client.rb', line 67 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 |
#PTK(from, to) ⇒ Object
170 171 172 |
# File 'lib/epics/client.rb', line 170 def PTK(from, to) download(Epics::PTK, from, to) end |
#save_ini_letter(bankname, path) ⇒ Object
72 73 74 75 |
# File 'lib/epics/client.rb', line 72 def save_ini_letter(bankname, path) File.write(path, ini_letter(bankname)) path end |
#save_keys(path) ⇒ Object
178 179 180 |
# File 'lib/epics/client.rb', line 178 def save_keys(path) File.write(path, dump_keys) end |
#STA(from = nil, to = nil) ⇒ Object
130 131 132 |
# File 'lib/epics/client.rb', line 130 def STA(from = nil, to = nil) download(Epics::STA, from, to) end |
#statements(from, to, type = :STA) ⇒ Object
85 86 87 |
# File 'lib/epics/client.rb', line 85 def statements(from, to, type = :STA) self.public_send(type, from, to) end |
#VMK(from = nil, to = nil) ⇒ Object
134 135 136 |
# File 'lib/epics/client.rb', line 134 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 |