shopify_app 7.0.0 → 7.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b6ad0f2e17e02639259c5664e451a46bb524e304
4
- data.tar.gz: 7cc21860a23e3d3f9bc21dfe90782dac008354c6
3
+ metadata.gz: 406b509cf830a10344fbec7876cc12c04a09355d
4
+ data.tar.gz: 8d2dcdf08c31159a37cd31f7881f87ef2eec9fdc
5
5
  SHA512:
6
- metadata.gz: ce081c615bd1d21b213c27cdd3b62ac3fd7f8200aa1aa20204222b0616d741e4af52c535a73c954a93fb3d0c8ed581a34588be8b90306b143b1a04d8f9c2f4cd
7
- data.tar.gz: 816f9259c2e32e8a39749f26d3c031839e88a1d0f57f0393a3013820a8a23916331dc6793e2d859b9be11ea8cfdc2467e6bca06469f8803ef8e0e296832ddce5
6
+ metadata.gz: e9fd9a832f80592c40f31cef8f5454ab445dc98c6ee0d5dcb19ae20dcb657580a620bb7a13adda5e2da3d54439e9f8b0a1cb8d87ee846a6657bbd5ed1f364035
7
+ data.tar.gz: 28aad6022b5daef4dddd1edabcd8a1f782142c8dfdb64e7b560a780b601f08a3795fb741eacbe4e190f3310293a8e262bb705fbf69fbaf9592f4aef35fc8e34a
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ 7.0.1
2
+ ----------
3
+ * add support to i18n for flash messages (English and Spanish).
4
+
1
5
  7.0.0
2
6
  ----------
3
7
 
data/README.md CHANGED
@@ -175,6 +175,21 @@ rails g shopify_app:add_webhook -t carts/update -a https://example.com/webhooks/
175
175
 
176
176
  where `-t` is the topic and `-a` is the address the webhook should be sent to.
177
177
 
178
+ ScripttagsManager
179
+ -----------------
180
+
181
+ As with webhooks, ShopifyApp can manage your app's scripttags for you by setting which scripttags you require in the initializer:
182
+
183
+ ```ruby
184
+ ShopifyApp.configure do |config|
185
+ config.scripttags = [
186
+ {event:'onload', src: 'https://my-shopifyapp.herokuapp.com/fancy.js'}
187
+ ]
188
+ end
189
+ ```
190
+
191
+ Scripttags are created in the same way as the Webhooks, with a background job which will create the required scripttags.
192
+
178
193
  ShopifyApp::SessionRepository
179
194
  -----------------------------
180
195
 
@@ -0,0 +1,4 @@
1
+ en:
2
+ logged_in: 'Logged In'
3
+ logged_out: 'Successfully logged out'
4
+ could_not_log_in: 'Could not log in to Shopify store'
@@ -0,0 +1,4 @@
1
+ es:
2
+ logged_in: 'Has iniciado sesión'
3
+ logged_out: 'Cerrar sesión'
4
+ could_not_log_in: 'No se pudo iniciar sesión en tu tienda de Shopify'
data/lib/shopify_app.rb CHANGED
@@ -12,6 +12,7 @@ require 'shopify_app/engine'
12
12
 
13
13
  # jobs
14
14
  require 'shopify_app/webhooks_manager_job'
15
+ require 'shopify_app/scripttags_manager_job'
15
16
 
16
17
  # helpers and concerns
17
18
  require 'shopify_app/shop'
@@ -19,6 +20,7 @@ require 'shopify_app/session_storage'
19
20
  require 'shopify_app/sessions_concern'
20
21
  require 'shopify_app/login_protection'
21
22
  require 'shopify_app/webhooks_manager'
23
+ require 'shopify_app/scripttags_manager'
22
24
  require 'shopify_app/webhook_verification'
23
25
  require 'shopify_app/utils'
24
26
 
@@ -10,6 +10,7 @@ module ShopifyApp
10
10
  attr_accessor :embedded_app
11
11
  alias_method :embedded_app?, :embedded_app
12
12
  attr_accessor :webhooks
13
+ attr_accessor :scripttags
13
14
 
14
15
  # configure myshopify domain for local shopify development
15
16
  attr_accessor :myshopify_domain
@@ -21,6 +22,10 @@ module ShopifyApp
21
22
  def has_webhooks?
22
23
  webhooks.present?
23
24
  end
25
+
26
+ def has_scripttags?
27
+ scripttags.present?
28
+ end
24
29
  end
25
30
 
26
31
  def self.configuration
