shopify-routes 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +100 -0
- data/Rakefile +2 -0
- data/lib/shopify-routes/version.rb +5 -0
- data/lib/shopify-routes.rb +441 -0
- data/shopify-routes.gemspec +19 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Travis Haynes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Shopify::Routes
|
2
|
+
|
3
|
+
Provides routes that redirect back to Shopify pages.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'shopify-routes'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install shopify-routes
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Adding the routes to your app is dead simple. All you need to do is add a single
|
22
|
+
line of code to your `config/routes.rb` file. However, it's highly recommended
|
23
|
+
that you add your routes to a namespace to prevent conflicts with your
|
24
|
+
application. Here's an example of how to add all the Shopify routes under a
|
25
|
+
`:shopify` namespace:
|
26
|
+
|
27
|
+
namespace :shopify do
|
28
|
+
ShopifyAPI::Routes.draw(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
You can also specify which routes you want to include, or exclude, as you would
|
32
|
+
normally with a Rails resource:
|
33
|
+
|
34
|
+
ShopifyAPI::Routes.draw self, only: [ :orders, :products ]
|
35
|
+
ShopifyAPI::Routes.draw self, except: [ :articles, :blogs ]
|
36
|
+
|
37
|
+
To include a referrer ID for the `:signup` and `:brochure` pages, add a
|
38
|
+
`:referrer` option to the routes:
|
39
|
+
|
40
|
+
ShopifyAPI::Routes.draw self, :referrer => "travishaynes"
|
41
|
+
|
42
|
+
The above example would route `shopify_brochure_path` to
|
43
|
+
[http://www.shopify.com?ref=travishaynes](http://www.shopify.com?ref=travishaynes),
|
44
|
+
and `shopify_signup_path` to
|
45
|
+
[https://app.shopify.com/services/signup?ref=travishaynes](https://app.shopify.com/services/signup?ref=travishaynes).
|
46
|
+
|
47
|
+
## Routes
|
48
|
+
|
49
|
+
Here's a list of all the routes that will be added to your app, outside of any
|
50
|
+
namespace to keep things simple.
|
51
|
+
|
52
|
+
brochure /
|
53
|
+
signup /signup(.:format)
|
54
|
+
admin /:shop/admin(.:format)
|
55
|
+
orders /:shop/admin/orders(.:format)
|
56
|
+
order /:shop/admin/orders/:id(.:format)
|
57
|
+
customers /:shop/admin/customers(.:format)
|
58
|
+
customer /:shop/admin/customers/:id(.:format)
|
59
|
+
new_customer /:shop/admin/customers/new(.:format)
|
60
|
+
products /:shop/admin/products(.:format)
|
61
|
+
product /:shop/admin/products/:id(.:format)
|
62
|
+
new_product /:shop/admin/products/new(.:format)
|
63
|
+
custom_collections /:shop/admin/custom_collections(.:format)
|
64
|
+
custom_collection /:shop/admin/custom_collections/:id(.:format)
|
65
|
+
new_custom_collection /:shop/admin/custom_collections/new(.:format)
|
66
|
+
smart_collections /:shop/admin/smart_collections(.:format)
|
67
|
+
smart_collection /:shop/admin/smart_collections/:id(.:format)
|
68
|
+
new_smart_collection /:shop/admin/smart_collections/new(.:format)
|
69
|
+
pages /:shop/admin/pages(.:format)
|
70
|
+
page /:shop/admin/pages/:id(.:format)
|
71
|
+
new_page /:shop/admin/pages/new(.:format)
|
72
|
+
blogs /:shop/admin/blogs(.:format)
|
73
|
+
blog /:shop/admin/blogs/:id(.:format)
|
74
|
+
new_blog /:shop/admin/blogs/new(.:format)
|
75
|
+
navigation /:shop/admin/links(.:format)
|
76
|
+
promotions /:shop/admin/marketing(.:format)
|
77
|
+
themes /:shop/admin/themes(.:format)
|
78
|
+
theme /:shop/admin/themes/:id(.:format)
|
79
|
+
theme_settings /:shop/admin/themes:id/settings(.:format)
|
80
|
+
general_settings /:shop/admin/general_preferences(.:format)
|
81
|
+
regions /:shop/admin/countries(.:format)
|
82
|
+
region /:shop/admin/countries/:id(.:format)
|
83
|
+
new_region /:shop/admin/countries/new(.:format)
|
84
|
+
checkout_and_payment /:shop/admin/payments(.:format)
|
85
|
+
shipping_rates /:shop/admin/shipping(.:format)
|
86
|
+
weight_based_shipping_rate /:shop/admin/weight_based_shipping_rates/:id(.:format)
|
87
|
+
price_based_shipping_rate /:shop/admin/price_based_shipping_rates/:id(.:format)
|
88
|
+
fulfillment_services /:shop/admin/fulfillment_services(.:format)
|
89
|
+
notifications /:shop/admin/notifications(.:format)
|
90
|
+
notification /:shop/admin/notifications/:id(.:format)
|
91
|
+
domains /:shop/admin/domains(.:format)
|
92
|
+
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork it
|
97
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
98
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
99
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
100
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,441 @@
|
|
1
|
+
require 'shopify_api'
|
2
|
+
|
3
|
+
module ShopifyAPI
|
4
|
+
class << self
|
5
|
+
# use this in your `config/routes.rb` file to draw the Shopify routes
|
6
|
+
# @param [ActionDispatch::Routing::RouteSet] router The router
|
7
|
+
# @param [Hash] options The options for drawing the routes
|
8
|
+
# @option options [String] :referrer Your Shopify Partner referrer ID
|
9
|
+
# @option options [Array] :only An Array of resources to included in the routes
|
10
|
+
# @option options [Array] :except An Array of resources to exclude from the routes
|
11
|
+
# @example Draw all the Shopify routes
|
12
|
+
# MyApp::Application.routes.draw do
|
13
|
+
# ShopifyAPI::Routes.draw(self)
|
14
|
+
# end
|
15
|
+
# @example Drawing only the Products and Orders routes
|
16
|
+
# MyApp::Application.routes.draw do
|
17
|
+
# ShopifyAPI::Routes.draw self, only: [:products, :orders]
|
18
|
+
# end
|
19
|
+
# @example Drawing every route except for :custom_collections
|
20
|
+
# MyApp::Application.routes.draw do
|
21
|
+
# ShopifyAPI::Routes.draw self, except: [:custom_collections]
|
22
|
+
# end
|
23
|
+
# @example Including a referrer ID
|
24
|
+
# MyApp::Application.routes.draw do
|
25
|
+
# ShopifyAPI::Routes.draw self, referrer: "travishaynes"
|
26
|
+
# end
|
27
|
+
# @api public
|
28
|
+
def routes(router, options = {})
|
29
|
+
# cache the router
|
30
|
+
@router = router
|
31
|
+
|
32
|
+
# extract the referrer from the options, if it's included
|
33
|
+
@ref = "?ref=#{options[:referrer]}" if options.include? :referrer
|
34
|
+
|
35
|
+
# default namespace
|
36
|
+
options[:namespace] ||= :shopify
|
37
|
+
|
38
|
+
# extract the :only, or :except options, if they're included
|
39
|
+
@only = Array(options[:only]) if options.include?(:only)
|
40
|
+
@except = Array(options[:except]) if options.include?(:except)
|
41
|
+
|
42
|
+
# draw the routes
|
43
|
+
draw
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# ensures a shop domain is suffixed with ".myshopify.com"
|
49
|
+
# @param [String] shop The shop's domain, with or without ".myshopify.com"
|
50
|
+
# @return [String] The shop's domain with ".myshopify.com"
|
51
|
+
# @api private
|
52
|
+
def shop_domain(shop)
|
53
|
+
shop =~ /.*myshopify\.com/ ? shop : shop + ".myshopify.com"
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# draws a route for the given path, actions and alias
|
58
|
+
# @param [String] path The path for the route
|
59
|
+
# @param [Array] actions List of actions to draw for this route
|
60
|
+
# @param [String] nom Alias for the route if the path name does not suffice
|
61
|
+
# @api private
|
62
|
+
def match(path, actions, nom = path)
|
63
|
+
|
64
|
+
# only draw this route if it's included
|
65
|
+
return unless include?(path)
|
66
|
+
|
67
|
+
actions.each do |action|
|
68
|
+
|
69
|
+
# create the route, and it's name
|
70
|
+
route = ":shop/admin/#{path.to_s}"
|
71
|
+
name = nom.to_s
|
72
|
+
|
73
|
+
case action
|
74
|
+
|
75
|
+
# route for show
|
76
|
+
when :show
|
77
|
+
route << "/:id"
|
78
|
+
name = name.singularize
|
79
|
+
|
80
|
+
# route for new
|
81
|
+
when :new
|
82
|
+
route << "/new"
|
83
|
+
name = "new_#{name.singularize}"
|
84
|
+
|
85
|
+
# custom routes
|
86
|
+
else
|
87
|
+
unless action == :index
|
88
|
+
route << action
|
89
|
+
action = ""
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# draw the route
|
94
|
+
match_admin_path(
|
95
|
+
route => name,
|
96
|
+
:action => action,
|
97
|
+
:controller => "shopify_#{nom.to_s.pluralize}"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
# generates a path to a resource in the Shopify namespace
|
105
|
+
# @param [String] path The path to match
|
106
|
+
# @param [String] resource The name of the resource - plural or singular
|
107
|
+
# @param [ActionDispatch::Routing::RouteSet] The router to add the matches
|
108
|
+
# @api private
|
109
|
+
def match_admin_path(options = {})
|
110
|
+
|
111
|
+
# use the router from the options, or the cached one
|
112
|
+
router = options[:router] || @router
|
113
|
+
|
114
|
+
# get the path and resource
|
115
|
+
path, resource = options.first
|
116
|
+
|
117
|
+
# default to using the resource for the named route
|
118
|
+
options[:as] ||= resource
|
119
|
+
|
120
|
+
# generate the match route
|
121
|
+
router.match path => router.redirect { |params, r|
|
122
|
+
|
123
|
+
# ensure the ".myshopify.com" suffix exists
|
124
|
+
shop = shop_domain(params[:shop])
|
125
|
+
|
126
|
+
# path to the shop's admin resource
|
127
|
+
uri = "https://#{shop}/admin/#{resource}"
|
128
|
+
|
129
|
+
# check if we need to include an id
|
130
|
+
uri << "/#{params[:id]}" if params.include?(:id)
|
131
|
+
|
132
|
+
# return the redirect URI
|
133
|
+
uri
|
134
|
+
},
|
135
|
+
|
136
|
+
:as => options[:as],
|
137
|
+
:action => options[:action],
|
138
|
+
:controller => options[:controller]
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
# checks if a resource should be included in the routes
|
144
|
+
# @param [Symbol] name The name of the resource
|
145
|
+
# @return [Boolean] true when it should be included
|
146
|
+
# @api private
|
147
|
+
def include?(name)
|
148
|
+
(@only.nil? && @except.nil?) ||
|
149
|
+
(!@only.nil? && @only.include?(name)) ||
|
150
|
+
(!@except.nil? && !@except.include?(name))
|
151
|
+
end
|
152
|
+
|
153
|
+
|
154
|
+
# draws the Shopify routes
|
155
|
+
# @param [ActionDispatch::Routing::RouteSet] r The router
|
156
|
+
# @api private
|
157
|
+
def draw(r = @router)
|
158
|
+
|
159
|
+
if include?(:brochure)
|
160
|
+
# route to the Shopify brochure path
|
161
|
+
brochure_path = "http://www.shopify.com#{@ref}"
|
162
|
+
r.match(
|
163
|
+
"/" => r.redirect(brochure_path),
|
164
|
+
:as => "brochure",
|
165
|
+
:controller => "shopify",
|
166
|
+
:action => "index"
|
167
|
+
)
|
168
|
+
end
|
169
|
+
|
170
|
+
if include?(:signup)
|
171
|
+
# route to the Shopify sign up path
|
172
|
+
signup_path = "https://app.shopify.com/services/signup#{@ref}"
|
173
|
+
r.match(
|
174
|
+
"signup" => r.redirect(signup_path),
|
175
|
+
:as => "signup",
|
176
|
+
:controller => "shopify",
|
177
|
+
:action => "signup"
|
178
|
+
)
|
179
|
+
end
|
180
|
+
|
181
|
+
if include?(:admin)
|
182
|
+
# route to a shop's admin path
|
183
|
+
r.match ":shop/admin" => r.redirect { |p,r|
|
184
|
+
"https://#{p[:shop]}.myshopify.com/admin"
|
185
|
+
},
|
186
|
+
:as => "admin",
|
187
|
+
:controller => "shopify_admin",
|
188
|
+
:action => "index"
|
189
|
+
end
|
190
|
+
|
191
|
+
# draw the routes
|
192
|
+
match :orders, [:index, :show]
|
193
|
+
match :customers, [:index, :show, :new]
|
194
|
+
match :products, [:index, :show, :new]
|
195
|
+
match :custom_collections, [:index, :show, :new]
|
196
|
+
match :smart_collections, [:index, :show, :new]
|
197
|
+
match :pages, [:index, :show, :new]
|
198
|
+
match :blogs, [:index, :show, :new]
|
199
|
+
match :links, [:index], "navigation"
|
200
|
+
match :marketing, [:index], "promotions"
|
201
|
+
match :themes, [:index, :show]
|
202
|
+
match :themes, [":id/settings"], "theme_settings"
|
203
|
+
match :general_preferences, [:index], "general_settings"
|
204
|
+
match :countries, [:index, :show, :new], "regions"
|
205
|
+
match :payments, [:index], "checkout_and_payment"
|
206
|
+
match :shipping, [:index], "shipping_rates"
|
207
|
+
match :weight_based_shipping_rates, [:show]
|
208
|
+
match :price_based_shipping_rates, [:show]
|
209
|
+
match :fulfillment_services, [:index]
|
210
|
+
match :notifications, [:index, :show]
|
211
|
+
match :domains, [:index]
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
module ShopifyAPI
|
218
|
+
class Routes
|
219
|
+
class << self
|
220
|
+
# use this in your `config/routes.rb` file to draw the Shopify routes
|
221
|
+
# @param [ActionDispatch::Routing::RouteSet] router The router
|
222
|
+
# @param [Hash] options The options for drawing the routes
|
223
|
+
# @option options [String] :referrer Your Shopify Partner referrer ID
|
224
|
+
# @option options [Array] :only An Array of resources to included in the routes
|
225
|
+
# @option options [Array] :except An Array of resources to exclude from the routes
|
226
|
+
# @example Draw all the Shopify routes
|
227
|
+
# MyApp::Application.routes.draw do
|
228
|
+
# ShopifyAPI::Routes.draw(self)
|
229
|
+
# end
|
230
|
+
# @example Drawing only the Products and Orders routes
|
231
|
+
# MyApp::Application.routes.draw do
|
232
|
+
# ShopifyAPI::Routes.draw self, only: [:products, :orders]
|
233
|
+
# end
|
234
|
+
# @example Drawing every route except for :custom_collections
|
235
|
+
# MyApp::Application.routes.draw do
|
236
|
+
# ShopifyAPI::Routes.draw self, except: [:custom_collections]
|
237
|
+
# end
|
238
|
+
# @example Including a referrer ID
|
239
|
+
# MyApp::Application.routes.draw do
|
240
|
+
# ShopifyAPI::Routes.draw self, referrer: "travishaynes"
|
241
|
+
# end
|
242
|
+
# @api public
|
243
|
+
def routes(router, options = {})
|
244
|
+
# cache the router
|
245
|
+
@router = router
|
246
|
+
|
247
|
+
# extract the referrer from the options, if it's included
|
248
|
+
@ref = "?ref=#{options[:referrer]}" if options.include? :referrer
|
249
|
+
|
250
|
+
# default namespace
|
251
|
+
options[:namespace] ||= :shopify
|
252
|
+
|
253
|
+
# extract the :only, or :except options, if they're included
|
254
|
+
@only = Array(options[:only]) if options.include?(:only)
|
255
|
+
@except = Array(options[:except]) if options.include?(:except)
|
256
|
+
|
257
|
+
# draw the routes
|
258
|
+
draw
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
# ensures a shop domain is suffixed with ".myshopify.com"
|
263
|
+
# @param [String] shop The shop's domain, with or without ".myshopify.com"
|
264
|
+
# @return [String] The shop's domain with ".myshopify.com"
|
265
|
+
# @api private
|
266
|
+
def shop_domain(shop)
|
267
|
+
shop =~ /.*myshopify\.com/ ? shop : shop + ".myshopify.com"
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
# generates a path to a resource in the Shopify namespace
|
272
|
+
# @param [String] path The path to match
|
273
|
+
# @param [String] resource The name of the resource - plural or singular
|
274
|
+
# @param [ActionDispatch::Routing::RouteSet] The router to add the matches
|
275
|
+
# @api private
|
276
|
+
def match_admin_path(options = {})
|
277
|
+
|
278
|
+
# use the router from the options, or the cached one
|
279
|
+
router = options[:router] || @router
|
280
|
+
|
281
|
+
# get the path and resource
|
282
|
+
path, resource = options.first
|
283
|
+
|
284
|
+
# generate the match route
|
285
|
+
router.match path => router.redirect { |params, r|
|
286
|
+
|
287
|
+
# ensure the ".myshopify.com" suffix exists
|
288
|
+
shop = shop_domain(params[:shop])
|
289
|
+
|
290
|
+
# path to the shop's admin resource
|
291
|
+
uri = "https://#{shop}/admin/#{resource}"
|
292
|
+
|
293
|
+
# check if we need to include an id
|
294
|
+
uri << "/#{params[:id]}" if params.include?(:id)
|
295
|
+
|
296
|
+
# return the redirect URI
|
297
|
+
uri
|
298
|
+
},
|
299
|
+
|
300
|
+
:as => options[:as]
|
301
|
+
|
302
|
+
end
|
303
|
+
|
304
|
+
|
305
|
+
# parses the options for the resource and resources methods
|
306
|
+
# @param [Hash] options The options Hash to parse
|
307
|
+
# @option options [String] :resource The name of the resource
|
308
|
+
# @option options [ActionDispatch::Routing::RouteSet] :router The router
|
309
|
+
# @api private
|
310
|
+
def resource_options(name)
|
311
|
+
name = name.to_s
|
312
|
+
|
313
|
+
{
|
314
|
+
:router => @router ||= options[:router],
|
315
|
+
:plural => name.pluralize,
|
316
|
+
:singular => name.singularize,
|
317
|
+
:route => ":shop/admin/#{name.pluralize}"
|
318
|
+
}
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
# creates a singular match path for a resource
|
323
|
+
# @param [Hash] options The options for this resource.
|
324
|
+
# @option options [String] :resource The name of the resource
|
325
|
+
# @option options [ActionDispatch::Routing::RouteSet] :router The router
|
326
|
+
# @api private
|
327
|
+
def resource(name)
|
328
|
+
options = resource_options(name)
|
329
|
+
path = options[:route]
|
330
|
+
resource = options[:plural]
|
331
|
+
match_admin_path path => resource, as: resource
|
332
|
+
options
|
333
|
+
end
|
334
|
+
|
335
|
+
|
336
|
+
# creates a plural match path for a resource
|
337
|
+
# @param [Hash] options The options for this resource.
|
338
|
+
# @option options [String] :resource The name of the resource
|
339
|
+
# @option options [ActionDispatch::Routing::RouteSet] :router The router
|
340
|
+
# @api private
|
341
|
+
def resources(name)
|
342
|
+
# draw the singular resource to go with this resource
|
343
|
+
options = resource(name)
|
344
|
+
|
345
|
+
# route for the resource by its ID
|
346
|
+
path = "#{options[:route]}/:id"
|
347
|
+
resource = options[:singular]
|
348
|
+
match_admin_path path => resource, as: resource
|
349
|
+
|
350
|
+
# route for a new resource
|
351
|
+
path = "#{options[:route]}/new"
|
352
|
+
resource = "new_#{options[:singular]}"
|
353
|
+
match_admin_path path => resource, as: resource
|
354
|
+
|
355
|
+
options
|
356
|
+
end
|
357
|
+
|
358
|
+
|
359
|
+
# checks if a resource should be included in the routes
|
360
|
+
# @param [Symbol] name The name of the resource
|
361
|
+
# @return [Boolean] true when it should be included
|
362
|
+
# @api private
|
363
|
+
def include?(name)
|
364
|
+
(@only.nil? && @except.nil?) ||
|
365
|
+
(!@only.nil? && @only.include?(name)) ||
|
366
|
+
(!@except.nil? && !@except.include?(name))
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
# draws the Shopify routes
|
371
|
+
# @param [ActionDispatch::Routing::RouteSet] r The router
|
372
|
+
# @api private
|
373
|
+
def draw(r = @router)
|
374
|
+
|
375
|
+
if include?(:brochure)
|
376
|
+
# route to the Shopify brochure path
|
377
|
+
brochure_path = "http://www.shopify.com#{@ref}"
|
378
|
+
r.match "/" => r.redirect(brochure_path), as: "brochure"
|
379
|
+
end
|
380
|
+
|
381
|
+
if include?(:signup)
|
382
|
+
# route to the Shopify sign up path
|
383
|
+
signup_path = "https://app.shopify.com/services/signup#{@ref}"
|
384
|
+
r.match "signup" => r.redirect(signup_path), as: "signup"
|
385
|
+
end
|
386
|
+
|
387
|
+
if include?(:admin)
|
388
|
+
# route to a shop's admin path
|
389
|
+
r.match ":shop/admin" => r.redirect { |p,r|
|
390
|
+
"https://#{p[:shop]}.myshopify.com/admin"
|
391
|
+
}, as: "admin"
|
392
|
+
end
|
393
|
+
|
394
|
+
# draw the routes
|
395
|
+
match :orders, [:index, :show]
|
396
|
+
match :customers, [:index, :show, :new]
|
397
|
+
match :products, [:index, :show, :new]
|
398
|
+
match :custom_collections, [:index, :show, :new]
|
399
|
+
match :smart_collections, [:index, :show, :new]
|
400
|
+
match :pages, [:index, :show, :new]
|
401
|
+
match :blogs, [:index, :show, :new]
|
402
|
+
match :links, [:index], "navigation"
|
403
|
+
match :marketing, [:index], "promotions"
|
404
|
+
match :themes, [:index, :show]
|
405
|
+
match :themes, [":id/settings"], "theme_settings"
|
406
|
+
match :general_preferences, [:index], "general_settings"
|
407
|
+
match :countries, [:index, :show, :new], "regions"
|
408
|
+
match :payments, [:index], "checkout_and_payment"
|
409
|
+
match :shipping, [:index], "shipping_rates"
|
410
|
+
match :weight_based_shipping_rates, [:show]
|
411
|
+
match :price_based_shipping_rates, [:show]
|
412
|
+
match :fulfillment_services, [:index]
|
413
|
+
match :notifications, [:index, :show]
|
414
|
+
match :domains, [:index]
|
415
|
+
end
|
416
|
+
|
417
|
+
end
|
418
|
+
|
419
|
+
def match(path, actions, nom = path)
|
420
|
+
|
421
|
+
actions.each do |action|
|
422
|
+
|
423
|
+
route = ":shop/admin/#{path.to_s}"
|
424
|
+
|
425
|
+
case action
|
426
|
+
when :show
|
427
|
+
route << "/:id"
|
428
|
+
when :new
|
429
|
+
route << "/new"
|
430
|
+
else
|
431
|
+
route << action unless action == :index
|
432
|
+
end
|
433
|
+
|
434
|
+
match_admin_path route => path.to_s, as: nom
|
435
|
+
end
|
436
|
+
|
437
|
+
end
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/shopify-routes/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Travis Haynes"]
|
6
|
+
gem.email = ["travis.j.haynes@gmail.com"]
|
7
|
+
gem.description = "Provides routes that redirect back to Shopify pages."
|
8
|
+
gem.summary = "Provides routes that redirect back to Shopify pages."
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "shopify-routes"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = "0.0.1"
|
17
|
+
|
18
|
+
gem.add_runtime_dependency "shopify_api", ">= 3.0.0"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shopify-routes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Travis Haynes
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: shopify_api
|
16
|
+
requirement: &13651460 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *13651460
|
25
|
+
description: Provides routes that redirect back to Shopify pages.
|
26
|
+
email:
|
27
|
+
- travis.j.haynes@gmail.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/shopify-routes.rb
|
38
|
+
- lib/shopify-routes/version.rb
|
39
|
+
- shopify-routes.gemspec
|
40
|
+
homepage: ''
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.10
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Provides routes that redirect back to Shopify pages.
|
64
|
+
test_files: []
|
65
|
+
has_rdoc:
|