class MWS::Client

MWS::Client

Attributes

access_key_id[RW]

Amazon Access Key ID

from_address[RW]

From Address

fulfillment_center_id[RW]
inbound_shipment[RW]

Inbound Shipment

inbound_shipment_plan[RW]

Inbound Shipment

items[RW]

Items

label_prep_preference[RW]

Label Prep Preference

marketplace_id[RW]

Amazon Marketplace

merchant_id[RW]

Amazon Merchant ID (also Seller ID)

s3_access_key_id[RW]
s3_secret_access_key[RW]
secret_access_key[RW]

Amazon Secret Access Key

shipment_id[RW]

Shipment ID (assigned by amazon)

shipment_name[RW]

Shipment Name

shipment_status[RW]

Public Class Methods

new(args={}) click to toggle source
# File lib/mws.rb, line 28
def initialize(args={})
  args.each { |k, v| send("#{k}=", v) }
  @items = []
end

Public Instance Methods

create_inbound_shipment() click to toggle source

CreateInboundShipment

# File lib/mws.rb, line 117
def create_inbound_shipment
  puts "creating new inbound shipment..."
  
  request = Request.new({
    'Action'                                                    => 'CreateInboundShipment',
    'Marketplace'                                               => @marketplace_id,
    'SellerId'                                                  => @merchant_id,
    'AWSAccessKeyId'                                            => @access_key_id,
    'InboundShipmentHeader.ShipmentName'                        => @shipment_name,
    'InboundShipmentHeader.ShipFromAddress.Name'                => @from_address[:name],
    'InboundShipmentHeader.ShipFromAddress.AddressLine1'        => @from_address[:address_line_1],
    'InboundShipmentHeader.ShipFromAddress.AddressLine2'        => @from_address[:address_line_2],
    'InboundShipmentHeader.ShipFromAddress.City'                => @from_address[:city],
    'InboundShipmentHeader.ShipFromAddress.StateOrProvinceCode' => @from_address[:state_or_province_code],
    'InboundShipmentHeader.ShipFromAddress.PostalCode'          => @from_address[:postal_code],
    'InboundShipmentHeader.ShipFromAddress.CountryCode'         => @from_address[:country_code],
    'InboundShipmentHeader.DestinationFulfillmentCenterId'      => @inbound_shipment_plan["member"]["DestinationFulfillmentCenterId"]
  },@secret_access_key)
  
  puts "created request"

  @inbound_shipment_plan["member"]["Items"]["member"].each_with_index do |item, index|
    request << {
      "InboundShipmentItems.member.#{index+1}.QuantityShipped"  => item["Quantity"],
      "InboundShipmentItems.member.#{index+1}.SellerSKU"        => item["SellerSKU"]
    }
  end
  
  puts "added items"
  response = request.post.to_hash
  ap response
  @shipment_id = request.post["CreateInboundShipmentResponse"]["CreateInboundShipmentResult"]["ShipmentId"]
end
create_inbound_shipment_plan() click to toggle source

CreateInboundShipmentPlan

# File lib/mws.rb, line 84
def create_inbound_shipment_plan
  request = Request.new({
    'Action'                              => 'CreateInboundShipmentPlan',
    'Marketplace'                         => @marketplace_id,
    'SellerId'                            => @merchant_id,
    'AWSAccessKeyId'                      => @access_key_id,
    'ShipFromAddress.Name'                => @from_address[:name],
    'ShipFromAddress.AddressLine1'        => @from_address[:address_line_1],
    'ShipFromAddress.AddressLine2'        => @from_address[:address_line_2],
    'ShipFromAddress.City'                => @from_address[:city],
    'ShipFromAddress.StateOrProvinceCode' => @from_address[:state_or_province_code],
    'ShipFromAddress.PostalCode'          => @from_address[:postal_code],
    'ShipFromAddress.CountryCode'         => @from_address[:country_code],
    'LabelPrepPreference'                 => @label_prep_preference
  },@secret_access_key)
  
  @items.flatten!.each_with_index do |item, index|
    request << {
      "InboundShipmentPlanRequestItems.member.#{index+1}.Condition" => item[:condition],
      "InboundShipmentPlanRequestItems.member.#{index+1}.SellerSKU" => item[:seller_sku],
      "InboundShipmentPlanRequestItems.member.#{index+1}.ASIN"      => item[:asin],
      "InboundShipmentPlanRequestItems.member.#{index+1}.Quantity"  => item[:quantity]
    }
  end
  
  @inbound_shipment_plan = request.post["CreateInboundShipmentPlanResponse"]["CreateInboundShipmentPlanResult"]["InboundShipmentPlans"]
  @fulfillment_center_id = @inbound_shipment_plan["member"]["DestinationFulfillmentCenterId"]
  @inbound_shipment_plan
