Class: Epics::GenericRequest

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

Direct Known Subclasses

BKA, C52, C53, C54, C5N, CDZ, CRZ, FDL, GenericUploadRequest, HAA, HAC, HEV, HIA, HKD, HPB, HPD, HTD, INI, PTK, STA, VMK, WSS, Z01, Z52, Z53, Z54

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, **options) ⇒ GenericRequest

Returns a new instance of GenericRequest.



6
7
8
9
# File 'lib/epics/generic_request.rb', line 6

def initialize(client, **options)
  @client = client
  @options = options
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



3
4
5
# File 'lib/epics/generic_request.rb', line 3

def client
  @client
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/epics/generic_request.rb', line 3

def options
  @options
end

#transaction_idObject

Returns the value of attribute transaction_id.



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

def transaction_id
  @transaction_id
end

Instance Method Details

#auth_signatureObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/epics/generic_request.rb', line 35

def auth_signature
  Nokogiri::XML::Builder.new do |xml|
    xml.AuthSignature{
      xml.send('ds:SignedInfo') {
        xml.send('ds:CanonicalizationMethod', '', Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")
        xml.send('ds:SignatureMethod', '', Algorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256")
        xml.send('ds:Reference', '', URI: "#xpointer(//*[@authenticate='true'])") {
          xml.send('ds:Transforms') {
            xml.send('ds:Transform', '', Algorithm: "http://www.w3.org/TR/2001/REC-xml-c14n-20010315")
          }
          xml.send('ds:DigestMethod', '', Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256")
          xml.send('ds:DigestValue', '')
        }
      }
      xml.send('ds:SignatureValue', '')
    }
  end.doc.root
end

#bodyObject



25
26
27
28
29
# File 'lib/epics/generic_request.rb', line 25

def body
  Nokogiri::XML::Builder.new do |xml|
    xml.body
  end.doc.root
end

#headerObject

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/epics/generic_request.rb', line 31

def header
  raise NotImplementedError
end

#nonceObject



11
12
13
# File 'lib/epics/generic_request.rb', line 11

def nonce
  SecureRandom.hex(16)
end

#rootObject



21
22
23
# File 'lib/epics/generic_request.rb', line 21

def root
  "ebicsRequest"
end

#timestampObject



15
16
17
# File 'lib/epics/generic_request.rb', line 15

def timestamp
  Time.now.utc.iso8601
end

#to_receipt_xmlObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/epics/generic_request.rb', line 77

def to_receipt_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision' => '1') {
      xml.header(authenticate: true) {
        xml.static {
          xml.HostID host_id
          xml.TransactionID(transaction_id)
        }
        xml.mutable {
          xml.TransactionPhase 'Receipt'
        }
      }
      xml.parent.add_child(auth_signature)
      xml.body {
        xml.TransferReceipt(authenticate: true) {
          xml.ReceiptCode 0
        }
      }
    }
  end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
end

#to_transfer_xmlObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/epics/generic_request.rb', line 54

def to_transfer_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision' => '1') {
      xml.header(authenticate: true) {
        xml.static {
          xml.HostID host_id
          xml.TransactionID transaction_id
        }
        xml.mutable {
          xml.TransactionPhase 'Transfer'
          xml.SegmentNumber(1, lastSegment: true)
        }
      }
      xml.parent.add_child(auth_signature)
      xml.body {
        xml.DataTransfer {
          xml.OrderData encrypted_order_data
        }
      }
    }
  end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
end

#to_xmlObject



99
100
101
102
103
104
105
106
107
# File 'lib/epics/generic_request.rb', line 99

def to_xml
  Nokogiri::XML::Builder.new do |xml|
    xml.send(root, 'xmlns:ds' => 'http://www.w3.org/2000/09/xmldsig#', 'xmlns' => 'urn:org:ebics:H004', 'Version' => 'H004', 'Revision'=> '1') {
      xml.parent.add_child(header)
      xml.parent.add_child(auth_signature)
      xml.parent.add_child(body)
    }
  end.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::AS_XML, encoding: 'utf-8')
end