sinatra-shopify 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/lib/sinatra/shopify.rb +81 -0
- data/sinatra-shopify.gemspec +18 -0
- metadata +97 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jesse Storimer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Sinatra-Shopify: A classy shopify_app
|
2
|
+
====================================
|
3
|
+
|
4
|
+
This is a Sinatra extension that allows you to work with the "Shopify API":http://shopify.com/developers. It's basically just a port of the "shopify_app":http://github.com/Shopify/shopify_app rails plugin to sinatra.
|
5
|
+
|
6
|
+
== Why?
|
7
|
+
|
8
|
+
I have been "having fun working on Shopify apps":http://www.jstorimer.com/blogs/my-blog/1133402-shopify-api-extensions lately, but I needed a simpler way than always generating a new rails app, new controllers, etc., for every little idea.
|
9
|
+
|
10
|
+
Rails is great, but most of the "Shopify apps":http://apps.shopify.com that I have come up with are one page apps, maybe two or three pages. The point is, I don't need a controller for that, I don't need the 63 files or however many the rails generator generates for me.
|
11
|
+
|
12
|
+
Sinatra is most awesome when you are working on a small app with just a few routes. You can clone this app and use it as a starting point for a shopify_app. All of the authentication logic/routes are in the lib folder, so they don't pollute the code of your app.
|
13
|
+
|
14
|
+
So in app.rb, you just have to worry about the functionality of your app.
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
Installable from rubygems as 'sinatra-shopify'.
|
19
|
+
|
20
|
+
The current implementation for authentication is to add the @authorize!@ method at the top of any routes that you want to be authenticated, like so:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
get '/sensitive_data' do
|
24
|
+
authorize!
|
25
|
+
|
26
|
+
# then do the sensitive stuff
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
Example
|
31
|
+
======
|
32
|
+
|
33
|
+
This repo includes an example Sinatra app. The fastest way to get it running:
|
34
|
+
|
35
|
+
* @git clone git://github.com/jstorimer/sinatra-shopify@
|
36
|
+
* @cd sinatra-shopify@
|
37
|
+
* @heroku create@ (make sure that you remember the name of your app as you will need that later)
|
38
|
+
* visit the "Shopify Partners area":http://app.shopify.com/services/partners
|
39
|
+
* Sign up for an account if you don't already have one
|
40
|
+
* Log in to your Shopify partners account
|
41
|
+
* Create a new application.
|
42
|
+
* Make sure that the Callback URL is set to http://_yourapp_.heroku.com/login/finalize
|
43
|
+
* In the lib/sinatra/shopify.yml file replace API_KEY and SECRET with the Api Key and Secret that you just got from the Shopify Partners area
|
44
|
+
* @git push heroku master@
|
45
|
+
* @heroku open@
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'shopify_api'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module Shopify
|
6
|
+
|
7
|
+
module Helpers
|
8
|
+
def current_shop
|
9
|
+
session[:shopify]
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorize!
|
13
|
+
redirect '/login' unless current_shop
|
14
|
+
|
15
|
+
ShopifyAPI::Base.site = session[:shopify].site
|
16
|
+
end
|
17
|
+
|
18
|
+
def logout!
|
19
|
+
session[:shopify] = nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.registered(app)
|
24
|
+
app.helpers Shopify::Helpers
|
25
|
+
app.enable :sessions
|
26
|
+
|
27
|
+
app.template :login do
|
28
|
+
<<-SRC
|
29
|
+
<h1>Login</h1>
|
30
|
+
|
31
|
+
<p>
|
32
|
+
First you have to register this app with a shop to allow access to its private admin data.
|
33
|
+
</p>
|
34
|
+
|
35
|
+
<form action='/login/authenticate' method='post'>
|
36
|
+
<label for='shop'><strong>The URL of the Shop</strong>
|
37
|
+
<span class="hint">(or just the subdomain if it's at myshopify.com)</span>
|
38
|
+
</label>
|
39
|
+
<p>
|
40
|
+
<input type='text' name='shop' />
|
41
|
+
</p>
|
42
|
+
<input type='submit' value='Authenticate' />
|
43
|
+
</form>
|
44
|
+
SRC
|
45
|
+
end
|
46
|
+
|
47
|
+
unless ENV['SHOPIFY_API_KEY'] && ENV['SHOPIFY_API_SECRET']
|
48
|
+
puts "Set your Shopify api_key and secret via ENV['SHOPIFY_API_KEY'] and ENV['SHOPIFY_API_SECRET']"
|
49
|
+
end
|
50
|
+
ShopifyAPI::Session.setup(:api_key => ENV['SHOPIFY_API_KEY'], :secret => ENV['SHOPIFY_API_SECRET'])
|
51
|
+
|
52
|
+
app.get '/login' do
|
53
|
+
erb :login
|
54
|
+
end
|
55
|
+
|
56
|
+
app.get '/logout' do
|
57
|
+
logout!
|
58
|
+
redirect '/'
|
59
|
+
end
|
60
|
+
|
61
|
+
app.post '/login/authenticate' do
|
62
|
+
redirect ShopifyAPI::Session.new(params[:shop]).create_permission_url
|
63
|
+
end
|
64
|
+
|
65
|
+
app.get '/login/finalize' do
|
66
|
+
shopify_session = ShopifyAPI::Session.new(params[:shop], params[:t])
|
67
|
+
if shopify_session.valid?
|
68
|
+
session[:shopify] = shopify_session
|
69
|
+
|
70
|
+
return_address = session[:return_to] || '/'
|
71
|
+
session[:return_to] = nil
|
72
|
+
redirect return_address
|
73
|
+
else
|
74
|
+
redirect '/login'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
register Shopify
|
81
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'sinatra-shopify'
|
3
|
+
s.version = '1.0.0'
|
4
|
+
|
5
|
+
s.summary = "A classy shopify_app"
|
6
|
+
s.description = "A Sinatra extension for working with the Shopify API. Akin to the shopify_app gem but for Sinatra"
|
7
|
+
|
8
|
+
s.authors = ["Jesse Storimer"]
|
9
|
+
s.email = "jesse@gmail.com"
|
10
|
+
s.homepage = "https://github.com/jstorimer/sinatra-shopify/"
|
11
|
+
|
12
|
+
s.files = Dir.glob('lib/**/*.rb')
|
13
|
+
s.files += ['README.md', 'LICENSE', 'sinatra-shopify.gemspec']
|
14
|
+
|
15
|
+
s.add_dependency 'sinatra', '~> 1.0'
|
16
|
+
s.add_dependency 'shopify_api', '~> 1.2'
|
17
|
+
end
|
18
|
+
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-shopify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jesse Storimer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-06-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: sinatra
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: "1.0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: shopify_api
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 11
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 2
|
47
|
+
version: "1.2"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
description: A Sinatra extension for working with the Shopify API. Akin to the shopify_app gem but for Sinatra
|
51
|
+
email: jesse@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- lib/sinatra/shopify.rb
|
60
|
+
- README.md
|
61
|
+
- LICENSE
|
62
|
+
- sinatra-shopify.gemspec
|
63
|
+
homepage: https://github.com/jstorimer/sinatra-shopify/
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.8.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: A classy shopify_app
|
96
|
+
test_files: []
|
97
|
+
|