shopify-sinatra-app 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/CHANGELOG +6 -0
- data/README.md +0 -2
- data/example/Gemfile +1 -1
- data/example/db/schema.rb +1 -1
- data/example/src/app.rb +1 -1
- data/example/test/app_test.rb +14 -1
- data/example/test/test_helper.rb +2 -0
- data/lib/sinatra/shopify-sinatra-app.rb +27 -11
- data/shopify-sinatra-app.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 824f5c84a183bf093bf35cb931166ed811fafb4dcdb32664a9c3027a56acf38f
|
4
|
+
data.tar.gz: 4369c1e33e0032792d4016f772bd041f3eb85aea722e015a9d7e1aed48e29f78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e64a1b720743bde0a66a79c39d5574d62f9867da1c7bb479a96253051197efb6e21f0a9366c59d1d98d503478b50a69c3707ba4300fefda601e26a78f7b5f042
|
7
|
+
data.tar.gz: 7ff7babe886332b170e4ae052669acba61a922ee2b814a77b0d52d0c72ce5920ad7171e80956dcdac81358e4489acf17002448f6f784f2dacf9d57744b2c85a4
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
0.7.0
|
2
|
+
-----
|
3
|
+
* make base_url private (users can add back in their app easily if needed)
|
4
|
+
* store request params in the session so they can be retrieved after the omniauth flow. This fixes app actions from the admin if the user's session has expired
|
5
|
+
* refactored some smaller methods to make the shopify_session method easier on the eyes.
|
6
|
+
|
1
7
|
0.6.0
|
2
8
|
-----
|
3
9
|
* remove current_shop* methods in favor of yielding shop_name to the block methods
|
data/README.md
CHANGED
@@ -112,8 +112,6 @@ It's impossible to control the flow of webhooks to your app from Shopify especia
|
|
112
112
|
|
113
113
|
**logout** - This method clears the current session
|
114
114
|
|
115
|
-
**base_url** - This returns the url of the app
|
116
|
-
|
117
115
|
shopify-sinatra-app includes sinatra/activerecord for creating models that can be persisted in the database. You might want to read more about sinatra/activerecord and the methods it makes available to you: [https://github.com/janko-m/sinatra-activerecord](https://github.com/janko-m/sinatra-activerecord)
|
118
116
|
|
119
117
|
shopify-sinatra-app also includes `rack-flash3` and the flash messages are forwarded to the Shopify Embedded App SDK (see the code in `views/layouts/application.erb`). Flash messages are useful for signalling to your users that a request was successful without changing the page. The following is an example of how to use a flash message in a route:
|
data/example/Gemfile
CHANGED
data/example/db/schema.rb
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# It's strongly recommended that you check this file into your version control system.
|
12
12
|
|
13
|
-
ActiveRecord::Schema.define(version:
|
13
|
+
ActiveRecord::Schema.define(version: 2014_04_14_042317) do
|
14
14
|
|
15
15
|
create_table "shops", force: :cascade do |t|
|
16
16
|
t.string "name"
|
data/example/src/app.rb
CHANGED
@@ -22,7 +22,7 @@ class SinatraApp < Sinatra::Base
|
|
22
22
|
# and cleans up data, add to this endpoint as your app
|
23
23
|
# stores more data.
|
24
24
|
post '/uninstall' do
|
25
|
-
|
25
|
+
shopify_webhook do |shop_name, params|
|
26
26
|
Shop.find_by(name: shop_name).destroy
|
27
27
|
end
|
28
28
|
end
|
data/example/test/app_test.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require './src/app'
|
3
3
|
|
4
|
+
class MockShop
|
5
|
+
def initialize(shop_name)
|
6
|
+
@shop_name = shop_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def myshopify_domain
|
10
|
+
@shop_name
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
4
14
|
class AppTest < Minitest::Test
|
5
15
|
def app
|
6
16
|
SinatraApp
|
@@ -8,10 +18,12 @@ class AppTest < Minitest::Test
|
|
8
18
|
|
9
19
|
def setup
|
10
20
|
@shop_name = 'testshop.myshopify.com'
|
21
|
+
@shopify_shop = MockShop.new(@shop_name)
|
11
22
|
end
|
12
23
|
|
13
24
|
def test_root_with_session
|
14
25
|
set_session
|
26
|
+
fake 'https://testshop.myshopify.com/admin/shop.json', body: {myshopify_domain: @shop_name}.to_json
|
15
27
|
fake 'https://testshop.myshopify.com/admin/products.json?limit=10', body: '{}'
|
16
28
|
get '/'
|
17
29
|
assert last_response.ok?
|
@@ -20,6 +32,7 @@ class AppTest < Minitest::Test
|
|
20
32
|
def test_root_with_session_activates_api
|
21
33
|
set_session
|
22
34
|
SinatraApp.any_instance.expects(:activate_shopify_api).with(@shop_name, 'token')
|
35
|
+
ShopifyAPI::Shop.expects(:current).returns(@shopify_shop)
|
23
36
|
ShopifyAPI::Product.expects(:find).returns([])
|
24
37
|
get '/'
|
25
38
|
assert last_response.ok?
|
@@ -46,7 +59,7 @@ class AppTest < Minitest::Test
|
|
46
59
|
set_session
|
47
60
|
SinatraApp.any_instance.expects(:activate_shopify_api).with(@shop_name, 'token')
|
48
61
|
SinatraApp.any_instance.expects(:clear_session)
|
49
|
-
ShopifyAPI::
|
62
|
+
ShopifyAPI::Shop.expects(:current).raises(ActiveResource::UnauthorizedAccess.new('UnauthorizedAccess'))
|
50
63
|
get '/'
|
51
64
|
assert_equal 302, last_response.status
|
52
65
|
assert_equal 'http://example.org/', last_response.location
|
data/example/test/test_helper.rb
CHANGED
@@ -18,10 +18,7 @@ module Sinatra
|
|
18
18
|
|
19
19
|
def logout
|
20
20
|
session.delete(:shopify)
|
21
|
-
|
22
|
-
|
23
|
-
def base_url
|
24
|
-
"#{request_protocol}://#{request.env['HTTP_HOST']}"
|
21
|
+
session.clear
|
25
22
|
end
|
26
23
|
|
27
24
|
# for the esdk initializer
|
@@ -30,13 +27,14 @@ module Sinatra
|
|
30
27
|
end
|
31
28
|
|
32
29
|
def shopify_session(&blk)
|
33
|
-
return_to = request.
|
30
|
+
return_to = request.path
|
31
|
+
return_params = request.params
|
34
32
|
|
35
|
-
if
|
36
|
-
authenticate(return_to)
|
37
|
-
elsif
|
33
|
+
if no_session?
|
34
|
+
authenticate(return_to, return_params)
|
35
|
+
elsif different_shop?
|
38
36
|
logout
|
39
|
-
authenticate(return_to)
|
37
|
+
authenticate(return_to, return_params)
|
40
38
|
else
|
41
39
|
shop_name = session[:shopify][:shop]
|
42
40
|
token = session[:shopify][:token]
|
@@ -45,7 +43,7 @@ module Sinatra
|
|
45
43
|
end
|
46
44
|
rescue ActiveResource::UnauthorizedAccess
|
47
45
|
clear_session shop_name
|
48
|
-
redirect request.
|
46
|
+
redirect request.path
|
49
47
|
end
|
50
48
|
|
51
49
|
def shopify_webhook(&blk)
|
@@ -62,8 +60,21 @@ module Sinatra
|
|
62
60
|
request.secure? ? 'https' : 'http'
|
63
61
|
end
|
64
62
|
|
65
|
-
def
|
63
|
+
def base_url
|
64
|
+
"#{request_protocol}://#{request.env['HTTP_HOST']}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def no_session?
|
68
|
+
!session.key?(:shopify)
|
69
|
+
end
|
70
|
+
|
71
|
+
def different_shop?
|
72
|
+
params[:shop].present? && session[:shopify][:shop] != sanitize_shop_param(params)
|
73
|
+
end
|
74
|
+
|
75
|
+
def authenticate(return_to = '/', return_params = nil)
|
66
76
|
if shop_name = sanitized_shop_name
|
77
|
+
session[:return_params] = return_params if return_params
|
67
78
|
redirect_url = "/auth/shopify?shop=#{shop_name}&return_to=#{base_url}#{return_to}"
|
68
79
|
redirect_javascript redirect_url
|
69
80
|
else
|
@@ -221,6 +232,11 @@ module Sinatra
|
|
221
232
|
after_shopify_auth()
|
222
233
|
|
223
234
|
return_to = env['omniauth.params']['return_to']
|
235
|
+
return_params = session[:return_params]
|
236
|
+
session.delete(:return_params)
|
237
|
+
|
238
|
+
return_to += "?#{return_params.to_query}" if return_params.present?
|
239
|
+
|
224
240
|
redirect return_to
|
225
241
|
end
|
226
242
|
|
data/shopify-sinatra-app.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-sinatra-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Hughes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|