ActiveResource-based Ruby client for Stallion Express API v4.
gem 'stallionexpress'StallionExpress.configure!(
api_token: ENV["STALLION_EXPRESS_API_TOKEN"],
)# Get all orders (lazy - fetches as needed)
StallionExpress::Order.all_lazy.each do |order|
puts order.order_id
order.items.each do |item|
puts " #{item.description}: #{item.quantity}"
end
end
# Find a specific order
order = StallionExpress::Order.find("ORDER-123")
# Create an order
order = StallionExpress::Order.create!(
store_id: "1234",
order_id: "ORDER-001",
name: "Jane Doe",
address1: "30 Clearview Dr",
city: "Rock Springs",
province_code: "WY",
postal_code: "82901",
country_code: "US",
weight: 0.6,
items: [
{ title: "Product", quantity: 1, value: 10.5 }
]
)# Get all shipments with tracking codes
StallionExpress::Shipment.all_lazy.each do |shipment|
puts "Order #{shipment.order_id}: #{shipment.tracking_code}"
puts "To: #{shipment.to_address.name}" if shipment.to_address
end
# Get full tracking details
tracking = StallionExpress::Shipment.track(order_id: "ORDER-123")
puts tracking.status
tracking.events.each do |event|
puts "#{event.datetime}: #{event.status} at #{event.location}"
end
puts "Tracking URL: #{tracking.details.url}" if tracking.details
# Create a shipment
shipment = StallionExpress::Shipment.create!(
to_address: {
name: "Jane Doe",
address1: "30 Clearview Dr",
city: "Rock Springs",
province_code: "WY",
postal_code: "82901",
country_code: "US"
},
weight: 0.6,
items: [
{ description: "Product", quantity: 1, value: 10 }
]
)rates = StallionExpress::Rates.quote(
to_address: { ... },
weight: 0.6,
items: [ ... ]
)
rates.each do |rate|
puts "#{rate.postage_type}: $#{rate.total_rate}"
endMIT