Module: ShopifyAPI

Defined in:
lib/shopify-routes.rb

Class Method Summary collapse

Class Method Details

.routes(router, options = {}) ⇒ Object

use this in your ‘config/routes.rb` file to draw the Shopify routes

Examples:

Draw all the Shopify routes

MyApp::Application.routes.draw do
  ShopifyAPI::Routes.draw(self)
end

Drawing only the Products and Orders routes

MyApp::Application.routes.draw do
  ShopifyAPI::Routes.draw self, only: [:products, :orders]
end

Drawing every route except for :custom_collections

MyApp::Application.routes.draw do
  ShopifyAPI::Routes.draw self, except: [:custom_collections]
end

Including a referrer ID

MyApp::Application.routes.draw do
  ShopifyAPI::Routes.draw self, referrer: "travishaynes"
end

Parameters:

  • router (ActionDispatch::Routing::RouteSet)

    The router

  • options (Hash) (defaults to: {})

    The options for drawing the routes

Options Hash (options):

  • :referrer (String)

    Your Shopify Partner referrer ID

  • :only (Array)

    An Array of resources to included in the routes

  • :except (Array)

    An Array of resources to exclude from the routes



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shopify-routes.rb', line 28

def routes(router, options = {})
  # cache the router
  @router = router

  # extract the referrer from the options, if it's included
  @ref = "?ref=#{options[:referrer]}" if options.include? :referrer

  # default namespace
  options[:namespace] ||= :shopify

  # extract the :only, or :except options, if they're included
  @only = Array(options[:only]) if options.include?(:only)
  @except = Array(options[:except]) if options.include?(:except)

  # draw the routes
  draw
end