Skip to content

Instantly share code, notes, and snippets.

View csaunders's full-sized avatar

Christopher Saunders csaunders

View GitHub Profile
@csaunders
csaunders / migration_guide.md
Last active August 29, 2015 13:57
Metafield Migration Guide

It was brought to our attention that the integer value type in our metafields API wasn't working the way you'd expect and required weird hacks in liquid such as {{ metafield.value | plus: 0}} to coerce the values back into integers. This was anything but desirable and we wanted to correct this discrepancy. There were some side-effects that came out of this which were accidental.

This change fixes the way the Shopify Metafield API behaves. According to the documentation two value_types are supported, string and integer though the integer value wasn't being respected and was simply just a string.

With the changes that have been deployed; if your field was an set to an integer value_type it will be properly coereced into the data-type you are expecting. Though if you were using the field incorrectly such as storing `"some string dat

@csaunders
csaunders / studeldoodle.rb
Created February 3, 2014 20:58
doodleldoeldodleo
module Doodle
class Poodle
end
end
module Strudel
module Doodle
class Fancy
def new_poodle
def request(data, hmac=nil)
options = {
:method => 'POST',
:input => data,
'X-Shopify-Hmac-SHA256' => hmac || calculate_hmac(data)
}
ActionDispatch::Request.new(Rack::MockRequest.env_for("", options))
end
@csaunders
csaunders / import_action.rb
Created January 18, 2014 17:30
Application code that is needed to do an API import into your local database
class Importer
def import
api_products = ShopifyAPI::Product.find(:all)
ShopProductSink::Product.create_from_resources(api_products)
end
end
module ShopProductSink
module ApiCreatable
extend ActiveSupport::Concern
module ClassMethods
def initialize_from_resource(resource)
attributes = usable_keys.reduce({}) do |result, key|
result[key] = resource.public_send(key) if resource.respond_to?(key)
result
end
@csaunders
csaunders / simplemath_c.rl
Created January 11, 2014 23:10
Simple Math State Machine
#include <string.h>
#include <stdio.h>
%%{
machine simplemath;
number = digit+;
operator = '+';
main := (digit operator digit) 0 @{ res = 1; };
}%%
diff --git a/.gitignore b/.gitignore
index 8b6632c..2a33328 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@ rdoc
pkg
doc
.yardoc
+.rbenv-version
diff --git a/Gemfile b/Gemfile
require 'openssl'
require 'base64'
class WebhooksController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :verify_webhook, :fetch_shop
def create
case topic
when 'orders/fulfilled'
shops GET /shops(.:format) shops#index => shops_path
POST /shops(.:format) shops#create => shops_path
new_shop GET /shops/new(.:format) shops#new => new_shop_path
edit_shop GET /shops/:id/edit(.:format) shops#edit => edit_shop_path
shop GET /shops/:id(.:format) shops#show => shop_path(shop)
PUT /shops/:id(.:format) shops#update => shop_path(shop)
DELETE /shops/:id(.:format) shops#destroy => shop_path(shop)