end
fba_label() click to toggle source
# File lib/mws.rb, line 171
def fba_label
  FBA::ShippingLabel.new({
    :shipment_id => @shipment_id,
    :ship_from_address => format_from_address,
    :ship_to_address => format_to_address,
    :access_key_id => @s3_access_key_id,
    :secret_access_key => @s3_secret_access_key,
    :template_url => "http://bsgnpo.s3.amazonaws.com/template.fba.label.pdf",
    :bucket => 'bsgnpo'
  })
end
fba_packing_slip() click to toggle source
# File lib/mws.rb, line 183
def fba_packing_slip
  MWS::PackingSlip.new({
    :shipment_id => @shipment_id,
    :ship_from_address => format_from_address,
    :ship_to_address => format_to_address,
    :access_key_id => @s3_access_key_id,
    :secret_access_key => @s3_secret_access_key,
    :template_url => "http://bsgnpo.s3.amazonaws.com/template.fba.packing.slip.pdf",
    :bucket => 'bsgnpo'
  })
end
format_from_address() click to toggle source
# File lib/mws.rb, line 151
def format_from_address
  [
    @from_address[:name],
    [@from_address[:address_line_1], @from_address[:address_line_2]].join,
    "#{@from_address[:city]}, #{@from_address[:state_or_province_code]} #{@from_address[:postal_code]}",
    TZInfo::Country.get(@from_address[:country_code]).name
  ].join("\n")
end
format_to_address() click to toggle source
# File lib/mws.rb, line 160
def format_to_address
  ship_to_address = @inbound_shipment_plan["member"]["ShipToAddress"]

  [
    ship_to_address["Name"],
    [ship_to_address["AddressLine1"], (ship_to_address["AddressLine2"] || [])].join,
    "#{ship_to_address["City"]}, #{ship_to_address["StateOrProvinceCode"]} #{ship_to_address["PostalCode"]}",
    TZInfo::Country.get(ship_to_address["CountryCode"]).name
  ].join("\n")
end
get_service_status() click to toggle source

GetServiceStatus

# File lib/mws.rb, line 72
def get_service_status
  Request.new({
    'Action' => 'GetServiceStatus',
    'Marketplace' => @marketplace_id,
    'SellerId' => @merchant_id,
    'AWSAccessKeyId' => @access_key_id
  },@secret_access_key).post
end
set_shipment_status(status) click to toggle source
# File lib/mws.rb, line 195
def set_shipment_status(status)
  request = Request.new({
    'Action'                                                    => 'CreateInboundShipment',
    'Marketplace'                                               => @marketplace_id,
    'SellerId'                                                  => @merchant_id,
    'AWSAccessKeyId'                                            => @access_key_id,
    'InboundShipmentHeader.ShipmentName'                        => @shipment_name,
    'InboundShipmentHeader.ShipmentStatus'                      => status,
    'InboundShipmentHeader.ShipFromAddress.Name'                => @from_address[:name],
    'InboundShipmentHeader.ShipFromAddress.AddressLine1'        => @from_address[:address_line_1],
    'InboundShipmentHeader.ShipFromAddress.AddressLine2'        => @from_address[:address_line_2],
    'InboundShipmentHeader.ShipFromAddress.City'                => @from_address[:city],
    'InboundShipmentHeader.ShipFromAddress.StateOrProvinceCode' => @from_address[:state_or_province_code],
    'InboundShipmentHeader.ShipFromAddress.PostalCode'          => @from_address[:postal_code],
    'InboundShipmentHeader.ShipFromAddress.CountryCode'         => @from_address[:country_code],
    'InboundShipmentHeader.DestinationFulfillmentCenterId'      => @fulfillment_center_id
  },@secret_access_key)
  
  response = request.post.to_hash
  shipment_id = response["CreateInboundShipmentResponse"]["CreateInboundShipmentResult"]["ShipmentId"]

  if shipment_id
    @shipment_status = status
  end
  shipment_id
end