Skip to content

danielosorio83/shipstation-ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shipstation-ruby

This is a Ruby wrapper for ShipStation's OData API.

0.0.1 Features

here

0.0.2 Features

  • Support spacename, You can use it with rails model Order and SS::Order. SS is default namespace.
  • Support api host
  • Collection Create

0.0.3 Features

  • Collection Update
  • Collection Delete( set attr Active = false )
  • Collection Destroy( call delete_object )

0.0.4 Features

  • Collection First
  • Collection Last
  • Collection Count
  • Collection return Rash instance
  • Collection Create return a instance, not Array.
  • Collection Where by array
  • Collection Where by String. eg. client.orders.where("CreateDate ge datetime'2014-06-17'") You can write a filter string, read more here, here, and here
  • Test with shipstation api 1.3

0.0.5 Features

Rename the gem to shipstation-rb.

0.0.6 Features

Removed gem dependency versions.

Installation

gem 'shipstation-rb', '~> 0.0.5'
gem 'awesome_print', :require => 'ap'

Rails Configuration

The ShipStation API uses basic HTTP authentication. Inside config/initializers, create a new configuration file and use the following template to pass in your ShipStation credentials:

ShipStation.username  = ENV['SHIPSTATION_USERNAME']
ShipStation.password  = ENV['SHIPSTATION_PASSWORD']
ShipStation.api_host  = ENV['SHIPSTATION_API_HOST']

OR

require "shipstation"
client = ShipStation::Client.new(APICONFIG[:ship_station_api], APICONFIG[:ship_station_account], APICONFIG[:ship_station_password])

Usage

Set your credentials and create a new client:

ShipStation.api_host  = "https://data.shipstation.com/1.3"
ShipStation.password  = "shipstation_password"
ShipStation.password  = "shipstation_password"
client = ShipStation::Client.new

Or create a new client by passing credentials directly:

client = ShipStation::Client.new("https://data.shipstation.com/1.3", "username", "password")

Query a resource by record id:

order = client.order.find(12345)

Get all records for any given resource in an array (paginated in batches of 100):

orders = client.order.all

Query records for any resource by any attribute, returns an array:

open_texas_orders = client.order.where("active" => "true", "ship_state" => "TX")

Other resources follow a similar pattern

all_warehouses = client.warehouse.all
customer_12345 = client.customer.find(12345)
texas_fedex_shipments = client.shipment.where("shipping_service_id" => 0001, "state" => "TX")

etc.

Once returned, resources can be queried by field name

client = ShipStation::Client.new
order = client.order.find(12345)

order.order_id ## 12345
order.ship_city ## Boise
order.order_total ## $343.32

Create order

client = ShipStation::Client.new
client.order.create(OrderNumber: "T0001", OrderStatusID: 2)

Update order

client = ShipStation::Client.new
client.order.Update(1234, OrderNumber: "T0002", OrderStatusID: 2)

Delete order

client = ShipStation::Client.new
client.orders.delete(1234)  #=> order.active = false

Destory order

client = ShipStation::Client.new
client.orders.destory(1234) # svc.delete_object(klass)

List all stores

client = ShipStation::Client.new
client.stores.all

First of clollection

client = ShipStation::Client.new
client.stores.first

Last of clollection

client = ShipStation::Client.new
client.stores.last

Crate a Order

client = ShipStation::Client.new
client.order.create(
        StoreID: APICONFIG[:ship_station_store_id],
        OrderNumber: real_order.number,
        ImportKey: "OrderID#{real_order.id}",
        OrderDate: real_order.order_date,
        PayDate: real_order.order_date,
        OrderStatusID: 2,
        RequestedShippingService: provider_name,
        OrderTotal: real_order.total,
        AmountPaid: real_order.payment_total,
        ShippingAmount: real_order.adjustments.select{|aa| aa["label"] == "Shipping" }[0].try(:amount),
        TaxAmount:      real_order.adjustments.select{|aa| aa["label"] == "sales_tax"}[0].try(:amount),
        NotesFromBuyer: "Please make sure it gets here by Monday!",
        InternalNotes: "Expedite this order.",
        BuyerName: real_order.user.login,
        BuyerEmail: real_order.user.email,
        ShipName: "#{real_order.ship_address.firstname} #{real_order.ship_address.lastname}",
        ShipCompany: "",
        ShipStreet1: real_order.ship_address.address1,
        ShipCity: real_order.ship_address.city,
        ShipState: real_order.ship_address.state.name,
        ShipPostalCode: real_order.ship_address.zipcode,
        ShipCountryCode: real_order.ship_address.country.iso,
        ShipPhone: real_order.ship_address.phone,
        AddressVerified: 0,
        MarketplaceID: 0,
        InsuranceProvider: 0,
        Confirmation: 0)

Requirements

This gem has been tested on Ruby 1.9.3 on version 1.1 of ShipStation's API.(by author)

This gem has been tested on Ruby ruby-2.0.0-p247 on version 1.2 and 1.3 of ShipStation's API.(By Rique Li)

About This Gem

I am Rique Li, I fork this from shipstation-ruby and make some changes, when all test done, I will make a PR.

If You like this gem, write me. ^_^

About

A Ruby wrapper for the ShipStation API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%