class Newgistics::Requests::PostManifest

Attributes

manifest[R]
response_handler[R]

Public Class Methods

new(manifest, response_handler: nil) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 6
def initialize(manifest, response_handler: nil)
  @manifest = manifest
  @response_handler = response_handler || default_response_handler
end

Public Instance Methods

body() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 15
def body
  xml_builder.to_xml
end
path() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 11
def path
  '/post_manifests.aspx'
end
perform() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 19
def perform
  Newgistics.api.post(self, response_handler)
end

Private Instance Methods

api_key() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 25
def api_key
  Newgistics.configuration.api_key
end
contents_xml(xml) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 72
def contents_xml(xml)
  xml.contents do
    manifest.contents.each { |item| item_xml(item, xml) }
  end
end
default_response_handler() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 87
def default_response_handler
  ResponseHandlers::PostManifest.new(manifest)
end
format_date(date) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 68
def format_date(date)
  date.strftime("%m/%d/%Y") if date.respond_to?(:strftime)
end
item_xml(item, xml) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 78
def item_xml(item, xml)
  xml.item do
    xml.sku item.sku
    xml.description item.description
    xml.original_qty item.original_qty
    xml.received_qty item.received_qty
  end
end
manifest_slip_xml(xml) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 48
def manifest_slip_xml(xml)
  manifest_slip = manifest.manifest_slip || ManifestSlip.new

  xml.manifest_slip do
    xml.manifest_po manifest_slip.manifest_po
    xml.manifest_name manifest_slip.manifest_name
    xml.warehouse_id manifest_slip.warehouse_id
    xml.status manifest_slip.status
    xml.tracking_no manifest_slip.tracking_no
    xml.pallet_count manifest_slip.pallet_count
    xml.carton_count manifest_slip.carton_count
    xml.weight manifest_slip.weight
    xml.notes manifest_slip.notes
    xml.ship_date format_date(manifest_slip.ship_date)
    xml.estimated_arrival_date format_date(
      manifest_slip.estimated_arrival_date
    )
  end
end
manifest_xml(xml) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 41
def manifest_xml(xml)
  xml.manifest do
    manifest_slip_xml(xml)
    contents_xml(xml)
  end
end
manifests_xml(xml) click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 35
def manifests_xml(xml)
  xml.manifests(apiKey: api_key) do
    manifest_xml(xml)
  end
end
xml_builder() click to toggle source
# File lib/newgistics/requests/post_manifest.rb, line 29
def xml_builder
  Nokogiri::XML::Builder.new do |xml|
    manifests_xml(xml)
  end
end