Class: Epics::HeaderRequest

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ HeaderRequest

Returns a new instance of HeaderRequest.



5
6
7
# File 'lib/epics/header_request.rb', line 5

def initialize(client)
  self.client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



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

def client
  @client
end

Instance Method Details

#build(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/epics/header_request.rb', line 11

def build(options = {})
  options[:with_bank_pubkey_digests] = true if options[:with_bank_pubkey_digests].nil?

  Nokogiri::XML::Builder.new do |xml|
    xml.header(authenticate: true) {
      xml.static {
        xml.HostID host_id
        xml.Nonce options[:nonce] if options[:nonce]
        xml.Timestamp options[:timestamp] if options[:timestamp]
        xml.PartnerID partner_id
        xml.UserID user_id
        xml.Product(client.product_name, 'Language' => client.locale)
        xml.OrderDetails {
          xml.OrderType options[:order_type]
          xml.OrderAttribute options[:order_attribute]
          xml.StandardOrderParams {
            build_attributes(xml, options[:order_params])
          } if options[:order_params]
          build_attributes(xml, options[:custom_order_params]) if options[:custom_order_params]
        }
        xml.BankPubKeyDigests {
          xml.Authentication(client.bank_x.public_digest, Version: 'X002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256')
          xml.Encryption(client.bank_e.public_digest, Version: 'E002', Algorithm: 'http://www.w3.org/2001/04/xmlenc#sha256')
        } if options[:with_bank_pubkey_digests]
        xml.SecurityMedium '0000'
        xml.NumSegments options[:num_segments] if options[:num_segments]
      }
      xml.mutable {
        build_attributes(xml, options[:mutable])
      } if options[:mutable]
    }
  end.doc.root
end