shopify_app 4.0.1 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -1
- data/README.rdoc +3 -3
- data/install.rb +1 -1
- data/lib/generators/shopify_app/README +2 -2
- data/lib/generators/shopify_app/USAGE +3 -3
- data/lib/generators/shopify_app/shopify_app_generator.rb +16 -8
- data/lib/generators/shopify_app/templates/app/controllers/home_controller.rb +1 -1
- data/lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb +49 -0
- data/lib/generators/shopify_app/templates/app/views/layouts/application.html.erb +2 -2
- data/lib/generators/shopify_app/templates/app/views/{login/index.html.erb → sessions/new.html.erb} +1 -1
- data/lib/shopify_app/version.rb +1 -1
- data/shopify_app.gemspec +1 -1
- metadata +6 -6
- data/lib/generators/shopify_app/templates/app/controllers/login_controller.rb +0 -44
data/CHANGELOG
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
* re-styled with Twitter Bootstrap css framework and updated docs [warren]
|
2
2
|
* Require shopify_api gem via proper railtie setup [willem]
|
3
3
|
* Don't require shopify.yml when using environment variables [cody]
|
4
|
-
* Renamed instances of current_shop to shop_session to maintain logic
|
4
|
+
* Renamed instances of current_shop to shop_session to maintain logic
|
5
|
+
* Replace old LoginController with a RESTful SessionsController
|
data/README.rdoc
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
This gem makes it easy to get a Rails 3.2 app up and running with the
|
6
6
|
Shopify API.
|
7
7
|
|
8
|
-
The generator creates a basic
|
8
|
+
The generator creates a basic SessionsController for authenticating with your
|
9
9
|
shop and a HomeController which displays basic information about your
|
10
10
|
products, orders and articles.
|
11
11
|
|
@@ -26,8 +26,8 @@ If you don't have an API key yet, create a Shopify Partner account at
|
|
26
26
|
http://shopify.com/partners and create an app. You can also create test shops
|
27
27
|
once you're logged in as a partner.
|
28
28
|
|
29
|
-
When you create your app in the Shopify Partner Account, set the
|
30
|
-
<tt>http://localhost:3000/login
|
29
|
+
When you create your app in the Shopify Partner Account, set the Application URL to
|
30
|
+
<tt>http://localhost:3000/login</tt>
|
31
31
|
|
32
32
|
You can also create a private application that only works for your shop by
|
33
33
|
visiting https://YOUR-SHOP.myshopify.com/admin/api
|
data/install.rb
CHANGED
@@ -7,7 +7,7 @@ puts
|
|
7
7
|
puts " * Go to http://www.shopify.com/partners and create or login to your Partner account."
|
8
8
|
puts
|
9
9
|
puts " * Jump over to the Apps tab and hit the 'Create a new app' button"
|
10
|
-
puts " (Make sure to set the
|
10
|
+
puts " (Make sure to set the Application URL to http://localhost:3000/login during development)"
|
11
11
|
puts
|
12
12
|
puts " * Install the Shopify API gem:
|
13
13
|
|
@@ -3,8 +3,8 @@
|
|
3
3
|
What's next?
|
4
4
|
------------
|
5
5
|
|
6
|
-
Make sure to set the
|
7
|
-
to <tt>http://localhost:3000/login
|
6
|
+
Make sure to set the Application URL of the application in your Shopify partner account
|
7
|
+
to <tt>http://localhost:3000/login</tt>.
|
8
8
|
|
9
9
|
Then, start your application with:
|
10
10
|
|
@@ -2,7 +2,7 @@ Description:
|
|
2
2
|
This is a generator for creating a basic Shopify application to quickly get
|
3
3
|
you started. You can see some examples on how to use the Shopify API.
|
4
4
|
|
5
|
-
The generator creates a basic
|
5
|
+
The generator creates a basic sessions controller for authenticating with your
|
6
6
|
Shop and a controller called "home" which displays basic information
|
7
7
|
about your products, orders and articles.
|
8
8
|
|
@@ -10,7 +10,7 @@ Description:
|
|
10
10
|
generator won't overwrite/delete some of your files.
|
11
11
|
|
12
12
|
Usage:
|
13
|
-
Pass your API key and then your Secret, which the
|
13
|
+
Pass your API key and then your Secret, which the sessions controller
|
14
14
|
will need to authenticate with your shop.
|
15
15
|
If you don't have an API key yet, register your application in our
|
16
16
|
partner system at http://www.shopify.com/partners
|
@@ -19,4 +19,4 @@ Usage:
|
|
19
19
|
Examples:
|
20
20
|
script/generate shopify_app edffbb1bb793e2750686e6f4647a384a abbcee050...
|
21
21
|
|
22
|
-
This will create a
|
22
|
+
This will create a sessions controller and a home controller and views.
|
@@ -40,14 +40,15 @@ class ShopifyAppGenerator < Rails::Generators::Base
|
|
40
40
|
|
41
41
|
def add_routes
|
42
42
|
unless options[:skip_routes]
|
43
|
-
|
44
|
-
route "
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
route "match '
|
43
|
+
route_without_newline "root :to => 'home#index'"
|
44
|
+
route "end"
|
45
|
+
route_without_newline " delete 'logout' => :destroy"
|
46
|
+
route_without_newline " get 'auth/shopify/callback' => :show"
|
47
|
+
route_without_newline " post 'login' => :create"
|
48
|
+
route_without_newline " get 'login' => :new"
|
49
|
+
route_without_newline "controller :sessions do"
|
50
|
+
route "match 'design' => 'home#design'"
|
51
|
+
route_without_newline "match 'welcome' => 'home#welcome'"
|
51
52
|
end
|
52
53
|
end
|
53
54
|
|
@@ -55,4 +56,11 @@ class ShopifyAppGenerator < Rails::Generators::Base
|
|
55
56
|
`bundle install`
|
56
57
|
readme '../README'
|
57
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def route_without_newline(routing_code)
|
63
|
+
sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
|
64
|
+
inject_into_file 'config/routes.rb', "\n #{routing_code}", { after: sentinel, verbose: false }
|
65
|
+
end
|
58
66
|
end
|
@@ -4,7 +4,7 @@ class HomeController < ApplicationController
|
|
4
4
|
|
5
5
|
def welcome
|
6
6
|
current_host = "#{request.host}#{':' + request.port.to_s if request.port != 80}"
|
7
|
-
@callback_url = "http://#{current_host}/login
|
7
|
+
@callback_url = "http://#{current_host}/login"
|
8
8
|
end
|
9
9
|
|
10
10
|
def index
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class SessionsController < ApplicationController
|
2
|
+
def new
|
3
|
+
authenticate if params[:shop].present?
|
4
|
+
end
|
5
|
+
|
6
|
+
def create
|
7
|
+
authenticate
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
if response = request.env['omniauth.auth']
|
12
|
+
sess = ShopifyAPI::Session.new(params[:shop], response[:credentials][:token])
|
13
|
+
session[:shopify] = sess
|
14
|
+
flash[:notice] = "Logged in"
|
15
|
+
redirect_to return_address
|
16
|
+
else
|
17
|
+
flash[:error] = "Could not log in to Shopify store."
|
18
|
+
redirect_to :action => 'new'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
session[:shopify] = nil
|
24
|
+
flash[:notice] = "Successfully logged out."
|
25
|
+
|
26
|
+
redirect_to :action => 'new'
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def authenticate
|
32
|
+
if shop_name = sanitize_shop_param(params)
|
33
|
+
redirect_to "/auth/shopify?shop=#{shop_name}"
|
34
|
+
else
|
35
|
+
redirect_to return_address
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def return_address
|
40
|
+
session[:return_to] || root_url
|
41
|
+
end
|
42
|
+
|
43
|
+
def sanitize_shop_param(params)
|
44
|
+
return unless params[:shop].present?
|
45
|
+
name = params[:shop].to_s.strip
|
46
|
+
name += '.myshopify.com' if !name.include?("myshopify.com") && !name.include?(".")
|
47
|
+
name.sub('https://', '').sub('http://', '')
|
48
|
+
end
|
49
|
+
end
|
@@ -45,12 +45,12 @@
|
|
45
45
|
|
46
46
|
<ul class="nav pull-right">
|
47
47
|
<li class="dropdown">
|
48
|
-
<%= link_to raw(shop_session.url+' <b class="caret"></b>'), "https://#{shop_session.url}", :class => 'shop_name dropdown-toggle', :'data-toggle' => 'dropdown'
|
48
|
+
<%= link_to raw(shop_session.url+' <b class="caret"></b>'), "https://#{shop_session.url}", :class => 'shop_name dropdown-toggle', :'data-toggle' => 'dropdown', :'data-target' => '#' %>
|
49
49
|
<ul class="dropdown-menu">
|
50
50
|
<li><%= link_to raw('<i class="icon-home"></i> Storefront'), "http://"+shop_session.url, :target => 'blank' %></li>
|
51
51
|
<li><%= link_to raw('<i class="icon-cog"></i> Shopify Admin'), "http://"+shop_session.url+"/admin", :target => 'blank' %></li>
|
52
52
|
<li class="divider"></li>
|
53
|
-
<li><%= link_to raw('<i class="icon-off"></i>
|
53
|
+
<li><%= link_to raw('<i class="icon-off"></i> Logout'), logout_path, :method => :delete %></li>
|
54
54
|
</ul>
|
55
55
|
</li>
|
56
56
|
</ul>
|
data/lib/generators/shopify_app/templates/app/views/{login/index.html.erb → sessions/new.html.erb}
RENAMED
@@ -4,7 +4,7 @@
|
|
4
4
|
</div>
|
5
5
|
|
6
6
|
<div style="width:340px; margin:0 auto;">
|
7
|
-
<%= form_tag
|
7
|
+
<%= form_tag login_path, :class => 'form-search' do %>
|
8
8
|
<%= text_field_tag 'shop', nil, :placeholder => 'Shop URL', :class => 'btn-large' %>
|
9
9
|
<%= submit_tag 'Install', :class => 'btn btn-primary btn-large' %>
|
10
10
|
<% end %>
|
data/lib/shopify_app/version.rb
CHANGED
data/shopify_app.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["edward@shopify.com", "willem@shopify.com", "david.underwood@shopify.com"]
|
11
11
|
s.homepage = "http://www.shopify.com/developers"
|
12
12
|
s.summary = %q{This gem is used to get quickly started with the Shopify API}
|
13
|
-
s.description = %q{Creates a basic
|
13
|
+
s.description = %q{Creates a basic sessions controller for authenticating with your Shop and also a product controller which lets your edit your products easily.}
|
14
14
|
|
15
15
|
s.rubyforge_project = "shopify-api"
|
16
16
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0
|
4
|
+
version: 4.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -75,8 +75,8 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
description: Creates a basic
|
79
|
-
also a product controller which lets your edit your products easily.
|
78
|
+
description: Creates a basic sessions controller for authenticating with your Shop
|
79
|
+
and also a product controller which lets your edit your products easily.
|
80
80
|
email:
|
81
81
|
- edward@shopify.com
|
82
82
|
- willem@shopify.com
|
@@ -107,7 +107,7 @@ files:
|
|
107
107
|
- lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app.css.scss
|
108
108
|
- lib/generators/shopify_app/templates/app/assets/stylesheets/shopify_app_buttons.css.less
|
109
109
|
- lib/generators/shopify_app/templates/app/controllers/home_controller.rb
|
110
|
-
- lib/generators/shopify_app/templates/app/controllers/
|
110
|
+
- lib/generators/shopify_app/templates/app/controllers/sessions_controller.rb
|
111
111
|
- lib/generators/shopify_app/templates/app/helpers/home_helper.rb
|
112
112
|
- lib/generators/shopify_app/templates/app/helpers/login_helper.rb
|
113
113
|
- lib/generators/shopify_app/templates/app/helpers/tabs_helper.rb
|
@@ -115,7 +115,7 @@ files:
|
|
115
115
|
- lib/generators/shopify_app/templates/app/views/home/index.html.erb
|
116
116
|
- lib/generators/shopify_app/templates/app/views/home/welcome.html.erb
|
117
117
|
- lib/generators/shopify_app/templates/app/views/layouts/application.html.erb
|
118
|
-
- lib/generators/shopify_app/templates/app/views/
|
118
|
+
- lib/generators/shopify_app/templates/app/views/sessions/new.html.erb
|
119
119
|
- lib/generators/shopify_app/templates/config/initializers/omniauth.rb
|
120
120
|
- lib/generators/shopify_app/templates/public/404.html
|
121
121
|
- lib/generators/shopify_app/templates/public/422.html
|
@@ -1,44 +0,0 @@
|
|
1
|
-
class LoginController < ApplicationController
|
2
|
-
def index
|
3
|
-
# Ask user for their #{shop}.myshopify.com address
|
4
|
-
|
5
|
-
# If the #{shop}.myshopify.com address is already provided in the URL, just skip to #authenticate
|
6
|
-
if params[:shop].present?
|
7
|
-
redirect_to authenticate_path(:shop => params[:shop])
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
def authenticate
|
12
|
-
if params[:shop].present?
|
13
|
-
redirect_to "/auth/shopify?shop=#{params[:shop].to_s.strip}"
|
14
|
-
else
|
15
|
-
redirect_to return_address
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def finalize
|
20
|
-
if response = request.env['omniauth.auth']
|
21
|
-
sess = ShopifyAPI::Session.new(params['shop'], response['credentials']['token'])
|
22
|
-
session[:shopify] = sess
|
23
|
-
flash[:notice] = "Logged in"
|
24
|
-
redirect_to return_address
|
25
|
-
session[:return_to] = nil
|
26
|
-
else
|
27
|
-
flash[:error] = "Could not log in to Shopify store."
|
28
|
-
redirect_to :action => 'index'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def logout
|
33
|
-
session[:shopify] = nil
|
34
|
-
flash[:notice] = "Successfully logged out."
|
35
|
-
|
36
|
-
redirect_to :action => 'index'
|
37
|
-
end
|
38
|
-
|
39
|
-
protected
|
40
|
-
|
41
|
-
def return_address
|
42
|
-
session[:return_to] || root_url
|
43
|
-
end
|
44
|
-
end
|