shopify_app 4.4.6 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d016076a4a542e4eaa1c2ceae28cbe7e1790bd42
4
- data.tar.gz: 2842f923938f4849ad339f03523324c19553ac0e
3
+ metadata.gz: 5c13d2dc552acb4d83345cfa79458bacf0e7c289
4
+ data.tar.gz: 37d1d7d575a20c3e6ec31a74c5218890c16bcb6e
5
5
  SHA512:
6
- metadata.gz: 0581d9b17e081a8ad0606f659e87eabe08b46bb94a0ef41a493198545be521b1faf38fe48a701f74a3be5336ca695d0e74f99a3d46e890c6e8cc836ee1238edf
7
- data.tar.gz: e1a8be720c1550592197518593f386fce7f9ec7b5666df00627a950a2b194da683793198d24aa323535122c30228607451bbeb4f78cfe3dd5480eb7b7c9f825d
6
+ metadata.gz: 435f36ef8b451587c3b44ee238ef62cac08beccb1123159d9290618f9011ccb5e8b423d11417eab6a1f84dbc5621615cd3845e82a898d505e6d945c35a3b2fb4
7
+ data.tar.gz: 32f20ae9da3e54e4241eeccb5bbe52c63cc3454911749630e72fe8ba89c4415b81ff731bc040f941175b85f70c4d45436626f368df315e2a8c7688e97d9dd01f
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Shopify App
2
2
 
