Note: This project is currently under development!
Reduce those unnecessary API calls!!
ShopifyProductSink is a Rails engine to simplify working with Shopify by keeping a shops products synchronized with a local copy.
- Provides functionality to import products from Shopify
- Provides an import helper which can do all the heavy lifting of pulling in products
- Provides a simple way to register webhooks for product changes
- Provides a module that can be included to take care of all the "boring" parts of webhook verification
- Provide a default webhooks controller that will do basic product synchronization
- Do proper shop scoping since right now there isn't any and there could possibly be some data leakage
- Refactor API createable integration objects such that them and their migrations aren't imported when the engine is installed
- Remove all CSS and JavaScript since it's not actually needed for this engine to work whatsoever
Right now I have no idea what I'm doing when it comes to engines, so I'm just speccing the docs based on the hooking into an application section on the Rails Guides
Until I get a rubygem setup you'll need to link right to the github repository in your Gemfile:
gem 'shop_product_sink', git: 'https://github.com/csaunders/shopProductSink'
Mount the application in your routes file:
mount ShopProductSink::Engine, at: "product_sink"
Install and Run the migrations:
rake shop_product_sink:install:migrations
rake db:migrate SCOPE=shop_product_sink
The engine comes with two utility functions that make it easier to integrate product synchronization into your app.
# Partner App Initialization
importer = ShopProductSink::Importers::Product.new(
shop: 'yourshop.myshopify.com',
token: 'abracadabra'
)
importer.import
# Alternative -- Private App Initialization
importer = ShopProductSink::Importers::Product.new(
site: 'https://apikey:password@yourshop.myshopify.com/admin'
)
importer.import
Secondly it comes with a utility to make registering webhooks easier. There are a few catches if you want to have it be more automated. There are routes setup for an included Webhooks Controller that you can leverage if you don't want to handle validating webhooks on your own.
1. Setup your applications default host
# application.rb
Rails.application.routes.default_url_options[:host] = "your.domain.tld"
2. In an initializer let the ShopProductSink::WebhooksController
know how to find
a single shop based on it's shopify domain
# config/initializers/shop_product_sink.rb
ShopProductSink::WebhooksController.shop_retrieval_strategy = -> (shopify_domain) {
Shop.where(domain: shopify_domain).first
}
3. Include your Application Secret in your ENV
You should probably be doing this already anyway since it's good practice. The only problem is you are somewhat forced onto a naming convention for at least one of your API variables.
The variable that needs to be set in your environment is SHOPIFY_API_SECRET
4. Register to receive Product change webhooks whenever it is necessary
ShopProductSink::WebhookRegistration.register(
shop: 'yourshop.myshopify.com',
token: 'abracadabra'
)
You don't have to!!!
If you want you can create your own webhooks handler and just include the ShopProductSink::Webhooks
module in it.
You are required to do a few things if you use this:
- Set the
shop_retrieval_strategy
- Implement
application_secret