shopify-sinatra-app 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +10 -19
- data/README.md +1 -0
- data/bin/shopify-sinatra-app-generator +23 -23
- data/lib/generator/Gemfile +2 -1
- data/lib/generator/Rakefile +3 -3
- data/lib/generator/config.ru +5 -0
- data/lib/generator/lib/app.rb +5 -6
- data/lib/generator/test/app_test.rb +10 -12
- data/lib/generator/test/test_helper.rb +2 -2
- data/lib/generator/views/home.erb +1 -1
- data/lib/sinatra/shopify-sinatra-app.rb +43 -46
- data/shopify-sinatra-app.gemspec +6 -6
- metadata +36 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49c0a937d645a62f0027838fe41b665c115f2a53
|
4
|
+
data.tar.gz: 6d2a1e607282763a9470970bbf961440b742fce8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf9e8b4f11cebb9c40335325cb2651cbedc6a4e11f9cad5fbca74e93ee54f0535f455ed062b971e344bdac4bc9301865e37a65a07629be5ae34c9db2d0fd76b
|
7
|
+
data.tar.gz: ed2f00667a9b446d126f3e3926842587c3d580c0c0fc353ea2cf39b88910681bd8f3f54a70a74d6f107b3253fb8bf2344c4de7ef3f52bf409b5674efe383330a
|
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
|
-
ruby
|
2
|
+
ruby '2.1.5'
|
3
3
|
|
4
4
|
gem 'sinatra'
|
5
5
|
gem 'sinatra-redis'
|
@@ -13,8 +13,8 @@ gem 'rake'
|
|
13
13
|
|
14
14
|
gem 'resque', '~> 1.22.0'
|
15
15
|
|
16
|
-
gem 'omniauth-shopify-oauth2'
|
17
|
-
gem 'shopify_api'
|
16
|
+
gem 'omniauth-shopify-oauth2', '~> 1.1.8'
|
17
|
+
gem 'shopify_api', '~> 4.0.2'
|
18
18
|
|
19
19
|
group :production do
|
20
20
|
gem 'pg'
|
data/Gemfile.lock
CHANGED
@@ -25,23 +25,21 @@ GEM
|
|
25
25
|
byebug (3.1.2)
|
26
26
|
columnize (~> 0.8)
|
27
27
|
debugger-linecache (~> 1.2)
|
28
|
-
coderay (1.1.0)
|
29
28
|
columnize (0.8.9)
|
30
29
|
debugger-linecache (1.2.0)
|
31
30
|
dotenv (0.7.0)
|
32
31
|
encryptor (1.3.0)
|
33
32
|
fakeweb (1.3.0)
|
34
|
-
faraday (0.9.
|
33
|
+
faraday (0.9.1)
|
35
34
|
multipart-post (>= 1.2, < 3)
|
36
35
|
foreman (0.64.0)
|
37
36
|
dotenv (~> 0.7.0)
|
38
37
|
thor (>= 0.13.6)
|
39
|
-
hashie (
|
38
|
+
hashie (3.4.1)
|
40
39
|
i18n (0.6.9)
|
41
40
|
json (1.8.1)
|
42
|
-
jwt (1.
|
41
|
+
jwt (1.5.0)
|
43
42
|
metaclass (0.0.4)
|
44
|
-
method_source (0.8.2)
|
45
43
|
minitest (5.3.4)
|
46
44
|
mocha (1.1.0)
|
47
45
|
metaclass (~> 0.0.1)
|
@@ -54,21 +52,17 @@ GEM
|
|
54
52
|
multi_json (~> 1.3)
|
55
53
|
multi_xml (~> 0.5)
|
56
54
|
rack (~> 1.2)
|
57
|
-
omniauth (1.2.
|
58
|
-
hashie (>= 1.2, <
|
55
|
+
omniauth (1.2.2)
|
56
|
+
hashie (>= 1.2, < 4)
|
59
57
|
rack (~> 1.0)
|
60
58
|
omniauth-oauth2 (1.1.2)
|
61
59
|
faraday (>= 0.8, < 0.10)
|
62
60
|
multi_json (~> 1.3)
|
63
61
|
oauth2 (~> 0.9.3)
|
64
62
|
omniauth (~> 1.2)
|
65
|
-
omniauth-shopify-oauth2 (1.1.
|
63
|
+
omniauth-shopify-oauth2 (1.1.8)
|
66
64
|
omniauth-oauth2 (~> 1.1.1)
|
67
65
|
pg (0.17.1)
|
68
|
-
pry (0.9.12.6)
|
69
|
-
coderay (~> 1.0)
|
70
|
-
method_source (~> 0.8)
|
71
|
-
slop (~> 3.4)
|
72
66
|
rack (1.5.2)
|
73
67
|
rack-flash3 (1.0.5)
|
74
68
|
rack
|
@@ -87,10 +81,8 @@ GEM
|
|
87
81
|
redis-namespace (~> 1.0)
|
88
82
|
sinatra (>= 0.9.2)
|
89
83
|
vegas (~> 0.1.2)
|
90
|
-
shopify_api (
|
91
|
-
activeresource
|
92
|
-
pry (>= 0.9.12.6)
|
93
|
-
thor (~> 0.18.1)
|
84
|
+
shopify_api (4.0.2)
|
85
|
+
activeresource
|
94
86
|
sinatra (1.4.5)
|
95
87
|
rack (~> 1.4)
|
96
88
|
rack-protection (~> 1.4)
|
@@ -102,7 +94,6 @@ GEM
|
|
102
94
|
redis
|
103
95
|
sinatra (>= 0.9.4)
|
104
96
|
sinatra-twitter-bootstrap (2.3.3)
|
105
|
-
slop (3.5.0)
|
106
97
|
sqlite3 (1.3.9)
|
107
98
|
thor (0.18.1)
|
108
99
|
thread_safe (0.3.4)
|
@@ -123,13 +114,13 @@ DEPENDENCIES
|
|
123
114
|
foreman
|
124
115
|
minitest
|
125
116
|
mocha
|
126
|
-
omniauth-shopify-oauth2
|
117
|
+
omniauth-shopify-oauth2 (~> 1.1.8)
|
127
118
|
pg
|
128
119
|
rack-flash3
|
129
120
|
rack-test
|
130
121
|
rake
|
131
122
|
resque (~> 1.22.0)
|
132
|
-
shopify_api
|
123
|
+
shopify_api (~> 4.0.2)
|
133
124
|
sinatra
|
134
125
|
sinatra-activerecord
|
135
126
|
sinatra-redis
|
data/README.md
CHANGED
@@ -234,6 +234,7 @@ Apps using this framework
|
|
234
234
|
-------------------------
|
235
235
|
|
236
236
|
* [shopify-fulfillment-integration](https://github.com/Shopify/shopify-fulfillment-integration)
|
237
|
+
* [shopify-tax-receipts](https://github.com/pickle27/shopify-tax-receipts)
|
237
238
|
* Add yours!
|
238
239
|
|
239
240
|
Contributing
|
@@ -3,17 +3,17 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
working_dir = Dir.pwd
|
5
5
|
|
6
|
-
spec = Gem::Specification.find_by_name(
|
6
|
+
spec = Gem::Specification.find_by_name('shopify-sinatra-app')
|
7
7
|
gem_root = spec.gem_dir
|
8
|
-
gem_lib = gem_root +
|
8
|
+
gem_lib = gem_root + '/lib'
|
9
9
|
|
10
|
-
generator_dir = gem_lib +
|
10
|
+
generator_dir = gem_lib + '/generator'
|
11
11
|
|
12
12
|
if ARGV.length < 2
|
13
13
|
puts "Usage:\n./shopify-sinatra-app new <app_name>"
|
14
14
|
else
|
15
15
|
app_name = ARGV[1]
|
16
|
-
app_dir = working_dir +
|
16
|
+
app_dir = working_dir + '/' + app_name
|
17
17
|
|
18
18
|
puts "Generating new app: #{app_name}"
|
19
19
|
puts "fullpath: #{app_dir}"
|
@@ -21,22 +21,22 @@ else
|
|
21
21
|
begin
|
22
22
|
Dir.mkdir(app_dir)
|
23
23
|
|
24
|
-
FileUtils.cp_r(generator_dir +
|
25
|
-
FileUtils.cp_r(generator_dir +
|
26
|
-
FileUtils.cp_r(generator_dir +
|
27
|
-
FileUtils.cp_r(generator_dir +
|
28
|
-
FileUtils.cp_r(generator_dir +
|
29
|
-
FileUtils.cp_r(generator_dir +
|
30
|
-
|
31
|
-
FileUtils.cp(generator_dir +
|
32
|
-
FileUtils.cp(generator_dir +
|
33
|
-
FileUtils.cp(generator_dir +
|
34
|
-
FileUtils.cp(generator_dir +
|
35
|
-
FileUtils.cp(generator_dir +
|
36
|
-
FileUtils.cp(generator_dir +
|
37
|
-
|
38
|
-
FileUtils.touch(app_dir +
|
39
|
-
file = File.open(app_dir +
|
24
|
+
FileUtils.cp_r(generator_dir + '/config', app_dir + '/config')
|
25
|
+
FileUtils.cp_r(generator_dir + '/db', app_dir + '/db')
|
26
|
+
FileUtils.cp_r(generator_dir + '/lib', app_dir + '/lib')
|
27
|
+
FileUtils.cp_r(generator_dir + '/public', app_dir + '/public')
|
28
|
+
FileUtils.cp_r(generator_dir + '/views', app_dir + '/views')
|
29
|
+
FileUtils.cp_r(generator_dir + '/test', app_dir + '/test')
|
30
|
+
|
31
|
+
FileUtils.cp(generator_dir + '/.gitignore', app_dir + '/.gitignore')
|
32
|
+
FileUtils.cp(generator_dir + '/config.ru', app_dir + '/config.ru')
|
33
|
+
FileUtils.cp(generator_dir + '/Procfile', app_dir + '/Procfile')
|
34
|
+
FileUtils.cp(generator_dir + '/Rakefile', app_dir + '/Rakefile')
|
35
|
+
FileUtils.cp(generator_dir + '/Gemfile', app_dir + '/Gemfile')
|
36
|
+
FileUtils.cp(generator_dir + '/README.md', app_dir + '/README.md')
|
37
|
+
|
38
|
+
FileUtils.touch(app_dir + '/.env')
|
39
|
+
file = File.open(app_dir + '/.env', 'w')
|
40
40
|
file.write("SHOPIFY_API_KEY=your_api_key\n")
|
41
41
|
file.write("SHOPIFY_SHARED_SECRET=your_shared_secret\n")
|
42
42
|
file.write("SECRET=random_string_to_encrypt_credentials_with\n")
|
@@ -44,17 +44,17 @@ else
|
|
44
44
|
|
45
45
|
Dir.chdir(app_dir)
|
46
46
|
|
47
|
-
pipe = IO.popen(
|
47
|
+
pipe = IO.popen('bundle install')
|
48
48
|
while (line = pipe.gets)
|
49
49
|
print line
|
50
50
|
end
|
51
51
|
|
52
|
-
pipe = IO.popen(
|
52
|
+
pipe = IO.popen('bundle exec rake db:migrate')
|
53
53
|
while (line = pipe.gets)
|
54
54
|
print line
|
55
55
|
end
|
56
56
|
|
57
57
|
rescue Errno::EEXIST => e
|
58
|
-
puts
|
58
|
+
puts 'App directory alread exists, pick a new app name or delete the existing folder'
|
59
59
|
end
|
60
60
|
end
|
data/lib/generator/Gemfile
CHANGED
data/lib/generator/Rakefile
CHANGED
@@ -4,18 +4,18 @@ require 'rake/testtask'
|
|
4
4
|
require './lib/app'
|
5
5
|
|
6
6
|
task :creds2heroku do
|
7
|
-
Bundler.with_clean_env
|
7
|
+
Bundler.with_clean_env do
|
8
8
|
File.readlines('.env').each do |var|
|
9
9
|
pipe = IO.popen("heroku config:set #{var}")
|
10
10
|
while (line = pipe.gets)
|
11
11
|
print line
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
end
|
15
15
|
end
|
16
16
|
|
17
17
|
task :deploy2heroku do
|
18
|
-
pipe = IO.popen(
|
18
|
+
pipe = IO.popen('git push heroku master --force')
|
19
19
|
while (line = pipe.gets)
|
20
20
|
print line
|
21
21
|
end
|
data/lib/generator/config.ru
CHANGED
data/lib/generator/lib/app.rb
CHANGED
@@ -12,7 +12,7 @@ class SinatraApp < Sinatra::Base
|
|
12
12
|
# from Shopify and displays them inside your app
|
13
13
|
get '/' do
|
14
14
|
shopify_session do
|
15
|
-
@products = ShopifyAPI::Product.find(:all, :
|
15
|
+
@products = ShopifyAPI::Product.find(:all, params: { limit: 10 })
|
16
16
|
erb :home
|
17
17
|
end
|
18
18
|
end
|
@@ -37,15 +37,14 @@ class SinatraApp < Sinatra::Base
|
|
37
37
|
# when your app is uninstalled from a shop. It is good
|
38
38
|
# practice to clean up any data from a shop when they
|
39
39
|
# uninstall your app.
|
40
|
-
uninstall_webhook = ShopifyAPI::Webhook.new(
|
41
|
-
topic:
|
40
|
+
uninstall_webhook = ShopifyAPI::Webhook.new(
|
41
|
+
topic: 'app/uninstalled',
|
42
42
|
address: "#{base_url}/uninstall",
|
43
|
-
format:
|
44
|
-
|
43
|
+
format: 'json'
|
44
|
+
)
|
45
45
|
uninstall_webhook.save
|
46
46
|
end
|
47
47
|
|
48
48
|
redirect '/'
|
49
49
|
end
|
50
|
-
|
51
50
|
end
|
@@ -1,19 +1,18 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'test_helper'
|
2
|
+
require './lib/app'
|
3
3
|
|
4
4
|
class AppTest < Minitest::Test
|
5
|
-
|
6
5
|
def app
|
7
6
|
SinatraApp
|
8
7
|
end
|
9
8
|
|
10
9
|
def setup
|
11
|
-
@shop_name =
|
10
|
+
@shop_name = 'testshop.myshopify.com'
|
12
11
|
end
|
13
12
|
|
14
13
|
def test_root_with_session
|
15
14
|
set_session
|
16
|
-
fake
|
15
|
+
fake 'https://testshop.myshopify.com/admin/products.json?limit=10', body: '{}'
|
17
16
|
get '/'
|
18
17
|
assert last_response.ok?
|
19
18
|
end
|
@@ -21,7 +20,7 @@ class AppTest < Minitest::Test
|
|
21
20
|
def test_root_with_session_activates_api
|
22
21
|
set_session
|
23
22
|
SinatraApp.any_instance.expects(:activate_shopify_api).with(@shop_name, 'token')
|
24
|
-
ShopifyAPI::Product.expects(:find).returns(
|
23
|
+
ShopifyAPI::Product.expects(:find).returns([])
|
25
24
|
get '/'
|
26
25
|
assert last_response.ok?
|
27
26
|
end
|
@@ -34,13 +33,13 @@ class AppTest < Minitest::Test
|
|
34
33
|
|
35
34
|
def test_root_with_shop_redirects_to_auth
|
36
35
|
get '/?shop=othertestshop.myshopify.com'
|
37
|
-
assert_match
|
36
|
+
assert_match '/auth/shopify?shop=othertestshop.myshopify.com', last_response.body
|
38
37
|
end
|
39
38
|
|
40
39
|
def test_root_with_session_and_new_shop_redirects_to_auth
|
41
40
|
set_session
|
42
41
|
get '/?shop=othertestshop.myshopify.com'
|
43
|
-
assert_match
|
42
|
+
assert_match '/auth/shopify?shop=othertestshop.myshopify.com', last_response.body
|
44
43
|
end
|
45
44
|
|
46
45
|
def test_root_rescues_UnauthorizedAccess_clears_session_and_redirects
|
@@ -56,14 +55,13 @@ class AppTest < Minitest::Test
|
|
56
55
|
def test_uninstall_webhook_endpoint
|
57
56
|
SinatraApp.any_instance.expects(:verify_shopify_webhook).returns(true)
|
58
57
|
Shop.any_instance.expects(:destroy)
|
59
|
-
post '/uninstall',
|
58
|
+
post '/uninstall', '{}', 'HTTP_X_SHOPIFY_SHOP_DOMAIN' => @shop_name
|
60
59
|
assert last_response.ok?
|
61
60
|
end
|
62
61
|
|
63
62
|
private
|
64
63
|
|
65
|
-
def set_session(shop =
|
66
|
-
SinatraApp.any_instance.stubs(:session).returns(
|
64
|
+
def set_session(shop = 'testshop.myshopify.com', token = 'token')
|
65
|
+
SinatraApp.any_instance.stubs(:session).returns(shopify: { shop: shop, token: token })
|
67
66
|
end
|
68
|
-
|
69
67
|
end
|
@@ -15,12 +15,12 @@ module Helpers
|
|
15
15
|
File.read("./test/fixtures/#{name}")
|
16
16
|
end
|
17
17
|
|
18
|
-
def fake(url, options={})
|
18
|
+
def fake(url, options = {})
|
19
19
|
method = options.delete(:method) || :get
|
20
20
|
body = options.delete(:body) || '{}'
|
21
21
|
format = options.delete(:format) || :json
|
22
22
|
|
23
|
-
FakeWeb.register_uri(method, url, {:
|
23
|
+
FakeWeb.register_uri(method, url, { body: body, status: 200, content_type: "application/#{format}" }.merge(options))
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -13,10 +13,9 @@ require 'omniauth-shopify-oauth2'
|
|
13
13
|
|
14
14
|
module Sinatra
|
15
15
|
module Shopify
|
16
|
-
|
17
16
|
module Methods
|
18
17
|
def install
|
19
|
-
|
18
|
+
fail NotImplementedError
|
20
19
|
end
|
21
20
|
|
22
21
|
def logout
|
@@ -32,7 +31,7 @@ module Sinatra
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def current_shop_name
|
35
|
-
return session[:shopify][:shop] if session.
|
34
|
+
return session[:shopify][:shop] if session.key?(:shopify)
|
36
35
|
return @shop_name if @shop_name
|
37
36
|
end
|
38
37
|
|
@@ -41,7 +40,7 @@ module Sinatra
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def shopify_session(&blk)
|
44
|
-
if !session.
|
43
|
+
if !session.key?(:shopify)
|
45
44
|
get_session
|
46
45
|
elsif params[:shop].present? && session[:shopify][:shop] != sanitize_shop_param(params)
|
47
46
|
logout
|
@@ -54,13 +53,13 @@ module Sinatra
|
|
54
53
|
end
|
55
54
|
rescue ActiveResource::UnauthorizedAccess
|
56
55
|
clear_session current_shop
|
57
|
-
redirect request.env[
|
56
|
+
redirect request.env['sinatra.route'].split(' ').last
|
58
57
|
end
|
59
58
|
|
60
59
|
def webhook_session(&blk)
|
61
60
|
return unless verify_shopify_webhook
|
62
61
|
@shop_name = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN']
|
63
|
-
shop = Shop.find_by(:
|
62
|
+
shop = Shop.find_by(name: @shop_name)
|
64
63
|
|
65
64
|
if shop.present?
|
66
65
|
params = ActiveSupport::JSON.decode(request.body.read.to_s)
|
@@ -73,7 +72,7 @@ module Sinatra
|
|
73
72
|
def webhook_job(jobKlass)
|
74
73
|
return unless verify_shopify_webhook
|
75
74
|
@shop_name = request.env['HTTP_X_SHOPIFY_SHOP_DOMAIN']
|
76
|
-
shop = Shop.find_by(:
|
75
|
+
shop = Shop.find_by(name: @shop_name)
|
77
76
|
params = ActiveSupport::JSON.decode(request.body.read.to_s)
|
78
77
|
Resque.enqueue(jobKlass, shop.name, shop.token, params)
|
79
78
|
status 200
|
@@ -83,9 +82,9 @@ module Sinatra
|
|
83
82
|
|
84
83
|
def get_session
|
85
84
|
shop_name = sanitize_shop_param(params)
|
86
|
-
shop = Shop.find_by(:
|
85
|
+
shop = Shop.find_by(name: shop_name)
|
87
86
|
|
88
|
-
return_to = request.env[
|
87
|
+
return_to = request.env['sinatra.route'].split(' ').last
|
89
88
|
|
90
89
|
if shop.present? && shop.token.present?
|
91
90
|
session[:shopify] ||= {}
|
@@ -102,7 +101,7 @@ module Sinatra
|
|
102
101
|
redirect_url = "/auth/shopify?shop=#{shop_name}&return_to=#{base_url}#{return_to}"
|
103
102
|
fullpage_redirect_to redirect_url
|
104
103
|
else
|
105
|
-
redirect
|
104
|
+
redirect '/install'
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
@@ -122,18 +121,18 @@ module Sinatra
|
|
122
121
|
|
123
122
|
erb "<script type='text/javascript'>
|
124
123
|
window.top.location.href = '<%= @fullpage_redirect_to %>';
|
125
|
-
</script>", :
|
124
|
+
</script>", layout: false
|
126
125
|
end
|
127
126
|
|
128
127
|
def sanitize_shop_param(params)
|
129
128
|
return unless params[:shop].present?
|
130
129
|
name = params[:shop].to_s.strip
|
131
|
-
name += '.myshopify.com' if !name.include?(
|
130
|
+
name += '.myshopify.com' if !name.include?('myshopify.com') && !name.include?('.')
|
132
131
|
name.gsub!('https://', '')
|
133
132
|
name.gsub!('http://', '')
|
134
133
|
|
135
134
|
u = URI("http://#{name}")
|
136
|
-
u.host.ends_with?(
|
135
|
+
u.host.ends_with?('.myshopify.com') ? u.host : nil
|
137
136
|
end
|
138
137
|
|
139
138
|
def verify_shopify_webhook
|
@@ -145,7 +144,7 @@ module Sinatra
|
|
145
144
|
if calculated_hmac == request.env['HTTP_X_SHOPIFY_HMAC_SHA256']
|
146
145
|
true
|
147
146
|
else
|
148
|
-
puts
|
147
|
+
puts 'Shopify Webhook verifictation failed!'
|
149
148
|
false
|
150
149
|
end
|
151
150
|
end
|
@@ -156,11 +155,11 @@ module Sinatra
|
|
156
155
|
app.register Sinatra::ActiveRecordExtension
|
157
156
|
app.register Sinatra::Twitter::Bootstrap::Assets
|
158
157
|
|
159
|
-
app.set :database_file, File.expand_path(
|
160
|
-
app.set :views, File.expand_path(
|
161
|
-
app.set :public_folder, File.expand_path(
|
162
|
-
app.set :erb, :
|
163
|
-
app.set :protection, :
|
158
|
+
app.set :database_file, File.expand_path('config/database.yml')
|
159
|
+
app.set :views, File.expand_path('views')
|
160
|
+
app.set :public_folder, File.expand_path('public')
|
161
|
+
app.set :erb, layout: :'layouts/application'
|
162
|
+
app.set :protection, except: :frame_options
|
164
163
|
|
165
164
|
app.enable :sessions
|
166
165
|
app.enable :inline_templates
|
@@ -171,40 +170,40 @@ module Sinatra
|
|
171
170
|
app.set :shared_secret, ENV['SHOPIFY_SHARED_SECRET']
|
172
171
|
app.set :secret, ENV['SECRET']
|
173
172
|
|
174
|
-
app.use Rack::Flash, :
|
173
|
+
app.use Rack::Flash, sweep: true
|
175
174
|
app.use Rack::MethodOverride
|
176
|
-
app.use Rack::Session::Cookie, :
|
177
|
-
:
|
178
|
-
:
|
179
|
-
:
|
175
|
+
app.use Rack::Session::Cookie, key: '#{base_url}.session',
|
176
|
+
path: '/',
|
177
|
+
secret: app.settings.secret,
|
178
|
+
expire_after: 60 * 30 # half an hour in seconds
|
180
179
|
|
181
|
-
app.set :redis_url, ENV[
|
180
|
+
app.set :redis_url, ENV['REDISCLOUD_URL'] || 'redis://localhost:6379/'
|
182
181
|
redis_uri = URI.parse(app.settings.redis_url)
|
183
|
-
Resque.redis = ::Redis.new(:
|
184
|
-
|
185
|
-
|
186
|
-
Resque.redis.namespace =
|
182
|
+
Resque.redis = ::Redis.new(host: redis_uri.host,
|
183
|
+
port: redis_uri.port,
|
184
|
+
password: redis_uri.password)
|
185
|
+
Resque.redis.namespace = 'resque'
|
187
186
|
app.set :redis, app.settings.redis_url
|
188
187
|
|
189
188
|
app.use OmniAuth::Builder do
|
190
189
|
provider :shopify,
|
191
|
-
|
192
|
-
|
190
|
+
app.settings.api_key,
|
191
|
+
app.settings.shared_secret,
|
193
192
|
|
194
|
-
|
193
|
+
scope: app.settings.scope,
|
195
194
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
195
|
+
setup: lambda { |env|
|
196
|
+
params = Rack::Utils.parse_query(env['QUERY_STRING'])
|
197
|
+
site_url = "https://#{params['shop']}"
|
198
|
+
env['omniauth.strategy'].options[:client_options][:site] = site_url
|
199
|
+
}
|
201
200
|
end
|
202
201
|
|
203
|
-
ShopifyAPI::Session.setup(
|
204
|
-
|
202
|
+
ShopifyAPI::Session.setup(api_key: app.settings.api_key,
|
203
|
+
secret: app.settings.shared_secret)
|
205
204
|
|
206
205
|
app.get '/install' do
|
207
|
-
erb :install, :
|
206
|
+
erb :install, layout: false
|
208
207
|
end
|
209
208
|
|
210
209
|
app.post '/login' do
|
@@ -217,7 +216,7 @@ module Sinatra
|
|
217
216
|
end
|
218
217
|
|
219
218
|
app.get '/auth/shopify/callback' do
|
220
|
-
shop_name = params[
|
219
|
+
shop_name = params['shop']
|
221
220
|
token = request.env['omniauth.auth']['credentials']['token']
|
222
221
|
|
223
222
|
session[:shopify] ||= {}
|
@@ -227,7 +226,7 @@ module Sinatra
|
|
227
226
|
shop = Shop.find_by(name: shop_name)
|
228
227
|
|
229
228
|
if shop.nil?
|
230
|
-
Shop.create(:
|
229
|
+
Shop.create(name: shop_name, token: token)
|
231
230
|
install
|
232
231
|
elsif
|
233
232
|
shop.update_attributes(token: token)
|
@@ -239,7 +238,7 @@ module Sinatra
|
|
239
238
|
|
240
239
|
app.get '/auth/failure' do
|
241
240
|
erb "<h1>Authentication Failed:</h1>
|
242
|
-
<h3>message:<h3> <pre>#{params}</pre>", :
|
241
|
+
<h3>message:<h3> <pre>#{params}</pre>", layout: false
|
243
242
|
end
|
244
243
|
end
|
245
244
|
end
|
@@ -247,14 +246,12 @@ module Sinatra
|
|
247
246
|
register Shopify
|
248
247
|
end
|
249
248
|
|
250
|
-
|
251
249
|
class Shop < ActiveRecord::Base
|
252
|
-
|
253
250
|
def self.secret
|
254
251
|
@secret ||= ENV['SECRET']
|
255
252
|
end
|
256
253
|
|
257
|
-
attr_encrypted :token, :
|
254
|
+
attr_encrypted :token, key: secret, attribute: 'token_encrypted'
|
258
255
|
validates_presence_of :name
|
259
256
|
validates_presence_of :token, on: :create
|
260
257
|
end
|
data/shopify-sinatra-app.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'shopify-sinatra-app'
|
3
|
-
s.version = '0.1.
|
3
|
+
s.version = '0.1.4'
|
4
4
|
|
5
|
-
s.summary =
|
6
|
-
s.description =
|
5
|
+
s.summary = 'A classy shopify app'
|
6
|
+
s.description = 'A Sinatra extension for building Shopify Apps. Akin to the shopify_app gem but for Sinatra'
|
7
7
|
|
8
|
-
s.authors = [
|
9
|
-
s.email =
|
10
|
-
s.homepage =
|
8
|
+
s.authors = ['Kevin Hughes']
|
9
|
+
s.email = 'kevin.hughes@shopify.com'
|
10
|
+
s.homepage = 'https://github.com/pickle27/shopify-sinatra-app/'
|
11
11
|
s.license = 'MIT'
|
12
12
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
metadata
CHANGED
@@ -1,223 +1,223 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shopify-sinatra-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sinatra-redis
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sinatra-activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sinatra-twitter-bootstrap
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-flash3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activesupport
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: attr_encrypted
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: resque
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - ~>
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: 1.22.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - ~>
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 1.22.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: shopify_api
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: omniauth-shopify-oauth2
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - ">="
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :runtime
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rake
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
|
-
- -
|
157
|
+
- - ">="
|
158
158
|
- !ruby/object:Gem::Version
|
159
159
|
version: '0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
|
-
- -
|
164
|
+
- - ">="
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: sqlite3
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- -
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
type: :development
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- -
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: rack-test
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
184
184
|
requirements:
|
185
|
-
- -
|
185
|
+
- - ">="
|
186
186
|
- !ruby/object:Gem::Version
|
187
187
|
version: '0'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - ">="
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: fakeweb
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- -
|
199
|
+
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0'
|
202
202
|
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- -
|
206
|
+
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: mocha
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
|
-
- -
|
213
|
+
- - ">="
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
type: :development
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
|
-
- -
|
220
|
+
- - ">="
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: '0'
|
223
223
|
description: A Sinatra extension for building Shopify Apps. Akin to the shopify_app
|
@@ -228,7 +228,7 @@ executables:
|
|
228
228
|
extensions: []
|
229
229
|
extra_rdoc_files: []
|
230
230
|
files:
|
231
|
-
- .gitignore
|
231
|
+
- ".gitignore"
|
232
232
|
- Gemfile
|
233
233
|
- Gemfile.lock
|
234
234
|
- LICENSE
|
@@ -269,17 +269,17 @@ require_paths:
|
|
269
269
|
- lib
|
270
270
|
required_ruby_version: !ruby/object:Gem::Requirement
|
271
271
|
requirements:
|
272
|
-
- -
|
272
|
+
- - ">="
|
273
273
|
- !ruby/object:Gem::Version
|
274
274
|
version: '0'
|
275
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
276
|
requirements:
|
277
|
-
- -
|
277
|
+
- - ">="
|
278
278
|
- !ruby/object:Gem::Version
|
279
279
|
version: '0'
|
280
280
|
requirements: []
|
281
281
|
rubyforge_project:
|
282
|
-
rubygems_version: 2.
|
282
|
+
rubygems_version: 2.2.2
|
283
283
|
signing_key:
|
284
284
|
specification_version: 4
|
285
285
|
summary: A classy shopify app
|