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) ⇒ 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

#bicObject


54
55
56
# File 'lib/epics/client.rb', line 54

def bic
  @bic ||= (self.HTD; @bic)
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


50
51
52
# File 'lib/epics/client.rb', line 50

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

#nameObject


46
47
48
# File 'lib/epics/client.rb', line 46

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

#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

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

#aObject


30
31
32
# File 'lib/epics/client.rb', line 30

def a
  keys["A006"]
end

#bank_eObject


38
39
40
# File 'lib/epics/client.rb', line 38

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

#bank_xObject


42
43
44
# File 'lib/epics/client.rb', line 42

def bank_x
  keys["#{host_id.upcase}.X002"]
end

#C52(from, to) ⇒ Object


130
131
132
# File 'lib/epics/client.rb', line 130

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

#C53(from, to) ⇒ Object


134
135
136
# File 'lib/epics/client.rb', line 134

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

#CCT(document) ⇒ Object


122
123
124
# File 'lib/epics/client.rb', line 122

def CCT(document)
  upload(Epics::CCT, document)
end

#CD1(document) ⇒ Object


114
115
116
# File 'lib/epics/client.rb', line 114

def CD1(document)
  upload(Epics::CD1, document)
end

#CDD(document) ⇒ Object


118
119
120
# File 'lib/epics/client.rb', line 118

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

#eObject


26
27
28
# File 'lib/epics/client.rb', line 26

def e
  keys["E002"]
end

#HAAObject


138
139
140
# File 'lib/epics/client.rb', line 138

def HAA
  Nokogiri::XML(download(Epics::HAA)).at_xpath("//xmlns:OrderTypes", xmlns: "urn:org:ebics:H004").content.split(/\s/)
end

#HAC(from, to) ⇒ Object


162
163
164
# File 'lib/epics/client.rb', line 162

def HAC(from, to)
  download(Epics::HAC, from, to)
end

#HIAObject


89
90
91
# File 'lib/epics/client.rb', line 89

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

#HKDObject


154
155
156
# File 'lib/epics/client.rb', line 154

def HKD
  download(Epics::HKD)
end

#HPBObject


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# 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
    bank.n = OpenSSL::BN.new(modulus, 2)
    bank.e = OpenSSL::BN.new(exponent, 2)

    self.keys["#{host_id.upcase}.#{type}"] = Epics::Key.new(bank)
  end

  [bank_x, bank_e]
end

#HPDObject


150
151
152
# File 'lib/epics/client.rb', line 150

def HPD
  download(Epics::HPD)
end

#HTDObject


142
143
144
145
146
147
148
# File 'lib/epics/client.rb', line 142

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

#INIObject


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

#inspectObject


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


158
159
160
# File 'lib/epics/client.rb', line 158

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


166
167
168
# File 'lib/epics/client.rb', line 166

def save_keys(path)
  File.write(path, dump_keys)
end

#STA(from, to) ⇒ Object


126
127
128
# File 'lib/epics/client.rb', line 126

def STA(from, to)
  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

#xObject


34
35
36
# File 'lib/epics/client.rb', line 34

def x
  keys["X002"]
end