lucid_intercom 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: 887d45cc3d09ea51187cf003b7943c49ac225c0b883aa3884f8e4ec2adaa4ee1
4
- data.tar.gz: 5c849447b48a0e201bc64e728f1a37fbd1e2c5248d2d7e5afc7959babae76a9a
3
+ metadata.gz: ae5331c5e43c8500eba29e4aa59eb888b5cf36eb688e4261bb36a03e69c73668
4
+ data.tar.gz: 512c22f9afc0ca22de424e8e7cb05620c962c97902c03f0f5ca700176be7f386
5
5
  SHA512:
6
- metadata.gz: 61d8acb02a990db111ab103d0f195bd17049b51fad579508d3579187298d025e2c845edb753b05b768b19209d25ed7d024db4e0a3c14a117ee6e3aba418f5988
7
- data.tar.gz: 3f6fd95024f71fbaa47df6972044c99e81bcf1135b5ffe66cfe98687d6ba4ff6f7e5a39c0c566a42503d8e1fe16c51e4c5abfd30406ddba52b16d8112f7b3b53
6
+ metadata.gz: 275bf250cc1623219ccc046a0209f7b3dc3424eba9b0ea7facdb293115b52c1048f7b974c01058e0c3110eee5cc0712542e116db445cc41ecff6aa4471b90552
7
+ data.tar.gz: 5b933a4d0827a816cceec0ebcee906e2d5fffafb6d2b3472f4c64da792433e64a6bf05aec32ab46fb3dd8433e2720677b65cbd2d9d0daab49bcc0631a9c9c0c2
@@ -15,7 +15,6 @@ require 'lucid_intercom/post_request.rb'
15
15
  require 'lucid_intercom/render_snippet.rb'
16
16
  require 'lucid_intercom/response.rb'
17
17
  require 'lucid_intercom/send_event.rb'
18
- require 'lucid_intercom/snippet.html.erb'
19
18
  require 'lucid_intercom/uninstalled_event.rb'
20
19
  require 'lucid_intercom/update_user.rb'
21
20
  require 'lucid_intercom/user_attributes.rb'
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'erb'
4
-
5
3
  require 'lucid_intercom/config'
6
4
 
7
5
  module LucidIntercom
8
6
  class RenderSnippet
9
- TEMPLATE = ERB.new(File.read("#{__dir__}/snippet.html.erb")).freeze
7
+ TEMPLATE = File.read("#{__dir__}/snippet.html").freeze
10
8
 
11
9
  #
12
10
  # @param shopify_data [Hash] shop attributes as returned by the Shopify API
@@ -21,30 +19,25 @@ module LucidIntercom
21
19
  # @return [String]
22
20
  #
23
21
  def call(shopify_data = {}, app_data = {})
24
- company = CompanyAttributes.new(shopify_data).to_h(browser: true)
25
- company_custom = CompanyCustomAttributes.new(shopify_data, app_data).to_h
26
- user = UserAttributes.new(shopify_data).to_h(browser: true)
27
-
28
- TEMPLATE.result(binding)
22
+ settings = shopify_data.empty? ? unauthenticated_settings : {
23
+ **unauthenticated_settings,
24
+ **UserAttributes.new(shopify_data).to_h(browser: true),
25
+ company: CompanyAttributes.new(shopify_data).to_h(browser: true).merge(CompanyCustomAttributes.new(shopify_data, app_data).to_h)
26
+ }
27
+
28
+ TEMPLATE % {
29
+ settings: settings.to_json,
30
+ app_id: settings[:app_id],
31
+ }
29
32
  end
30
33
 
31
34
  #
32
- # Quote and escape a value for JavaScript.
33
- #
34
- # @param obj [Object]
35
- #
36
- # @return [Object]
35
+ # @return [Hash]
37
36
  #
38
- def escape(obj)
39
- return obj unless obj.is_a?(String)
40
-
41
- s = obj.gsub(/./) do |c|
42
- return c unless %w(" ' / < > \\).include?(c)
43
-
44
- "\\#{c}"
45
- end
46
-
47
- "\"#{s}\""
37
+ private def unauthenticated_settings
38
+ {
39
+ app_id: LucidIntercom.app_id,
40
+ }
48
41
  end
49
42
  end
50
43
  end
@@ -0,0 +1,2 @@
1
+ <script>window.intercomSettings=%{settings};</script>
2
+ <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==='function'){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/%{app_id}';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidIntercom
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-30 00:00:00.000000000 Z
11
+ date: 2018-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -101,7 +101,7 @@ files:
101
101
  - lib/lucid_intercom/render_snippet.rb
102
102
  - lib/lucid_intercom/response.rb
103
103
  - lib/lucid_intercom/send_event.rb
104
- - lib/lucid_intercom/snippet.html.erb
104
+ - lib/lucid_intercom/snippet.html
105
105
  - lib/lucid_intercom/uninstalled_event.rb
106
106
  - lib/lucid_intercom/update_user.rb
107
107
  - lib/lucid_intercom/user_attributes.rb
@@ -1,2 +0,0 @@
1
- <script>window.intercomSettings={app_id:'<%= LucidIntercom.app_id %>',<% if attributes %><% user.each do |k, v| %><%= k %>:<%= escape v %>,<% end %>company:{<% company.each do |k, v| %><%= k %>:<%= escape v %>,<% end %><% company_custom.each do |k, v| %><%= k %>:<%= escape v %>,<% end %>},<% end %>};</script>
2
- <script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==='function'){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/<%= LucidIntercom.app_id %>';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script>