shopify-routes 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Shopify::Routes
1
+ # Shopify.routes
2
2
 
3
3
  Provides routes that redirect back to Shopify pages.
4
4
 
@@ -24,8 +24,10 @@ that you add your routes to a namespace to prevent conflicts with your
24
24
  application. Here's an example of how to add all the Shopify routes under a
25
25
  `:shopify` namespace:
26
26
 
27
- namespace :shopify do
28
- ShopifyAPI::Routes.draw(self)
27
+ MyApp::Application.routes.draw do
28
+ namespace :shopify do
29
+ ShopifyAPI::Routes.draw(self)
30
+ end
29
31
  end
30
32
 
31
33
  You can also specify which routes you want to include, or exclude, as you would
@@ -46,12 +48,22 @@ and `shopify_signup_path` to
46
48
 
47
49
  ## Routes
48
50
 
51
+ For all except the brochure and signup pages, you'll have to include the shop's
52
+ domain in the url helper. For example:
53
+
54
+ orders_url(:shop => "my-shopify-domain")
55
+
56
+ Or for redirecting to a specific order:
57
+
58
+ orders_url(:shop => "my-shopify-domain", :id => 1001)
59
+
49
60
  Here's a list of all the routes that will be added to your app, outside of any
50
61
  namespace to keep things simple.
51
62
 
52
63
  brochure /
53
64
  signup /signup(.:format)
54
65
  admin /:shop/admin(.:format)
66
+ applications /:shop/admin/applications(.:format)
55
67
  orders /:shop/admin/orders(.:format)
56
68
  order /:shop/admin/orders/:id(.:format)
57
69
  customers /:shop/admin/customers(.:format)
@@ -189,6 +189,7 @@ module ShopifyAPI
189
189
  end
190
190
 
191
191
  # draw the routes
192
+ match :applications, [:index]
192
193
  match :orders, [:index, :show]
193
194
  match :customers, [:index, :show, :new]
194
195
  match :products, [:index, :show, :new]
@@ -212,230 +213,3 @@ module ShopifyAPI
212
213
  end
213
214
  end
214
215
  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
@@ -1,5 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/shopify-routes/version', __FILE__)
3
2
 
4
3
  Gem::Specification.new do |gem|
5
4
  gem.authors = ["Travis Haynes"]
@@ -13,7 +12,7 @@ Gem::Specification.new do |gem|
13
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
13
  gem.name = "shopify-routes"
15
14
  gem.require_paths = ["lib"]
16
- gem.version = "0.0.1"
15
+ gem.version = "0.0.2"
17
16
 
18
17
  gem.add_runtime_dependency "shopify_api", ">= 3.0.0"
19
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify-routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shopify_api
16
- requirement: &13651460 !ruby/object:Gem::Requirement
16
+ requirement: &13236360 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13651460
24
+ version_requirements: *13236360
25
25
  description: Provides routes that redirect back to Shopify pages.
26
26
  email:
27
27
  - travis.j.haynes@gmail.com
@@ -35,7 +35,6 @@ files:
35
35
  - README.md
36
36
  - Rakefile
37
37
  - lib/shopify-routes.rb
38
- - lib/shopify-routes/version.rb
39
38
  - shopify-routes.gemspec
40
39
  homepage: ''
41
40
  licenses: []
@@ -1,5 +0,0 @@
1
- module ShopifyAPI
2
- module Routes
3
- VERSION = "0.0.1"
4
- end
5
- end