Skip to content

Instantly share code, notes, and snippets.

View schof's full-sized avatar

Sean Schofield schof

  • Stedi
  • Washington, DC
View GitHub Profile
@schof
schof / gist:9711306
Created March 22, 2014 17:41
Sample /add_order response
{"request_id":"52f367367575e449c3000001","summary":"Order created in ShipStation: 90833246","order":{"id":"R154085346","shipstation_id":90833246}}
@schof
schof / line_items.json
Created April 2, 2014 18:44
Same line items
"line_items": [
{
"product_id": "0300385BLK00M",
"name": "eve dress",
"quantity": 1,
"price": 198,
"image_url": "https://thereformation.com/rcms/media/3964/resize?size=60x60&tags=clp",
"properties": {
"color": "Black",
"size": "XS"
@schof
schof / gist:2cfc8989d2a37e9a34f1
Created February 8, 2015 01:59
Order Number Generator
# Current time in hex (saves a few chars)
n = Time.now.to_i.to_s(16)
# Add some more random digits and convert to base24 (more entropy w/minimal chars)
n += rand(9999).to_s(24)
# Make sure the whole thing is exactly 10 chars
n.ljust(10).gsub(" ", "0")
# Convert to upcase
#!/bin/bash
# A simple script to backup an organization's GitHub repositories.
GHBU_BACKUP_DIR=${GHBU_BACKUP_DIR-"github-backups"} # where to place the backup files
GHBU_ORG=$GHBU_ORG # the GitHub organization whose repos will be backed up
GHBU_API=${GHBU_API-"https://api.github.com"} # base URI for the GitHub API
GHBU_GITHOST="github.com" # the GitHub hostname (see comments)
# I recommend using an API token so it is easily trackable and removable.
# Note that you MUST have SSH keys for a user with the access to all repos set up
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
if git-rev-parse --verify HEAD > /dev/null
Processing ProductsController#show (for 127.0.0.1 at 2009-11-15 17:55:52) [GET]
Parameters: {"action"=>"show", "id"=>"palmgard-grip-tack-lite-adult-football-lineman-gloves", "controller"=>"products"}
[4;36;1mProduct Load (0.9ms)[0m [0;1mSELECT * FROM `products` WHERE (`products`.`permalink` = 'palmgard-grip-tack-lite-adult-football-lineman-gloves') LIMIT 1[0m
Cache miss: Spree::Config ({})
[4;35;1mPreference Load (0.4ms)[0m [0mSELECT * FROM `preferences` WHERE (`preferences`.owner_id = 1 AND `preferences`.owner_type = 'Configuration') [0m
[4;36;1mConfiguration Columns (1.2ms)[0m [0;1mSHOW FIELDS FROM `configurations`[0m
[4;35;1mConfiguration Load (0.2ms)[0m [0mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
[4;36;1mCACHE (0.0ms)[0m [0;1mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
[4;35;1mCACHE (0.0ms)[0m [0mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
Cache write (will save 3.80ms): Spree::Config
Processing ProductsController#show (for 127.0.0.1 at 2009-11-15 17:55:52) [GET]
Parameters: {"action"=>"show", "id"=>"palmgard-grip-tack-lite-adult-football-lineman-gloves", "controller"=>"products"}
[4;36;1mProduct Load (0.9ms)[0m [0;1mSELECT * FROM `products` WHERE (`products`.`permalink` = 'palmgard-grip-tack-lite-adult-football-lineman-gloves') LIMIT 1[0m
Cache miss: Spree::Config ({})
[4;35;1mPreference Load (0.4ms)[0m [0mSELECT * FROM `preferences` WHERE (`preferences`.owner_id = 1 AND `preferences`.owner_type = 'Configuration') [0m
[4;36;1mConfiguration Columns (1.2ms)[0m [0;1mSHOW FIELDS FROM `configurations`[0m
[4;35;1mConfiguration Load (0.2ms)[0m [0mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
[4;36;1mCACHE (0.0ms)[0m [0;1mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
[4;35;1mCACHE (0.0ms)[0m [0mSELECT * FROM `configurations` WHERE (`configurations`.`id` = 1) [0m
Cache write (will save 3.80ms): Spree::Config
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders?search[number]=R664048424 --globoff -i
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6"
http://localhost:3000/api/orders/1035625630
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders/1035625630/shipments
# create new shipment for order (assumes you know shipping method id - no inventory units)
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders?search[number]=R664048424 --globoff -i
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6"
http://localhost:3000/api/orders/1035625630
curl -H "Content-Type:application/json" -H "Accept:application/json" -H "X-SpreeAPIKey: 164472af75abf6bb02a7b83ff1bed852852252b6" http://localhost:3000/api/orders/1035625630/shipments
# create new shipment for order (assumes you know shipping method id - no inventory units)
Shipment.class_eval do
def editable_by?(user)
%w(pending ready_to_ship unable_to_ship needs_fulfilment).include?(state) or user.has_role?(:admin)
end
Shipment.state_machines[:state] = StateMachine::Machine.new(Shipment, :initial => 'pending') do
event :ready do
transition :from => 'pending', :to => 'ready_to_ship'
end
event :pend do