Sha256: fd29a461a40914bb41b00fda27e23b5b0a46d6b63022e59cc86ab286ad49ea92

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

require 'fedex/request/shipment'
require 'fedex/document'

module Fedex
  module Request
    class Document < Shipment

      def initialize(credentials, options={})
        super(credentials, options)

        @shipping_document = options[:shipping_document]
        @filenames = options.fetch(:filenames) { {} }
      end

      def add_custom_components(xml)
        super

        add_shipping_document(xml) if @shipping_document
      end

      private

      # Add shipping document specification
      def add_shipping_document(xml)
        xml.ShippingDocumentSpecification{
          Array(@shipping_document[:shipping_document_types]).each do |type|
            xml.ShippingDocumentTypes type
          end
          hash_to_xml(xml, @shipping_document.reject{ |k| k == :shipping_document_types})
        }
      end

      def success_response(api_response, response)
        super

        shipment_documents = response.merge!({
          :filenames => @filenames
        })

        Fedex::Document.new shipment_documents
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
fedex-3.10.11 lib/fedex/request/document.rb
fedex-3.10.1 lib/fedex/request/document.rb
fedex-3.10.0 lib/fedex/request/document.rb
fedex-3.9.1 lib/fedex/request/document.rb
fedex-3.9.0 lib/fedex/request/document.rb
fedex-3.8.0 lib/fedex/request/document.rb
fedex-3.6.1 lib/fedex/request/document.rb
fedex-3.6.0 lib/fedex/request/document.rb
fedex-3.4.0 lib/fedex/request/document.rb
fedex-3.3.1 lib/fedex/request/document.rb
fedex-3.3.0 lib/fedex/request/document.rb
fedex-3.1.0 lib/fedex/request/document.rb