class Endicia::Label
Public Instance Methods
request_label(values = {}, options = {})
click to toggle source
values is a Hash of the API values you wish to send to Endicia
, nested as the documentation describes options is a Hash of other options (see default_options() for available options)
# File lib/endicia_ruby/label.rb, line 11 def request_label(values = {}, options = {}) # Build the options for this method with passed in values overriding defaults root_node_attrs = root_attributes.merge!(values[:attrs] || {}) # Include API credentials in the values we use to build the XML node_values = @options[:credentials].merge!(values[:nodes] || {}) builder = Nokogiri::XML::Builder.new do |xml| xml.LabelRequest(root_node_attrs) do recursive_build_xml_nodes!(xml, node_values) end end xml_body = builder.to_xml # Log the XML of the request if desired log("ENDICIA LABEL REQUEST: #{format_xml_for_logging(xml_body)}") if options[:log_requests] # Post the XML to the appropriate API URL url = "#{api_url_base}/GetPostageLabelXML" # Endicia's test server has an invalid certificate o_O raw_response = self.class.post(url, body: "labelRequestXML=#{xml_body}", verify: environment != :test) # Log the XML of the response if desired log("ENDICIA LABEL RESPONSE: #{format_xml_for_logging(raw_response.body)}") if options[:log_responses] # Build a nice response object and return it Endicia::LabelResponse.new(raw_response).tap do |the_label| the_label.request_body = xml_body.to_s the_label.request_url = url end end
Protected Instance Methods
root_attributes()
click to toggle source
# File lib/endicia_ruby/label.rb, line 45 def root_attributes { Test: api_test_mode_value, LabelType: 'Default', } end