shopify-sinatra-app 0.3.0 → 0.3.1
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 +8 -0
- data/README.md +9 -11
- data/example/Gemfile +2 -2
- data/example/Gemfile.lock +35 -29
- data/example/views/install.erb +5 -3
- data/lib/sinatra/shopify-sinatra-app.rb +33 -8
- data/shopify-sinatra-app.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebf27b104b99f8d138a0c5c3c871cdc3edd9558c
|
4
|
+
data.tar.gz: 107fa00dc3e77b8f8f07ab5cb21b978b22863406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1a134962895a415bfcc25b48d8ec1da62f1d861f2fd42799627edcecb3ef96dc9875639025851a5153e2e3a1cdfcbb61010feb1bda9ce112e4fe01860325a3f
|
7
|
+
data.tar.gz: b52f04425dff3d76ce9e1480b5080614e910320b8a0e3e23b464344bc3ba7c48b39f2bd610be39418827478427e6ede55b844e9048ff696e733f1bb380a8bd19
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.3.1
|
2
|
+
-----
|
3
|
+
* update authentication code for upcoming chrome changes.
|
4
|
+
|
5
|
+
0.3.0
|
6
|
+
-----
|
7
|
+
* Remove sinatra-twitter-bootstrap dependency. Include css from cdn directly for example app.
|
8
|
+
|
1
9
|
0.2.0
|
2
10
|
-----
|
3
11
|
* added a SHOPIFY_REDIRECT_URI env param for setting the redirect_uri (was breifly HOSTNAME)
|
data/README.md
CHANGED
@@ -3,7 +3,8 @@ shopify-sinatra-app [![Build Status](https://travis-ci.org/kevinhughes27/shopify
|
|
3
3
|
|
4
4
|
"A classy shopify app"
|
5
5
|
|
6
|
-
shopify-sinatra-app is lightweight extension for building Shopify apps using Sinatra. It comes with the Shopify API gem for interacting with the Shopify API and uses the Shopify omniauth gem to handle authentication. The framework itself provides a handful of helper methods to make creating your app as easy as possible. The framework was designed with deployment to Heroku in mind and following the instructions below I've been able to create a new application from scratch, deploy it to Heroku and install on my live test shop in less than 5 minutes.
|
6
|
+
shopify-sinatra-app is lightweight extension for building Shopify apps using Sinatra. It comes with the Shopify API gem for interacting with the Shopify API and uses the Shopify omniauth gem to handle authentication via Oauth (other auth methods are not supported). The framework itself provides a handful of helper methods to make creating your app as easy as possible. The framework was designed with deployment to Heroku in mind and following the instructions below I've been able to create a new application from scratch, deploy it to Heroku and install on my live test shop in less than 5 minutes.
|
7
|
+
|
7
8
|
|
8
9
|
Getting Started
|
9
10
|
---------------
|
@@ -66,12 +67,12 @@ After creating your new application you need to edit the `.env` file and add the
|
|
66
67
|
```
|
67
68
|
SHOPIFY_API_KEY=<your api key>
|
68
69
|
SHOPIFY_SHARED_SECRET=<your shared secret>
|
69
|
-
SHOPIFY_REDIRECT_URI="<your redirect_uri>"
|
70
70
|
SECRET=<generate a random string to encrypt credentials with>
|
71
71
|
```
|
72
72
|
|
73
73
|
If your app has any other secret credentials you should add them to this file.
|
74
74
|
|
75
|
+
|
75
76
|
Shopify::Methods
|
76
77
|
----------------
|
77
78
|
|
@@ -137,11 +138,10 @@ end
|
|
137
138
|
|
138
139
|
note - a flash must be followed by a redirect or it won't work!
|
139
140
|
|
141
|
+
|
140
142
|
Developing
|
141
143
|
----------
|
142
|
-
|
143
|
-
|
144
|
-
When developing locally you'll need to enable unsafe javascripts in your browser for the Embedded App SDK to function. Read more [here](http://docs.shopify.com/embedded-app-sdk/getting-started).
|
144
|
+
The embedded app sdk won't load non https content so you'll need to use a forwarding service like [ngrok](https://ngrok.com/) or [forwardhq](https://forwardhq.com/). Set your application url in the [Shopify Partner area](https://app.shopify.com/services/partners/api_clients) to your forwarded url. However The redirect_uri should still be `http://localhost:4567/auth/shopify/callback` which will allow you to install your app on a live shop while running it locally.
|
145
145
|
|
146
146
|
To run the app locally we use `foreman` which comes with the [Heroku Toolbelt](https://devcenter.heroku.com/articles/quickstart). Foreman handles running our application and setting our credentials as environment variables. To run the application type:
|
147
147
|
|
@@ -153,13 +153,8 @@ Note - we use `foreman run ...` not `foreman start ...` because we only want to
|
|
153
153
|
|
154
154
|
To debug your app simply add `require 'byebug'` at the top and then type `byebug` where you would like to drop into an interactive session. You may also want to try out [Pry](http://pryrepl.org/).
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
```
|
159
|
-
./ngrok 4567
|
160
|
-
```
|
156
|
+
If you are testing webhooks locally make sure they also go through the forwarded url and not `localhost`.
|
161
157
|
|
162
|
-
Ngrok will report what address your app is available at, leave Ngrok running and then create your webhook to point to the ngrok url plus your route e.g. `<ngrok url>/webhook_test.json`. Now trigger the webhook you are testing and it will get forwarded through ngrok to your local web application allowing you to use debuggers and REPLs to complete your code.
|
163
158
|
|
164
159
|
Testing
|
165
160
|
-------
|
@@ -175,6 +170,7 @@ bundle exec rake test
|
|
175
170
|
|
176
171
|
Checkout the contents of the `app_test.rb` file and the `test_helper.rb` and modify them as you add functionality to your app. You can also check the tests of other apps using this framework to see more about how to write tests for your own app.
|
177
172
|
|
173
|
+
|
178
174
|
Deploying
|
179
175
|
---------
|
180
176
|
|
@@ -231,6 +227,7 @@ Note - if you are not using any background queue for processing webhooks then yo
|
|
231
227
|
|
232
228
|
Make sure you set your shopify apps url to your Heroku app url (and make sure to use the `https` version or else the Embedded App SDK won't work) in the Shopify Partner area https://app.shopify.com/services/partners/api_clients.
|
233
229
|
|
230
|
+
|
234
231
|
Apps using this framework
|
235
232
|
-------------------------
|
236
233
|
|
@@ -238,6 +235,7 @@ Apps using this framework
|
|
238
235
|
* [shopify-tax-receipts](https://github.com/pickle27/shopify-tax-receipts)
|
239
236
|
* Add yours!
|
240
237
|
|
238
|
+
|
241
239
|
Contributing
|
242
240
|
------------
|
243
241
|
|
data/example/Gemfile
CHANGED
data/example/Gemfile.lock
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
shopify-sinatra-app (0.3.0)
|
5
|
+
activesupport (~> 4.1.1)
|
6
|
+
attr_encrypted (~> 1.3.2)
|
7
|
+
omniauth-shopify-oauth2 (~> 1.1.11)
|
8
|
+
rack-flash3 (~> 1.0.5)
|
9
|
+
resque (~> 1.25.2)
|
10
|
+
shopify_api (~> 4.0.2)
|
11
|
+
sinatra (~> 1.4.6)
|
12
|
+
sinatra-activerecord (~> 2.0.9)
|
13
|
+
sinatra-redis (~> 0.3.0)
|
14
|
+
|
1
15
|
GEM
|
2
16
|
remote: https://rubygems.org/
|
3
17
|
specs:
|
@@ -8,10 +22,10 @@ GEM
|
|
8
22
|
activemodel (= 4.1.14)
|
9
23
|
activesupport (= 4.1.14)
|
10
24
|
arel (~> 5.0.0)
|
11
|
-
activeresource (4.
|
25
|
+
activeresource (4.1.0)
|
12
26
|
activemodel (~> 4.0)
|
13
27
|
activesupport (~> 4.0)
|
14
|
-
rails-observers (~> 0.1.
|
28
|
+
rails-observers (~> 0.1.2)
|
15
29
|
activesupport (4.1.14)
|
16
30
|
i18n (~> 0.6, >= 0.6.9)
|
17
31
|
json (~> 1.7, >= 1.7.7)
|
@@ -19,8 +33,8 @@ GEM
|
|
19
33
|
thread_safe (~> 0.1)
|
20
34
|
tzinfo (~> 1.1)
|
21
35
|
arel (5.0.1.20140414130214)
|
22
|
-
attr_encrypted (1.3.
|
23
|
-
encryptor (
|
36
|
+
attr_encrypted (1.3.5)
|
37
|
+
encryptor (~> 1.3.0)
|
24
38
|
builder (3.2.2)
|
25
39
|
byebug (8.2.1)
|
26
40
|
dotenv (2.0.2)
|
@@ -30,31 +44,32 @@ GEM
|
|
30
44
|
multipart-post (>= 1.2, < 3)
|
31
45
|
foreman (0.78.0)
|
32
46
|
thor (~> 0.19.1)
|
33
|
-
hashie (3.4.
|
47
|
+
hashie (3.4.6)
|
34
48
|
i18n (0.7.0)
|
35
49
|
json (1.8.3)
|
36
|
-
jwt (1.5.
|
50
|
+
jwt (1.5.1)
|
37
51
|
metaclass (0.0.4)
|
38
52
|
minitest (5.8.3)
|
39
53
|
mocha (1.1.0)
|
40
54
|
metaclass (~> 0.0.1)
|
41
55
|
mono_logger (1.1.0)
|
42
|
-
multi_json (1.
|
43
|
-
multi_xml (0.
|
56
|
+
multi_json (1.12.1)
|
57
|
+
multi_xml (0.6.0)
|
44
58
|
multipart-post (2.0.0)
|
45
|
-
oauth2 (1.
|
59
|
+
oauth2 (1.1.0)
|
46
60
|
faraday (>= 0.8, < 0.10)
|
47
|
-
jwt (~> 1.0)
|
61
|
+
jwt (~> 1.0, < 1.5.2)
|
48
62
|
multi_json (~> 1.3)
|
49
63
|
multi_xml (~> 0.5)
|
50
|
-
rack (
|
51
|
-
omniauth (1.
|
64
|
+
rack (>= 1.2, < 3)
|
65
|
+
omniauth (1.3.2)
|
52
66
|
hashie (>= 1.2, < 4)
|
53
|
-
rack (
|
67
|
+
rack (>= 1.0, < 3)
|
54
68
|
omniauth-oauth2 (1.4.0)
|
55
69
|
oauth2 (~> 1.0)
|
56
70
|
omniauth (~> 1.2)
|
57
|
-
omniauth-shopify-oauth2 (1.1.
|
71
|
+
omniauth-shopify-oauth2 (1.1.16)
|
72
|
+
oauth2 (~> 1.1.0)
|
58
73
|
omniauth-oauth2 (~> 1.2)
|
59
74
|
pg (0.18.4)
|
60
75
|
rack (1.6.4)
|
@@ -67,7 +82,7 @@ GEM
|
|
67
82
|
rails-observers (0.1.2)
|
68
83
|
activemodel (~> 4.0)
|
69
84
|
rake (10.4.2)
|
70
|
-
redis (3.
|
85
|
+
redis (3.3.2)
|
71
86
|
redis-namespace (1.5.2)
|
72
87
|
redis (~> 3.0, >= 3.0.4)
|
73
88
|
resque (1.25.2)
|
@@ -76,17 +91,6 @@ GEM
|
|
76
91
|
redis-namespace (~> 1.3)
|
77
92
|
sinatra (>= 0.9.2)
|
78
93
|
vegas (~> 0.1.2)
|
79
|
-
shopify-sinatra-app (0.2.0)
|
80
|
-
activesupport (~> 4.1.1)
|
81
|
-
attr_encrypted (~> 1.3.2)
|
82
|
-
omniauth-shopify-oauth2 (~> 1.1.11)
|
83
|
-
rack-flash3 (~> 1.0.5)
|
84
|
-
resque (~> 1.25.2)
|
85
|
-
shopify_api (~> 4.0.2)
|
86
|
-
sinatra (~> 1.4.6)
|
87
|
-
sinatra-activerecord (~> 2.0.9)
|
88
|
-
sinatra-redis (~> 0.3.0)
|
89
|
-
sinatra-twitter-bootstrap (~> 2.3.3)
|
90
94
|
shopify_api (4.0.7)
|
91
95
|
activeresource
|
92
96
|
rack
|
@@ -100,7 +104,6 @@ GEM
|
|
100
104
|
sinatra-redis (0.3.0)
|
101
105
|
redis
|
102
106
|
sinatra (>= 0.9.4)
|
103
|
-
sinatra-twitter-bootstrap (2.3.4)
|
104
107
|
sqlite3 (1.3.11)
|
105
108
|
thor (0.19.1)
|
106
109
|
thread_safe (0.3.5)
|
@@ -124,9 +127,12 @@ DEPENDENCIES
|
|
124
127
|
rack-flash3
|
125
128
|
rack-test
|
126
129
|
rake
|
127
|
-
shopify-sinatra-app
|
130
|
+
shopify-sinatra-app!
|
128
131
|
sinatra-activerecord
|
129
132
|
sqlite3
|
130
133
|
|
134
|
+
RUBY VERSION
|
135
|
+
ruby 2.3.1p112
|
136
|
+
|
131
137
|
BUNDLED WITH
|
132
|
-
1.
|
138
|
+
1.13.6
|
data/example/views/install.erb
CHANGED
@@ -29,9 +29,11 @@
|
|
29
29
|
|
30
30
|
<div class="container">
|
31
31
|
<form role="form" class="form-large" action="/login" method="post">
|
32
|
-
<div class="input-
|
33
|
-
<input class="form-control
|
34
|
-
<
|
32
|
+
<div class="input-group form-wide">
|
33
|
+
<input class="form-control" type="url" name="shop" placeholder="Shop URL">
|
34
|
+
<span class="input-group-btn">
|
35
|
+
<input class="btn" type="submit" value="Install App" />
|
36
|
+
</span>
|
35
37
|
</div>
|
36
38
|
</form>
|
37
39
|
</div>
|
@@ -87,9 +87,9 @@ module Sinatra
|
|
87
87
|
end
|
88
88
|
|
89
89
|
def authenticate(return_to = '/')
|
90
|
-
if shop_name =
|
90
|
+
if shop_name = sanitized_shop_name
|
91
91
|
redirect_url = "/auth/shopify?shop=#{shop_name}&return_to=#{base_url}#{return_to}"
|
92
|
-
|
92
|
+
redirect_javascript redirect_url
|
93
93
|
else
|
94
94
|
redirect '/install'
|
95
95
|
end
|
@@ -106,12 +106,38 @@ module Sinatra
|
|
106
106
|
shop.save
|
107
107
|
end
|
108
108
|
|
109
|
-
def
|
110
|
-
|
109
|
+
def redirect_javascript(url)
|
110
|
+
erb %(
|
111
|
+
<!DOCTYPE html>
|
112
|
+
<html lang="en">
|
113
|
+
<head>
|
114
|
+
<meta charset="utf-8" />
|
115
|
+
<base target="_top">
|
116
|
+
<title>Redirecting…</title>
|
117
|
+
|
118
|
+
<script type='text/javascript'>
|
119
|
+
// If the current window is the 'parent', change the URL by setting location.href
|
120
|
+
if (window.top == window.self) {
|
121
|
+
window.top.location.href = #{url.to_json};
|
122
|
+
|
123
|
+
// If the current window is the 'child', change the parent's URL with postMessage
|
124
|
+
} else {
|
125
|
+
message = JSON.stringify({
|
126
|
+
message: 'Shopify.API.remoteRedirect',
|
127
|
+
data: { location: window.location.origin + #{url.to_json} }
|
128
|
+
});
|
129
|
+
window.parent.postMessage(message, 'https://#{sanitized_shop_name}');
|
130
|
+
}
|
131
|
+
</script>
|
132
|
+
</head>
|
133
|
+
<body>
|
134
|
+
</body>
|
135
|
+
</html>
|
136
|
+
%), layout: false
|
137
|
+
end
|
111
138
|
|
112
|
-
|
113
|
-
|
114
|
-
</script>", layout: false
|
139
|
+
def sanitized_shop_name
|
140
|
+
@sanitized_shop_name ||= sanitize_shop_param(params)
|
115
141
|
end
|
116
142
|
|
117
143
|
def sanitize_shop_param(params)
|
@@ -179,7 +205,6 @@ module Sinatra
|
|
179
205
|
provider :shopify,
|
180
206
|
app.settings.api_key,
|
181
207
|
app.settings.shared_secret,
|
182
|
-
redirect_uri: app.settings.redirect_uri,
|
183
208
|
|
184
209
|
scope: app.settings.scope,
|
185
210
|
|
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.3.
|
4
|
+
version: 0.3.1
|
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: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -282,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
282
|
version: '0'
|
283
283
|
requirements: []
|
284
284
|
rubyforge_project:
|
285
|
-
rubygems_version: 2.
|
285
|
+
rubygems_version: 2.5.1
|
286
286
|
signing_key:
|
287
287
|
specification_version: 4
|
288
288
|
summary: A classy shopify app
|