shopify_app 6.1.1 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1517b43ed58cca94e285f75dfee44f7d7c8da5e0
4
- data.tar.gz: e3ac5ee6de58727a096360eed00a69aaed41fb26
3
+ metadata.gz: edd2018df13585de884dcef3250e27251cba681c
4
+ data.tar.gz: 0297fb447782e9268f3af28fdede9d30b777f0a5
5
5
  SHA512:
6
- metadata.gz: 39b517aff20a5c0841b8b0f059ed2ee712e4d037f2decaf02564ae517170fcd392c079d69215635315e817654750820d6f42c94bb498fbbf07c9ddc4710b82f2
7
- data.tar.gz: 8bf95bf4467f65cc0c6db5563ecd0e4636223bd79b00db733054c9cb5b42f8dd742e04a5459f66c820bc94ac6040047fcc998dea773c6661967aaddfcfaf9223
6
+ metadata.gz: b52906367f75755913a17b5659d6cb782850386f7e4b23c601a24afb50bddab5e0132f5af93ba8c2a79d052d65cf403fcf228f84873b8ca7b7d475d0aae1328b
7
+ data.tar.gz: 5be95c420bb9a8585e764ced63d38048401a922b2cd1c436d5b0f272318a3ab90a2f1c8caca5e3b70167b1146cc1290fdbb35216d88c9c66c3122ed6b9557e0a
data/README.md CHANGED
@@ -11,6 +11,14 @@ This gem includes some common code and generators for writing Rails applications
11
11
  *Note: It's recommended to use this on a new Rails project, so that the generator won't overwrite/delete some of your files.*
12
12
 
13
13
 