@@ -0,0 +1,68 @@
1
+ module ShopifyApp
2
+ class ScripttagsManager
3
+ class CreationFailed < StandardError; end
4
+
5
+ def self.queue(shop_name, token)
6
+ ShopifyApp::ScripttagsManagerJob.perform_later(shop_name: shop_name, token: token)
7
+ end
8
+
9
+ def initialize(shop_name, token)
10
+ @shop_name, @token = shop_name, token
11
+ end
12
+
13
+ def recreate_scripttags!
14
+ destroy_scripttags
15
+ create_scripttags
16
+ end
17
+
18
+ def create_scripttags
19
+ return unless required_scripttags.present?
20
+
21
+ with_shopify_session do
22
+ required_scripttags.each do |scripttag|
23
+ create_scripttag(scripttag) unless scripttag_exists?(scripttag[:src])
24
+ end
25
+ end
26
+ end
27
+
28
+ def destroy_scripttags
29
+ with_shopify_session do
30
+ ShopifyAPI::ScriptTag.all.each do |scripttag|
31
+ ShopifyAPI::ScriptTag.delete(scripttag.id) if is_required_scripttag?(scripttag)
32
+ end
33
+ end
34
+ @current_scripttags = nil
35
+ end
36
+
37
+ private
38
+
39
+ def required_scripttags
40
+ ShopifyApp.configuration.scripttags
41
+ end
42
+
43
+ def is_required_scripttag?(scripttag)
44
+ required_scripttags.map{ |w| w[:src] }.include? scripttag.src
45
+ end
46
+
47
+ def with_shopify_session
48
+ ShopifyAPI::Session.temp(@shop_name, @token) do
49
+ yield
50
+ end
51
+ end
52
+
53
+ def create_scripttag(attributes)
54
+ attributes.reverse_merge!(format: 'json')
55
+ scripttag = ShopifyAPI::ScriptTag.create(attributes)
56
+ raise CreationFailed, scripttag.errors.full_messages.to_sentence unless scripttag.persisted?
57
+ scripttag
58
+ end
59
+
60
+ def scripttag_exists?(src)
61
+ current_scripttags[src]
62
+ end
63
+
64
+ def current_scripttags
65
+ @current_scripttags ||= ShopifyAPI::ScriptTag.all.index_by(&:src)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,11 @@
1
+ module ShopifyApp
2
+ class ScripttagsManagerJob < ActiveJob::Base
3
+ def perform(params = {})
4
+ shop_name = params.fetch(:shop_name)
5
+ token = params.fetch(:token)
6
+
7
+ manager = ScripttagsManager.new(shop_name, token)
8
+ manager.create_scripttags
9
+ end
10
+ end
11
+ end
@@ -20,11 +20,12 @@ module ShopifyApp
20
20
  session[:shopify_domain] = shop_name
21
21
 
22
22
  WebhooksManager.queue(shop_name, token) if ShopifyApp.configuration.has_webhooks?
23
+ ScripttagsManager.queue(shop_name, token) if ShopifyApp.configuration.has_scripttags?
23
24
 
24
- flash[:notice] = "Logged in"
25
+ flash[:notice] = I18n.t('.logged_in')
25
26
  redirect_to_with_fallback return_address
26
27
  else
27
- flash[:error] = "Could not log in to Shopify store."
28
+ flash[:error] = I18n.t('could_not_log_in')
28
29
  redirect_to_with_fallback login_url
29
30
  end
30
31
  end
@@ -32,7 +33,7 @@ module ShopifyApp
32
33
  def destroy
33
34
  session[:shopify] = nil
34
35
  session[:shopify_domain] = nil
35
- flash[:notice] = "Successfully logged out."
36
+ flash[:notice] = I18n.t('.logged_out')
36
37
  redirect_to_with_fallback login_url
37
38
  end
38
39
 
@@ -1,3 +1,3 @@
1
1
  module ShopifyApp
2
- VERSION = '7.0.0'
2
+ VERSION = '7.0.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shopify_app
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -148,6 +148,8 @@ files:
148
148
  - app/controllers/shopify_app/sessions_controller.rb
149
149
  - app/controllers/shopify_app/webhooks_controller.rb
150
150
  - app/views/shopify_app/sessions/new.html.erb
151
+ - config/locales/en.yml
152
+ - config/locales/es.yml
151
153
  - config/routes.rb
152
154
  - lib/generators/shopify_app/add_webhook/add_webhook_generator.rb
153
155
  - lib/generators/shopify_app/add_webhook/templates/webhook_job.rb
@@ -177,6 +179,8 @@ files:
177
179
  - lib/shopify_app/engine.rb
178
180
  - lib/shopify_app/in_memory_session_store.rb
179
181
  - lib/shopify_app/login_protection.rb
182
+ - lib/shopify_app/scripttags_manager.rb
183
+ - lib/shopify_app/scripttags_manager_job.rb
180
184
  - lib/shopify_app/session_storage.rb
181
185
  - lib/shopify_app/sessions_concern.rb
182
186
  - lib/shopify_app/shop.rb