3
+ [![Build Status](https://travis-ci.org/Shopify/shopify_app.png)](https://travis-ci.org/Shopify/shopify_app)
4
+
3
5
  Shopify application generator for Rails 3.1 and Rails 4.0
4
6
 
5
7
  ## Description
@@ -72,6 +74,42 @@ common:
72
74
  secret: your secret
73
75
  ```
74
76
 
77
+ ## Set up your ShopifySessionRepository.store
78
+
79
+ `ShopifySessionRepository` allows you as a developer to define how your sessions are retrieved and
80
+ stored for a shop. This can simply be your `Shop` model that stores the API Token and shop name. If
81
+ you are using ActiveRecord, then all you need to implement is `self.store(shopify_session)` and
82
+ `self.retrieve(id)` in order to store the record on disk or retrieve it for use at a later point.
83
+ It is imperative that your store method returns the identifier for the session. Typically this is
84
+ just the record ID.
85
+
86
+ Your ActiveRecord model would look something like this:
87
+
88
+ ```ruby
89
+ class Shop < ActiveRecord::Base
90
+ def self.store(session)
91
+ shop = Shop.new(domain: session.url, token: session.token)
92
+ shop.save!
93
+ shop.id
94
+ end
95
+
96
+ def retrieve(id)
97
+ shop = Shop.find(id)
98
+ ShopifyAPI::Session.new(shop.domain, shop.token)
99
+ end
100
+ end
101
+ ```
102
+
103
+ By default you will have an in memory store but it really won't work on multi-server environments since
104
+ they won't be sharing the static data that would be required in case your user gets directed to a
105
+ different server by your load balancer.
106
+
107
+ The in memory store also does not behave well on Heroku because the session data would be destroyed
108
+ when a dyno is killed due to inactivity.
109
+
110
+ Changing the `ShopifySessionRepository.storage` can simply be done by editing
111
+ `config/initializers/shopify_session_repository.rb` to use the correct model.
112
+
75
113
  ## Set your required API permissions
76
114
 
77
115
  Before making API requests, your application must state which API permissions it requires from the shop it's installed in. These requested permissions will be listed on the screen the merchant sees when approving your app to be installed in their shop.
@@ -10,7 +10,7 @@ class SessionsController < ApplicationController
10
10
  def show
11
11
  if response = request.env['omniauth.auth']
12
12
  sess = ShopifyAPI::Session.new(params[:shop], response['credentials']['token'])
13
- session[:shopify] = sess
13
+ session[:shopify] = ShopifySessionRepository.store(sess)
14
14
  flash[:notice] = "Logged in"
15
15
  redirect_to return_address
16
16
  else
@@ -0,0 +1,21 @@
1
+ # You should replace InMemorySessionStore with what you will be using
2
+ # in Production
3
+ #
4
+ # Interface to implement are self.retrieve(id) and self.store(ShopifyAPI::Session)
5
+ #
6
+ # Here is how you would add these functions to an ActiveRecord:
7
+ #
8
+ # class Shop < ActiveRecord::Base
9
+ # def self.store(session)
10
+ # shop = Shop.new(domain: session.url, token: session.token)
11
+ # shop.save!
12
+ # shop.id
13
+ # end
14
+ #
15
+ # def retrieve(id)
16
+ # shop = Shop.find(id)
17
+ # ShopifyAPI::Session.new(shop.domain, shop.token)
18
+ # end
19
+ # end
20
+
21
+ ShopifySessionRepository.storage = InMemorySessionStore
data/lib/shopify_app.rb CHANGED
@@ -12,6 +12,8 @@ module ShopifyApp
12
12
  end
13
13
  end
14
14
 
15
+ require 'shopify_app/shopify_session_repository'
16
+ require 'shopify_app/in_memory_session_store'
15
17
  require 'shopify_app/login_protection'
16
18
  require 'shopify_app/configuration'
17
19
  require 'shopify_app/railtie'
@@ -0,0 +1,25 @@
1
+ # WARNING - This really only works for development, see README for more details
2
+ class InMemorySessionStore
3
+ class EnvironmentError < StandardError; end
4
+
5
+ def self.retrieve(id)
6
+ repo[id]
7
+ end
8
+
9
+ def self.store(session)
10
+ id = SecureRandom.uuid
11
+ repo[id] = session
12
+ id
13
+ end
14
+
15
+ def self.clear
16
+ @@repo = nil
17
+ end
18
+
19
+ def self.repo
20
+ if Rails.env.production?
21
+ raise EnvironmentError.new("Cannot use InMemorySessionStore in a Production environment")
22
+ end
23
+ @@repo ||= {}
24
+ end
25
+ end
@@ -6,10 +6,10 @@ module ShopifyApp::LoginProtection
6
6
  end
7
7
 
8
8
  def shopify_session
9
- if session[:shopify]
9
+ if shop_session
10
10
  begin
11
11
  # session[:shopify] set in LoginController#show
12
- ShopifyAPI::Base.activate_session(session[:shopify])
12
+ ShopifyAPI::Base.activate_session(shop_session)
13
13
  yield
14
14
  ensure
15
15
  ShopifyAPI::Base.clear_session
@@ -21,7 +21,7 @@ module ShopifyApp::LoginProtection
21
21
  end
22
22
 
23
23
  def shop_session
24
- session[:shopify]
24
+ ShopifySessionRepository.retrieve(session[:shopify])
25
25
  end
26
26
 
27
27
  def login_again_if_different_shop
@@ -0,0 +1,22 @@
1
+ class ShopifySessionRepository
2
+ class ConfigurationError < StandardError; end
3
+
4
+ def self.storage=(storage)
5
+ @@storage = storage
6
+ end
7
+
8
+ def self.retrieve(id)
9
+ validate
10
+ @@storage.retrieve(id)
11
+ end
12
+
13
+ def self.store(session)
14
+ validate
15
+ @@storage.store(session)
16
+ end
17
+
18
+ def self.validate
19
+ raise ConfigurationError.new("ShopifySessionRepository.store is not configured!") unless @@storage
20
+ end
21
+
22
+ end
@@ -1,3 +1,3 @@
1
1
  module ShopifyApp
2
- VERSION = "4.4.6"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ConfigurationTest < MiniTest::Unit::TestCase
3
+ class ConfigurationTest < Minitest::Test
4
4
  def setup
5
5
  Rails.stubs(:env).returns('development')
6
6
  Rails.stubs(:root).returns(File.expand_path('../..', File.dirname(__FILE__)))
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class InMemorySessionStoreTest < Minitest::Test
4
+ def teardown
5
+ InMemorySessionStore.clear
6
+ end
7
+
8
+ def test_storing_a_session
9
+ uuid = InMemorySessionStore.store('something')
10
+ assert_equal 'something', InMemorySessionStore.repo[uuid]
11
+ end
12
+
13
+ def test_retrieving_a_session
14
+ InMemorySessionStore.repo['abra'] = 'something'
15
+ assert_equal 'something', InMemorySessionStore.retrieve('abra')
16
+ end
17
+
18
+ def test_clearing_the_store
19
+ uuid = InMemorySessionStore.store('data')
20
+ assert_equal 'data', InMemorySessionStore.retrieve(uuid)
21
+ InMemorySessionStore.clear
22
+ assert !InMemorySessionStore.retrieve(uuid), 'The sessions should have been removed'
23
+ end
24
+
25
+ def test_it_should_raise_when_the_environment_is_not_valid
26
+ Rails.env.stubs(:production?).returns(true)
27
+ assert_raises InMemorySessionStore::EnvironmentError do
28
+ InMemorySessionStore.store('data')
29
+ end
30
+
31
+ assert_raises InMemorySessionStore::EnvironmentError do
32
+ InMemorySessionStore.retrieve('abracadabra')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ class TestSessionStore
4
+ attr_reader :storage
5
+ def initialize
6
+ @storage = []
7
+ end
8
+
9
+ def retrieve(id)
10
+ storage[id]
11
+ end
12
+
13
+ def store(session)
14
+ id = storage.length
15
+ storage[id] = session
16
+ id
17
+ end
18
+ end
19
+
20
+ class ShopifySessionRepositoryTest < Minitest::Test
21
+ attr_reader :session_store, :session
22
+ def setup
23
+ @session_store = TestSessionStore.new
24
+ @session = ShopifyAPI::Session.new('shop.myshopify.com', 'abracadabra')
25
+ ShopifySessionRepository.storage = session_store
26
+ end
27
+
28
+ def teardown
29
+ ShopifySessionRepository.storage = nil
30
+ end
31
+
32
+ def test_adding_a_session_to_the_repository
33
+ assert_equal 0, ShopifySessionRepository.store(session)
34
+ assert_equal session, session_store.retrieve(0)
35
+ end
36
+
37
+ def test_retrieving_a_session_from_the_repository
38
+ session_store.storage[9] = session
39
+ assert_equal session, ShopifySessionRepository.retrieve(9)
40
+ end
41
+
42
+ def test_retrieving_a_session_for_an_id_that_does_not_exist
43
+ ShopifySessionRepository.store(session)
44
+ assert !ShopifySessionRepository.retrieve(100), "The session with id 100 should not exist in the Repository"
45
+ end
46
+
47
+ def test_retrieving_a_session_for_a_misconfigured_shops_repository
48
+ ShopifySessionRepository.storage = nil
49
+ assert_raises ShopifySessionRepository::ConfigurationError do
50
+ ShopifySessionRepository.retrieve(0)
51
+ end
52
+
53
+ assert_raises ShopifySessionRepository::ConfigurationError do
54
+ ShopifySessionRepository.store(session)
55
+ end
56
+ end
57
+ end
data/test/test_helper.rb CHANGED
@@ -2,4 +2,4 @@ require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
3
  require 'mocha/setup'
4
4
 
5
- require File.expand_path('../../lib/shopify_app.rb', __FILE__)
5
+ require File.expand_path('../../lib/shopify_app.rb', __FILE__)
metadata CHANGED
@@ -1,139 +1,117 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.6
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MQ8wDQYDV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hc4KdE2JqzCPOsS4zsZGhgwhPs
30
- fl3hbtVFTqbOlwL9vy1fudXcolIE/ZTcxQ+er07ZFZdKCXayR9PPs64heamfn0fp
31
- TConQSX2BnZdhIEYW+cKzEC/bLc=
32
- -----END CERTIFICATE-----
33
- date: 2014-05-27 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2014-06-09 00:00:00.000000000 Z
34
12
  dependencies:
35
13
  - !ruby/object:Gem::Dependency
36
14
  name: rails
37
15
  requirement: !ruby/object:Gem::Requirement
38
16
  requirements:
39
- - - ">="
17
+ - - '>='
40
18
  - !ruby/object:Gem::Version
41
19
  version: '3.1'
42
- - - "<"
20
+ - - <
43
21
  - !ruby/object:Gem::Version
44
22
  version: '5.0'
45
23
  type: :runtime
46
24
  prerelease: false
47
25
  version_requirements: !ruby/object:Gem::Requirement
48
26
  requirements:
49
- - - ">="
27
+ - - '>='
50
28
  - !ruby/object:Gem::Version
51
29
  version: '3.1'
52
- - - "<"
30
+ - - <
53
31
  - !ruby/object:Gem::Version
54
32
  version: '5.0'
55
33
  - !ruby/object:Gem::Dependency
56
34
  name: shopify_api
57
35
  requirement: !ruby/object:Gem::Requirement
58
36
  requirements:
59
- - - "~>"
37
+ - - ~>
60
38
  - !ruby/object:Gem::Version
61
39
  version: 3.2.0
62
40
  type: :runtime
63
41
  prerelease: false
64
42
  version_requirements: !ruby/object:Gem::Requirement
65
43
  requirements:
66
- - - "~>"
44
+ - - ~>
67
45
  - !ruby/object:Gem::Version
68
46
  version: 3.2.0
69
47
  - !ruby/object:Gem::Dependency
70
48
  name: omniauth-shopify-oauth2
71
49
  requirement: !ruby/object:Gem::Requirement
72
50
  requirements:
73
- - - "~>"
51
+ - - ~>
74
52
  - !ruby/object:Gem::Version
75
53
  version: 1.1.4
76
54
  type: :runtime
77
55
  prerelease: false
78
56
  version_requirements: !ruby/object:Gem::Requirement
79
57
  requirements:
80
- - - "~>"
58
+ - - ~>
81
59
  - !ruby/object:Gem::Version
82
60
  version: 1.1.4
83
61
  - !ruby/object:Gem::Dependency
84
62
  name: less-rails-bootstrap
85
63
  requirement: !ruby/object:Gem::Requirement
86
64
  requirements:
87
- - - "~>"
65
+ - - ~>
88
66
  - !ruby/object:Gem::Version
89
67
  version: '2.0'
90
68
  type: :runtime
91
69
  prerelease: false
92
70
  version_requirements: !ruby/object:Gem::Requirement
93
71
  requirements:
94
- - - "~>"
72
+ - - ~>
95
73
  - !ruby/object:Gem::Version
96
74
  version: '2.0'
97
75
  - !ruby/object:Gem::Dependency
98
76
  name: rake
99
77
  requirement: !ruby/object:Gem::Requirement
100
78
  requirements:
101
- - - ">="
79
+ - - '>='
102
80
  - !ruby/object:Gem::Version
103
81
  version: '0'
104
82
  type: :development
105
83
  prerelease: false
106
84
  version_requirements: !ruby/object:Gem::Requirement
107
85
  requirements:
108
- - - ">="
86
+ - - '>='
109
87
  - !ruby/object:Gem::Version
110
88
  version: '0'
111
89
  - !ruby/object:Gem::Dependency
112
90
  name: minitest
113
91
  requirement: !ruby/object:Gem::Requirement
114
92
  requirements:
115
- - - ">="
93
+ - - '>='
116
94
  - !ruby/object:Gem::Version
117
95
  version: '0'
118
96
  type: :development
119
97
  prerelease: false
120
98
  version_requirements: !ruby/object:Gem::Requirement
121
99
  requirements:
122
- - - ">="
100
+ - - '>='
123
101
  - !ruby/object:Gem::Version
124
102
  version: '0'
125
103
  - !ruby/object:Gem::Dependency
126
104
  name: mocha
127
105
  requirement: !ruby/object:Gem::Requirement
128
106
  requirements:
129
- - - ">="
107
+ - - '>='
130
108
  - !ruby/object:Gem::Version
131
109
  version: '0'
132
110
  type: :development
133
111
  prerelease: false
134
112
  version_requirements: !ruby/object:Gem::Requirement
135
113
  requirements:
136
- - - ">="
114
+ - - '>='
137
115
  - !ruby/object:Gem::Version
138
116
  version: '0'
139
117
  description: Creates a basic sessions controller for authenticating with your Shop
@@ -146,7 +124,7 @@ executables: []
146
124
  extensions: []
147
125
  extra_rdoc_files: []
148
126
  files:
149
- - ".gitignore"
127
+ - .gitignore
150
128
  - CHANGELOG
151
129
  - Gemfile
152
130
  - LICENSE
@@ -180,6 +158,7 @@ files:
180
158
  - lib/generators/shopify_app/templates/app/views/layouts/application.html.erb
181
159
  - lib/generators/shopify_app/templates/app/views/sessions/new.html.erb
182
160
  - lib/generators/shopify_app/templates/config/initializers/omniauth.rb
161
+ - lib/generators/shopify_app/templates/config/initializers/shopify_session_repository.rb
183
162
  - lib/generators/shopify_app/templates/public/404.html
184
163
  - lib/generators/shopify_app/templates/public/422.html
185
164
  - lib/generators/shopify_app/templates/public/500.html
@@ -189,8 +168,10 @@ files:
189
168
  - lib/generators/shopify_app/templates/public/shopify-72.png
190
169
  - lib/shopify_app.rb
191
170
  - lib/shopify_app/configuration.rb
171
+ - lib/shopify_app/in_memory_session_store.rb
192
172
  - lib/shopify_app/login_protection.rb
193
173
  - lib/shopify_app/railtie.rb
174
+ - lib/shopify_app/shopify_session_repository.rb
194
175
  - lib/shopify_app/version.rb
195
176
  - shipit.rubygems.yml
196
177
  - shopify_app.gemspec
@@ -199,6 +180,8 @@ files:
199
180
  - test/config/other_config_file.yml
200
181
  - test/config/shopify_app.yml
201
182
  - test/lib/shopify_app/configuration_test.rb
183
+ - test/lib/shopify_app/in_memory_session_store_test.rb
184
+ - test/lib/shopify_app/shopify_session_repository_test.rb
202
185
  - test/test_helper.rb
203
186
  homepage: http://www.shopify.com/developers
204
187
  licenses: []
@@ -209,18 +192,26 @@ require_paths:
209
192
  - lib
210
193
  required_ruby_version: !ruby/object:Gem::Requirement
211
194
  requirements:
212
- - - ">="
195
+ - - '>='
213
196
  - !ruby/object:Gem::Version
214
197
  version: '0'
215
198
  required_rubygems_version: !ruby/object:Gem::Requirement
216
199
  requirements:
217
- - - ">="
200
+ - - '>='
218
201
  - !ruby/object:Gem::Version
219
202
  version: '0'
220
203
  requirements: []
221
204
  rubyforge_project: shopify-api
222
- rubygems_version: 2.2.0
205
+ rubygems_version: 2.2.2
223
206
  signing_key:
224
207
  specification_version: 4
225
208
  summary: This gem is used to get quickly started with the Shopify API
226
- test_files: []
209
+ test_files:
210
+ - test/config/development_config_file.yml
211
+ - test/config/empty_config_file.yml
212
+ - test/config/other_config_file.yml
213
+ - test/config/shopify_app.yml
214
+ - test/lib/shopify_app/configuration_test.rb
215
+ - test/lib/shopify_app/in_memory_session_store_test.rb
216
+ - test/lib/shopify_app/shopify_session_repository_test.rb
217
+ - test/test_helper.rb
checksums.yaml.gz.sig DELETED
Binary file
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
Binary file