Class: Epics::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/epics/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  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 = options[:locale] || Epics::DEFAULT_LOCALE
  self.product_name = options[:product_name] || Epics::DEFAULT_PRODUCT_NAME
  self.debug_mode = !!options[:debug_mode]
  self.x_509_certificates_content = {
    a: options[:x_509_certificate_a_content],
    x: options[:x_509_certificate_x_content],
    e: options[:x_509_certificate_e_content]
  }
end

Instance Attribute Details

#bicObject



64
65
66
# File 'lib/epics/client.rb', line 64

def bic
  @bic ||= (self.HTD; @bic)
end

#debug_modeObject

Returns the value of attribute debug_mode.



4
5
6
# File 'lib/epics/client.rb', line 4

def debug_mode
  @debug_mode
end

#host_idObject

Returns the value of attribute host_id.



4
5
6
# File 'lib/epics/client.rb', line 4

def host_id
  @host_id
end

#ibanObject



60
61
62
# File 'lib/epics/client.rb', line 60

def iban
  @iban ||= (self.HTD; @iban)
end

#keysObject

Returns the value of attribute keys.



4
5
6
# File 'lib/epics/client.rb', line 4

def keys
  @keys
end

#keys_contentObject

Returns the value of attribute keys_content.



4
5
6
# File 'lib/epics/client.rb', line 4

def keys_content
  @keys_content
end

#localeObject

Returns the value of attribute locale.



4
5
6
# File 'lib/epics/client.rb', line 4

def locale
  @locale
end

#nameObject



56
57
58
# File 'lib/epics/client.rb', line 56

def name
  @name ||= (self.HTD; @name)
end

#partner_idObject

Returns the value of attribute partner_id.



4
5
6
# File 'lib/epics/client.rb', line 4

def partner_id
  @partner_id
end

#passphraseObject

Returns the value of attribute passphrase.



4
5
6
# File 'lib/epics/client.rb', line 4

def passphrase
  @passphrase
end

#product_nameObject

Returns the value of attribute product_name.



4
5
6
# File 'lib/epics/client.rb', line 4

def product_name
  @product_name
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/epics/client.rb', line 4

def url
  @url
end

#user_idObject

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_contentObject

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, options = {})
  client = new(nil, passphrase, url, host_id, user_id, partner_id, options)
  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

#aObject



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_eObject



48
49
50
# File 'lib/epics/client.rb', line 48

def bank_e
  keys["#{host_id.upcase}.E002"]
end

#bank_xObject



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

#eObject



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

#HAAObject



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_requestObject



94
95
96
# File 'lib/epics/client.rb', line 94

def header_request
  @header_request ||= Epics::HeaderRequest.new(self)
end

#HEVObject



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

#HIAObject



110
111
112
# File 'lib/epics/client.rb', line 110

def HIA
  post(url, Epics::HIA.new(self).to_xml).body.ok?
end

#HKDObject



273
274
275
# File 'lib/epics/client.rb', line 273

def HKD
  download(Epics::HKD)
end

#HPBObject



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

#HPDObject



269
270
271
# File 'lib/epics/client.rb', line 269

def HPD
  download(Epics::HPD)
end

#HTDObject



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

#INIObject



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

#inspectObject



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_rendererObject



81
82
83
# File 'lib/epics/client.rb', line 81

def letter_renderer
  @letter_renderer ||= Epics::LetterRenderer.new(self)
end

#order_typesObject



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

#WSSObject



285
286
287
# File 'lib/epics/client.rb', line 285

def WSS
  download(Epics::WSS)
end

#xObject



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

#Z53(from, to) ⇒ Object



248
249
250
# File 'lib/epics/client.rb', line 248

def Z53(from, to)
  download_and_unzip(Epics::Z53, from: from, to: to)
end

#Z54(from, to) ⇒ Object



252
253
254
# File 'lib/epics/client.rb', line 252

def Z54(from, to)
  download_and_unzip(Epics::Z54, from: from, to: to)
end