14
+ Quickstart
15
+ ----------
16
+
17
+ Check out this screencast on how to create and deploy a new Shopify App to Heroku in 5 minutes:
18
+
19
+ [https://vimeo.com/130247240](https://vimeo.com/130247240)
20
+
21
+
14
22
  Becoming a Shopify App Developer
15
23
  --------------------------------
16
24
  If you don't have a Shopify Partner account yet head over to http://shopify.com/partners to create one, you'll need it before you can start developing apps.
@@ -143,6 +151,12 @@ ShopifyApp::SessionRepository.storage = 'Shop'
143
151
  If you run the `shop_model` generator it will create the required code to use the generated Shop model as the SessionRepository and update the initializer.
144
152
 
145
153
 
154
+ AuthenticatedController
155
+ -----------------------
156
+
157
+ The engine includes a controller called `AuthenticatedController` which inherits from `ApplicationController`. It adds some before_filters which ensure the user is authenticated and will redirect to the login page if not. It is best practice to have all controllers that belong to the Shopify part of your app inherit from this controller. The HomeController that is generated already inherits from AuthenticatedController.
158
+
159
+
146
160
  Questions or problems?
147
161
  ----------------------
148
162
  http://api.shopify.com <= Read up on the possible API calls!
@@ -0,0 +1,5 @@
1
+ class AuthenticatedController < ApplicationController
2
+ before_action :login_again_if_different_shop
3
+ around_filter :shopify_session
4
+ layout ShopifyApp.configuration.embedded_app? ? 'embedded_app' : 'application'
5
+ end
@@ -10,7 +10,7 @@
10
10
  <form method="GET" action="login">
11
11
  <label>Type shop name:</label>
12
12
  <input type="text" name="shop" placeholder="blabla.myshopify.com"/>
13
- <button type='submit'>Install</buttom>
13
+ <button type='submit'>Install</button>
14
14
  </form>
15
15
 
16
16
  </body>
@@ -1,12 +1,5 @@
1
- class HomeController < ApplicationController
2
- before_action :login_again_if_different_shop
3
- around_filter :shopify_session
4
- <% if embedded_app? -%>
5
- layout 'embedded_app'
6
- <% end -%>
7
-
1
+ class HomeController < AuthenticatedController
8
2
  def index
9
3
  @products = ShopifyAPI::Product.find(:all, :params => {:limit => 10})
10
4
  end
11
-
12
5
  end
@@ -2,10 +2,4 @@
2
2
  ShopifyApp.configuration.api_key,
3
3
  ShopifyApp.configuration.secret,
4
4
 
5
- :scope => ShopifyApp.configuration.scope,
6
-
7
- :setup => lambda {|env|
8
- params = Rack::Utils.parse_query(env['QUERY_STRING'])
9
- site_url = "https://#{params['shop']}"
10
- env['omniauth.strategy'].options[:client_options][:site] = site_url
11
- }
5
+ :scope => ShopifyApp.configuration.scope
@@ -12,8 +12,10 @@ module ShopifyApp
12
12
 
13
13
  def callback
14
14
  if response = request.env['omniauth.auth']
15
- sess = ShopifyAPI::Session.new(params[:shop], response['credentials']['token'])
15
+ shop_name = response.uid
16
+ sess = ShopifyAPI::Session.new(shop_name, response['credentials']['token'])
16
17
  session[:shopify] = ShopifyApp::SessionRepository.store(sess)
18
+ session[:shopify_domain] = shop_name
17
19
  flash[:notice] = "Logged in"
18
20
  redirect_to return_address
19
21
  else
@@ -24,8 +26,8 @@ module ShopifyApp
24
26
 
25
27
  def destroy
26
28
  session[:shopify] = nil
29
+ session[:shopify_domain] = nil
27
30
  flash[:notice] = "Successfully logged out."
28
-
29
31
  redirect_to action: 'new'
30
32
  end
31
33
 
@@ -1,3 +1,3 @@
1
1
  module ShopifyApp
2
- VERSION = "6.1.1"
2
+ VERSION = "6.1.2"
3
3
  end
@@ -73,14 +73,18 @@ class SessionsControllerTest < ActionController::TestCase
73
73
 
74
74
  get :callback, shop: 'shop'
75
75
  assert_not_nil session[:shopify]
76
+ assert_equal 'shop.myshopify.com', session[:shopify_domain]
76
77
  end
77
78
 
78
79
  test "#destroy should clear shopify from session and redirect to login with notice" do
79
80
  shop_id = 1
80
81
  session[:shopify] = shop_id
82
+ session[:shopify_domain] = 'shop1.myshopify.com'
81
83
 
82
84
  get :destroy
85
+
83
86
  assert_nil session[:shopify]
87
+ assert_nil session[:shopify_domain]
84
88
  assert_redirected_to login_path
85
89
  refute flash[:notice].empty?
86
90
  end
@@ -88,7 +92,7 @@ class SessionsControllerTest < ActionController::TestCase
88
92
  private
89
93
 
90
94
  def mock_shopify_omniauth
91
- OmniAuth.config.add_mock(:shopify, provider: :shopify, credentials: {token: '1234'})
95
+ OmniAuth.config.add_mock(:shopify, provider: :shopify, uid: 'shop.myshopify.com', credentials: {token: '1234'})
92
96
  request.env['omniauth.auth'] = OmniAuth.config.mock_auth[:shopify] if request
93
97
  request.env['omniauth.params'] = { shop: 'shop.myshopify.com' } if request
94
98
  end
@@ -0,0 +1,16 @@
1
+ require 'test_helper'
2
+ require 'generators/shopify_app/controllers/controllers_generator'
3
+
4
+ class ControllersGeneratorTest < Rails::Generators::TestCase
5
+ tests ShopifyApp::Generators::ControllersGenerator
6
+ destination File.expand_path("../tmp", File.dirname(__FILE__))
7
+ setup :prepare_destination
8
+
9
+ test "copies ShopifyApp controllers to the host application" do
10
+ run_generator
11
+ assert_directory "app/controllers"
12
+ assert_file "app/controllers/sessions_controller.rb"
13
+ assert_file "app/controllers/authenticated_controller.rb"
14
+ end
15
+
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.1
4
+ version: 6.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-27 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -142,6 +142,7 @@ files:
142
142
  - README.md
143
143
  - RELEASING
144
144
  - Rakefile
145
+ - app/controllers/authenticated_controller.rb
145
146
  - app/controllers/sessions_controller.rb
146
147
  - app/views/sessions/new.html.erb
147
148
  - config/routes.rb
@@ -195,6 +196,7 @@ files:
195
196
  - test/dummy/config/initializers/shopify_app.rb
196
197
  - test/dummy/config/routes.rb
197
198
  - test/dummy/config/secrets.yml
199
+ - test/generators/controllers_generator_test.rb
198
200
  - test/generators/install_generator_test.rb
199
201
  - test/generators/routes_generator_test.rb
200
202
  - test/generators/shop_model_generator_test.rb