intercom-rails 0.2.33 → 0.2.34
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.mdown +49 -6
- data/lib/intercom-rails/config.rb +13 -1
- data/lib/intercom-rails/proxy/user.rb +5 -1
- data/lib/intercom-rails/script_tag.rb +1 -2
- data/lib/intercom-rails/shutdown_helper.rb +21 -2
- data/lib/intercom-rails/version.rb +1 -1
- data/lib/rails/generators/intercom/config/intercom.rb.erb +5 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf8138e7cf9f1c997403f95a28146cdac9404b2d
|
4
|
+
data.tar.gz: 9c551fd51c30b8416ade93d958f5e4577f96f38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f03ac8ed8936cfcaac4e0c373c3e0a2a8840efddba212c7cde24fa8436707f9b07de6ff1ef4cee5e899179ef51ab41265a5d3a44e66b5a371b565ffd697ea633
|
7
|
+
data.tar.gz: 99d4081d4157c022428e1509a5130d86c8eb25e69946451f66d740284609c8fc3991bc6e70e3e9b5da346bc2ae5ff11c470e44eba919c7bd0d3861dc55051fcd
|
data/README.mdown
CHANGED
@@ -44,6 +44,10 @@ If it's not working make sure:
|
|
44
44
|
```ruby
|
45
45
|
config.user.current = Proc.new { current_user_object }
|
46
46
|
```
|
47
|
+
If your users can be defined in different ways in your app you can also pass an array as follows :
|
48
|
+
```ruby
|
49
|
+
config.user.current = [Proc.new { current_user_object }, Proc.new { @user_object }]
|
50
|
+
```
|
47
51
|
* If you want the Intercom Messenger to be available when there is no current user, set `config.include_for_logged_out_users = true` in your config and sign up for the [Acquire](https://www.intercom.io/live-chat) package.
|
48
52
|
|
49
53
|
Feel free to mail us: team@intercom.io, if you're still having trouble.
|
@@ -64,23 +68,62 @@ Because of this, it’s very important to properly shutdown Intercom when a user
|
|
64
68
|
|
65
69
|
#### Using Devise
|
66
70
|
|
67
|
-
If
|
71
|
+
If you use devise, you can override (if not already done) the session_controller by replacing in your `config/routes.rb` file :
|
72
|
+
```ruby
|
73
|
+
devise_for :users
|
74
|
+
```
|
75
|
+
by
|
76
|
+
```ruby
|
77
|
+
devise_for :users, controllers: {sessions: "sessions"}
|
78
|
+
```
|
79
|
+
|
80
|
+
Then you can use the following code to prepare Intercom Shutdown on log out in your `app/session_controller.rb`
|
68
81
|
|
69
82
|
```ruby
|
70
|
-
|
83
|
+
class SessionsController < Devise::SessionsController
|
84
|
+
|
85
|
+
after_action :prepare_intercom_shutdown, only: [:destroy]
|
86
|
+
|
87
|
+
# Your logic here
|
88
|
+
|
89
|
+
protected
|
90
|
+
def prepare_intercom_shutdown
|
91
|
+
IntercomRails::ShutdownHelper.prepare_intercom_shutdown(session)
|
92
|
+
end
|
93
|
+
end
|
71
94
|
```
|
72
95
|
|
73
|
-
|
96
|
+
Assuming that the `destroy` method of session_controller redirects to your `visitors_controller.rb#index` method, edit your `visitors_controller` as follow :
|
97
|
+
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
class VisitorsController < ApplicationController
|
101
|
+
after_action :intercom_shutdown, only: [:index]
|
102
|
+
|
103
|
+
def index
|
104
|
+
# You logic here
|
105
|
+
end
|
106
|
+
|
107
|
+
# You logic here
|
108
|
+
|
109
|
+
protected
|
110
|
+
def intercom_shutdown
|
111
|
+
IntercomRails::ShutdownHelper.intercom_shutdown(session, cookies)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
```
|
74
115
|
|
75
116
|
#### Using another service
|
76
117
|
|
77
|
-
If you use another service than Devise or if you implemented your own authentication service, you can call the following method in a controller to shutdown Intercom on logout
|
78
|
-
**Be aware that if you call this method before a 'redirect_to' (quite common on logout) it will have no impact** as it is impossible to update cookies when you use a redirection.
|
118
|
+
If you use another service than Devise or if you implemented your own authentication service, you can call the following method in a controller to shutdown Intercom on logout.
|
79
119
|
|
80
120
|
```ruby
|
81
|
-
IntercomRails::ShutdownHelper::intercom_shutdown_helper(
|
121
|
+
IntercomRails::ShutdownHelper::intercom_shutdown_helper(cookies)
|
82
122
|
```
|
83
123
|
|
124
|
+
**Be aware that if you call this method before a 'redirect_to' (quite common on logout) it will have no impact** as it is impossible to update cookies when you use a redirection.
|
125
|
+
But you can use the same logic as the `devise` implementation above.
|
126
|
+
|
84
127
|
#### Session Duration
|
85
128
|
|
86
129
|
To add a `session_duration` variable (in ms) to the widget, add the following line to `config/initializers/intercom.rb`:
|
@@ -68,6 +68,18 @@ module IntercomRails
|
|
68
68
|
raise ArgumentError, "#{field_name} is not a proc" unless value.kind_of?(Proc)
|
69
69
|
end
|
70
70
|
|
71
|
+
IS_ARAY_OF_PROC_VALIDATOR = Proc.new do |data, field_name|
|
72
|
+
raise ArgumentError, "#{field_name} data should be a proc or an array of proc" unless data.all? { |value| value.kind_of?(Proc)}
|
73
|
+
end
|
74
|
+
|
75
|
+
IS_PROC_OR_ARRAY_OF_PROC_VALIDATOR = Proc.new do |data, field_name|
|
76
|
+
if data.kind_of?(Array)
|
77
|
+
IS_ARAY_OF_PROC_VALIDATOR.call(data, field_name)
|
78
|
+
else
|
79
|
+
IS_PROC_VALIDATOR.call(data, field_name)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
71
83
|
def self.reset!
|
72
84
|
to_reset = self.constants.map {|c| const_get c}
|
73
85
|
to_reset << self
|
@@ -88,7 +100,7 @@ module IntercomRails
|
|
88
100
|
config_accessor :include_for_logged_out_users
|
89
101
|
|
90
102
|
config_group :user do
|
91
|
-
config_accessor :current, &
|
103
|
+
config_accessor :current, &IS_PROC_OR_ARRAY_OF_PROC_VALIDATOR
|
92
104
|
config_accessor :exclude_if, &IS_PROC_VALIDATOR
|
93
105
|
config_accessor :model, &IS_PROC_VALIDATOR
|
94
106
|
config_accessor :company_association, &IS_PROC_VALIDATOR
|
@@ -16,7 +16,11 @@ module IntercomRails
|
|
16
16
|
|
17
17
|
def self.potential_user_objects
|
18
18
|
if config.current.present?
|
19
|
-
|
19
|
+
if config.current.kind_of?(Array)
|
20
|
+
config.current.map { |user| Proc.new { instance_eval &user } }
|
21
|
+
else
|
22
|
+
[Proc.new { instance_eval &IntercomRails.config.user.current }]
|
23
|
+
end
|
20
24
|
else
|
21
25
|
PREDEFINED_POTENTIAL_USER_OBJECTS
|
22
26
|
end
|
@@ -137,8 +137,7 @@ module IntercomRails
|
|
137
137
|
def app_id
|
138
138
|
return user_details[:app_id] if user_details[:app_id].present?
|
139
139
|
return IntercomRails.config.app_id if IntercomRails.config.app_id.present?
|
140
|
-
return 'abcd1234' if defined?(Rails) && Rails.env.development?
|
141
|
-
|
140
|
+
return 'abcd1234' if defined?(Rails) && (Rails.env.development? || Rails.env.test?)
|
142
141
|
nil
|
143
142
|
end
|
144
143
|
|
@@ -4,8 +4,27 @@ module IntercomRails
|
|
4
4
|
# It is recommanded to call this function every time a user log out of your application
|
5
5
|
# specifically if you use both "Acquire" and another Intercom product
|
6
6
|
# Do not use before a redirect_to because it will not clear the cookies on a redirection
|
7
|
-
def self.intercom_shutdown_helper
|
8
|
-
|
7
|
+
def self.intercom_shutdown_helper(cookies)
|
8
|
+
if (cookies.is_a?(ActionDispatch::Cookies::CookieJar))
|
9
|
+
cookies["intercom-session-#{IntercomRails.config.app_id}"] = { value: nil, expires: 1.day.ago}
|
10
|
+
else
|
11
|
+
controller = cookies
|
12
|
+
Rails.logger.info("Warning: IntercomRails::ShutdownHelper.intercom_shutdown_helper takes an instance of ActionDispatch::Cookies::CookieJar as an argument since v0.2.34. Passing a controller is depreciated. See https://github.com/intercom/intercom-rails#shutdown for more details.")
|
13
|
+
controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}", { value: nil, expires: 1.day.ago})
|
14
|
+
end
|
15
|
+
rescue
|
9
16
|
end
|
17
|
+
|
18
|
+
def self.prepare_intercom_shutdown(session)
|
19
|
+
session[:perform_intercom_shutdown] = true
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.intercom_shutdown(session, cookies)
|
23
|
+
if session[:perform_intercom_shutdown]
|
24
|
+
session.delete(:perform_intercom_shutdown)
|
25
|
+
intercom_shutdown_helper(cookies)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
10
29
|
end
|
11
30
|
end
|
@@ -5,8 +5,11 @@ IntercomRails.config do |config|
|
|
5
5
|
|
6
6
|
# == Intercom session_duration
|
7
7
|
#
|
8
|
+
<%- if @session_duration -%>
|
8
9
|
config.session_duration = <%= @session_duration %>
|
9
|
-
|
10
|
+
<%- else -%>
|
11
|
+
# config.session_duration = 300000
|
12
|
+
<%- end -%>
|
10
13
|
# == Intercom secret key
|
11
14
|
# This is required to enable secure mode, you can find it on your Setup
|
12
15
|
# guide in the "Secure Mode" step.
|
@@ -40,6 +43,7 @@ IntercomRails.config do |config|
|
|
40
43
|
config.user.current = Proc.new { <%= @current_user %> }
|
41
44
|
<%- else -%>
|
42
45
|
# config.user.current = Proc.new { current_user }
|
46
|
+
# config.user.current = [Proc.new { current_user }]
|
43
47
|
<%- end -%>
|
44
48
|
|
45
49
|
# == Include for logged out Users
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intercom-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.34
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben McRedmond
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-04-
|
13
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -204,9 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project: intercom-rails
|
207
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.4.8
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: Rails helper for emitting javascript script tags for Intercom
|
211
211
|
test_files: []
|
212
|
-
has_rdoc:
|