class Zuora::Calls::Amend

Public Instance Methods

xml_builder() click to toggle source

Returns a function that given a builder, constructs an Ammendment @return [Callable] function of builder

# File lib/zuora/calls/amend.rb, line 12
def xml_builder
  lambda do |builder|
    builder[:api].amend do
      builder[:api].requests do
        Array.wrap(amendments).each do |amendment|
          build_object builder, :amendments, amendment, :obj
        end
        build_object builder, :amend_options, amend_options, :api
        build_object builder, :preview_options, preview_options, :api
      end
    end
  end
end

Private Instance Methods

build_node(builder, child_ns, field, value) click to toggle source

Builds one node. Behavior differs based on whether value is a hash If value is a hash, a parent node is rendered and the call is applied to its children. If it is a child node, a child node is rendered. @param [Nokogiri::XML::Builder] builder @param [Symbol] child_ns - child namespace @param [Symbol] field - snake case name of a Zuora object or field @param [Enumerable or Object] - parent or child node @return nil

# File lib/zuora/calls/amend.rb, line 37
def build_node(builder, child_ns, field, value)
  field = Zuora::Utils::Envelope.to_zuora_key field
  if value.respond_to?(:each)
    # Parent
    builder[:api].send(field) { build_nodes builder, value, child_ns }
  else
    # Child
    builder[child_ns].send(field, value)
  end
end
build_nodes(builder, root, child_ns) click to toggle source

Takes a hash and builds SOAP XML nodes. See build_node for behavior. @param [Nokogiri::XML::Builder] builder @param [Enumerable] root @param [Symbol] child_ns - child node namespace @return nil

# File lib/zuora/calls/amend.rb, line 53
def build_nodes(builder, root, child_ns)
  root.each(&->(k, v) { build_node builder, child_ns, k, v })
end
build_object(builder, property_name, object, child_ns) click to toggle source

Helper to recursively build XML from nested objects. @param [Nokogiri::XML::Builder] builder @param [Symbol] property_name - name of a property on this object @param [Symbol] child_ns - namespace of child node fields @return nil

# File lib/zuora/calls/amend.rb, line 62
def build_object(builder, property_name, object, child_ns)
  raise 'Objects must respond to each' unless object.respond_to?(:each)
  object_name = Zuora::Utils::Envelope.to_zuora_key property_name
  builder[:api].send(object_name) do
    build_nodes builder, object, child_ns
  end
end