This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a product id, and a map of variant ids and quantities | |
def update_inventory(id, vid_quantities) | |
variants = vid_quantities.map do |vid, qty| | |
{ "id" => vid, "inventory_quantity" => qty } | |
end | |
data = { | |
"product" => { | |
"variants" => variants | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> Shopify.request(:get, "products.json?fields=id,title") | |
=> {"products"=>[{"id"=>2938468037, "title"=>"Ghostbusters Inflatable Stay Puft Marshmallow Man Costume"}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Obtained credit - credits remaining: 39 | |
Obtained credit - credits remaining: 38 | |
Obtained credit - credits remaining: 37 | |
Obtained credit - credits remaining: 36 | |
Obtained credit - credits remaining: 35 | |
Obtained credit - credits remaining: 34 | |
Obtained credit - credits remaining: 33 | |
Obtained credit - credits remaining: 32 | |
Obtained credit - credits remaining: 31 | |
Obtained credit - credits remaining: 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run 42 threads to hit the call limit | |
42.times.each do | |
Thread.new { Shopify.get_product(1234567890) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use a shared lock and credits_remaining | |
@lock = Mutex.new | |
@credits_remaining = 40 | |
@shopify_url = ENV["SHOPIFY_URL"] | |
# Sends a request to Shopify, blocking until credits are available | |
def self.request(method, path, params={}) | |
params[:headers] = {"Content-Type" => "application/json"} | |
# wait for a credit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> response.headers["HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT"] | |
"1/40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup an App namespace for all other Javascript to hook to. | |
var App = {}; | |
// Watch is a utility for hooking into form changes | |
// | |
// Example: | |
// App.Watch.init("#company-filter", function(el){}); | |
App.Watch = (function() { | |
function init(el, handler) { | |
$(el).on("propertychange keyup input paste", function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = App || {}; | |
App.Commentable = function(options) { | |
var options = $.extend({ | |
log_tail: 'is the greatest' | |
}, options); | |
return { | |
log: function(msg) { | |
console.log(msg + ' ' + options.log_tail); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# contains common attachment methods | |
# NOTE: this currently assumes the attachment is called 'attachment' | |
module Attachable | |
# determines if an attachment may have a thumbnail | |
def thumbnailable? | |
!(attachment_content_type =~ %r{^(image|(x-)?application)/(bmp|gif|jpeg|jpg|pjpeg|png|x-png|pdf)$}).nil? | |
end | |
def image_dimensions(max=400) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
#notification-box { | |
position: absolute; | |
top: 25px; left: 0; | |
width: 100%; | |
padding: 0; margin: 0; | |
} | |
</style> | |
<div id="notification-box"> |