Class: RequestDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/cxml/documents/request_doc.rb

Overview

Default parent for all Request builders

Direct Known Subclasses

ConfirmationRequest, ShipNoticeRequest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RequestDoc

Returns a new instance of RequestDoc.



6
7
8
# File 'lib/cxml/documents/request_doc.rb', line 6

def initialize(opts={})
  @opts = opts.with_indifferent_access.reverse_merge(self.class.class_variable_defined?("@@defaults") ? self.class.class_variable_get("@@defaults") : {})
end

Instance Attribute Details

#optsObject

Returns the value of attribute opts.



3
4
5
# File 'lib/cxml/documents/request_doc.rb', line 3

def opts
  @opts
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
# File 'lib/cxml/documents/request_doc.rb', line 10

def [](key)
  @opts[key]
end

#[]=(key, val) ⇒ Object



14
15
16
# File 'lib/cxml/documents/request_doc.rb', line 14

def []=(key,val)
  @opts[key] = val
end

#featuresObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/cxml/documents/request_doc.rb', line 27

def features
  raise NotImplementedError, "Missing features function for #{self.class.name}"
end

#renderObject



18
19
20
21
22
23
24
25
# File 'lib/cxml/documents/request_doc.rb', line 18

def render
  doc = CXML::Document.new('Request' => { 'builder' => proc { |node|
    features(node)
  }})

  doc.setup
  doc.render.to_xml
end

#send(endpoint) ⇒ Object



31
32
33
34
35
# File 'lib/cxml/documents/request_doc.rb', line 31

def send(endpoint)
  RestClient.post endpoint, self.render, content_type: :xml

  # TODO: Abstract and verify response
end