Method: Bandwidth#build_xml

Defined in:
lib/bandwidth/bandwidth.rb

#build_xml(method_name, params) ⇒ String

Builds the XML document for the method call

Parameters:

  • method name to invoke on the REST API

  • parameters to pass to the method, should be symbols and may be all lowercase with underscores or camelCase

Returns:

  • the resulting XML document



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/bandwidth/bandwidth.rb', line 85

def build_xml(method_name, params)
  builder_params = params.merge({ :developer_key => @developer_key })
  
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.send(method_name.to_s.camelize.uncapitalize.to_sym, xml_namespaces) do
      builder_params.each do |parent_k, parent_v|
        if parent_v.instance_of?(Array)
          xml.send(parent_k.to_s.camelize.uncapitalize.to_sym) do
            parent_v.each do |item|
              item.each do |item_k, item_v|
                symbol = (item_k.to_s + '_').to_sym
                xml.send(symbol, item_v)
              end
            end
          end
        else
          xml.send(parent_k.to_s.camelize.uncapitalize.to_sym, parent_v)
        end
      end
    end
  end
  builder.to_xml
end