Sha256: 1278ba6ec34de107ce80108096fe8b8b69d58f411ee6bae896bf85f966b9b8fc

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'fedex_ship/request/shipment'
require 'fedex_ship/document'

module FedexShip
  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
        })

        FedexShip::Document.new shipment_documents
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fedex_ship-0.1.0 lib/fedex_ship/request/document.rb