Class: GlobalCollect::Requests::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/global_collect/requests/base.rb

Direct Known Subclasses

Composite, Simple

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/global_collect/requests/base.rb', line 7

def initialize(action)
  @action = action
  @suggested_response_mixins ||= []
  @version = GlobalCollect::default_api_version
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



3
4
5
# File 'lib/global_collect/requests/base.rb', line 3

def action
  @action
end

#suggested_response_mixinsObject (readonly)

Returns the value of attribute suggested_response_mixins.



5
6
7
# File 'lib/global_collect/requests/base.rb', line 5

def suggested_response_mixins
  @suggested_response_mixins
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/global_collect/requests/base.rb', line 4

def version
  @version
end

Instance Method Details

#default_xml_encoding_optionsObject

WDL §3.1



19
20
21
# File 'lib/global_collect/requests/base.rb', line 19

def default_xml_encoding_options
  { :encoding => "UTF-8" }
end

#to_xmlObject

WDL §4



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/global_collect/requests/base.rb', line 24

def to_xml
  xml = Builder::XmlMarkup.new
  xml.instruct!(:xml, default_xml_encoding_options)
  xml.tag!("XML") do |xml_node|
    xml_node.tag!("REQUEST") do |req_node|
      req_node.tag!("ACTION", @action)
      req_node.tag!("META") do |meta_node|
        meta_node.tag!("IPADDRESS" , GlobalCollect::ip_address ) if GlobalCollect::authentication_scheme == :ip_check
        meta_node.tag!("MERCHANTID", GlobalCollect::merchant_id)
        meta_node.tag!("VERSION"   , version)
      end
      req_node.tag!("PARAMS") do |params_node|
        yield(params_node)
      end
    end
  end
  xml.target!
end