Sha256: 7260de26ec3abc7440186571b4b221a89f60d0c6cf54a2c6a1c46c540db3335c
Contents?: true
Size: 1.76 KB
Versions: 8
Compression:
Stored size: 1.76 KB
Contents
require 'nokogiri' require_relative 'label_response' require_relative 'request' module Endicia class Label < Request # 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) 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 def root_attributes { Test: api_test_mode_value, LabelType: 'Default', } end end end
Version data entries
8 entries across 8 versions & 1 rubygems