class Newgistics::Requests::PostInboundReturn

Attributes

inbound_return[R]
response_handler[R]

Public Class Methods

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

Public Instance Methods

body() click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 15
def body
  xml_builder.to_xml
end
path() click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 11
def path
  '/post_inbound_returns.aspx'
end
perform() click to toggle source
# File lib/newgistics/requests/post_inbound_return.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_inbound_return.rb, line 41
def api_key
  Newgistics.configuration.api_key
end
default_response_handler() click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 25
def default_response_handler
  ResponseHandlers::PostInboundReturn.new(inbound_return)
end
item_xml(item, xml) click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 67
def item_xml(item, xml)
  xml.Item do
    xml.SKU item.sku
    xml.Qty item.qty
    xml.Reason item.reason
  end
end
items_xml(items, xml) click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 61
def items_xml(items, xml)
  xml.Items do
    items.each { |item| item_xml(item, xml) }
  end
end
return_attributes(inbound_return) click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 54
def return_attributes(inbound_return)
  {
    id: inbound_return.shipment_id,
    orderID: inbound_return.order_id
  }.reject { |_k, v| v.nil? || v.empty? }
end
return_xml(inbound_return, xml) click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 45
def return_xml(inbound_return, xml)
  xml.Return(return_attributes(inbound_return)) do
    xml.RMA inbound_return.rma
    xml.Comments inbound_return.comments

    items_xml(inbound_return.items, xml)
  end
end
returns_xml(xml) click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 35
def returns_xml(xml)
  xml.Returns(apiKey: api_key) do
    return_xml(inbound_return, xml)
  end
end
xml_builder() click to toggle source
# File lib/newgistics/requests/post_inbound_return.rb, line 29
def xml_builder
  Nokogiri::XML::Builder.new do |xml|
    returns_xml(xml)
  end
end