Class: Securetrading::XmlDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/securetrading/xml_doc.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_type, account_type) ⇒ XmlDoc

Returns a new instance of XmlDoc.



3
4
5
6
# File 'lib/securetrading/xml_doc.rb', line 3

def initialize(request_type, )
  @account_type = 
  @request_type = request_type
end

Class Method Details

.elements(hash) ⇒ Object

rubocop:disable Metrics/MethodLength



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/securetrading/xml_doc.rb', line 18

def self.elements(hash)
  return [''] unless hash.present?
  hash.flat_map do |k, v|
    return v.flat_map { |e| elements(k => e) } if v.is_a?(Array)
    el = new_element(k.to_s)
    if v.is_a?(Hash)
      elements(v).each { |e| el << e }
    else
      el << v.to_s
    end
    [el]
  end
end

.new_element(name) ⇒ Object

rubocop:enable Metrics/MethodLength



33
34
35
# File 'lib/securetrading/xml_doc.rb', line 33

def self.new_element(name)
  Ox::Element.new(name)
end

Instance Method Details

#docObject



8
9
10
11
12
13
14
15
# File 'lib/securetrading/xml_doc.rb', line 8

def doc
  return @doc if @doc.present?
  @doc = Ox::Document.new(version: '1.0')
  root = new_element('requestblock')
  root[:version] = '3.67'
  root << alias_el << request_el
  @doc << root
end