intercom-rails 0.2.31 → 0.2.33

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: 3aece6afdf71811d91c2971e43834534012c2dc0
4
- data.tar.gz: ee3a90363e1fe29bd1392cb8fa8942c535279655
3
+ metadata.gz: 03b50b1d5b763f0ef0a553e7d72d8daa1a3cd412
4
+ data.tar.gz: 4aacec38fd8a8696f56ee130487b9519959ea946
5
5
  SHA512:
6
- metadata.gz: 16b271674d1d3cd029e603e5855bb9b901edb3e4a61bfc353f3951ea4f3454c3e2484bedfeec79b324da07db2c471d21c41f10091cb0b3ce805fe3d00c553ed4
7
- data.tar.gz: 32818a64edc5805d05621e8ed6e0969cfc8862ffcb417bca5c8e46df5db8139790fd3d51b11b1fb21bc74f0dfbd430fc5d983ba2be1b95b883b628dfdf179c4b
6
+ metadata.gz: 5d80bc1ade277f6ea62376c67abd0185c30e9730fe2ba19b3132afb193229c3cbda4128e5d51566fa0a2a8adcdc0da975444651b52851f9717ce7ed313e7e728
7
+ data.tar.gz: 1a7bb15f5946f704f24a33007eda1dc19757bc78b7389c99c0f51dcb80665a73ab57f7717a5e8703338373ddfff783dd11363a12cd739623cdf659353b6237bf
data/README.mdown CHANGED
@@ -1,5 +1,7 @@
1
1
  # IntercomRails
2
2
 
3
+ [![Join the chat at https://gitter.im/intercom/intercom-rails](https://badges.gitter.im/intercom/intercom-rails.svg)](https://gitter.im/intercom/intercom-rails?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4
+
3
5
  The easiest way to install Intercom in a rails app.
4
6
 
5
7
  For interacting with the Intercom REST API, use the `intercom` gem (https://github.com/intercom/intercom-ruby)
@@ -54,8 +56,44 @@ If you want to use secure mode, ensure you set your API secret in `config/initia
54
56
  ```ruby
55
57
  config.api_secret = '123456'
56
58
  ```
59
+ **Note: This example is just for the sake of simplicity, you should never include your api secret in source control. Instead, you should use the Rails [secret config](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml) feature.**
60
+ ### Shutdown
61
+
62
+ If you use Intercom Acquire combined with another product like Support, Learn or Engage, any user that uses a shared computer and browser with someone else will be able to see the most recently logged in user’s conversation history until the cookie expires.
63
+ Because of this, it’s very important to properly shutdown Intercom when a user’s session on your app ends (via manually or automatically logging out).
64
+
65
+ #### Using Devise
66
+
67
+ If your Rails application uses devise for authentication, you simply need to add the following line in your "config/initializers/session_store.rb" :
68
+
69
+ ```ruby
70
+ Rails.application.config.session_store :cookie_store, key: 'intercom-session-' + IntercomRails.config.app_id
71
+ ```
72
+
73
+ You should not modify or remove existing configurations in this file.
74
+
75
+ #### Using another service
76
+
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 (self being the controller instance).
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.
79
+
80
+ ```ruby
81
+ IntercomRails::ShutdownHelper::intercom_shutdown_helper(self)
82
+ ```
83
+
84
+ #### Session Duration
85
+
86
+ To add a `session_duration` variable (in ms) to the widget, add the following line to `config/initializers/intercom.rb`:
87
+
88
+ ```ruby
89
+ config.session_duration = 5 * 60 * 1000
90
+ ```
91
+ That will force your Intercom session to expire after 5 minutes which is the minimum amount of time authorized.
92
+
93
+ More information about how session_duration works in [intercom documentation](https://docs.intercom.io/configuring-for-your-product-or-site/customizing-the-intercom-messenger#secure-user-conversations-configure-your-cookie-timeout)
57
94
 
58
95
  ### User Custom data attributes
96
+
59
97
  You can associate any attributes, specific to your app, with a user in Intercom.
60
98
  For custom data attributes you want updated on every request set them in `config/initializers/intercom.rb`, the latest value will be sent to Intercom on each page visit.
61
99
 
@@ -106,6 +144,10 @@ Basic usage is as follows - in `config/initializers/intercom.rb`
106
144
  config.company.current = Proc.new { current_company }
107
145
  ```
108
146
 
147
+ `current_company` is the method/variable that contains the user's current company in your controllers.
148
+ If you are using devise you should replace `current_company` with `current_user.company` in the above code and every time you see 'current_company' in your configuration file.
149
+ This will result in injecting the user current company in the widget settings.
150
+
109
151
  and like with Users, you can set custom attribute on companies too:
110
152
 
111
153
  ```ruby
@@ -247,14 +289,6 @@ The SHA-256 hash is available using `csp_sha256` just after generating the tag i
247
289
  <%= intercom_script_tag %>
248
290
  <% add_entry_to_csp_whitelist(intercom_script_tag.csp_sha256) %>
249
291
  ```
250
- ## Importing your users
251
- To get started faster with Intercom, `IntercomRails` includes a Rake task that will do an initial import of your users:
252
-
253
- ```
254
- rake intercom:import
255
- ```
256
-
257
- Any custom data defined in `config/initializers/intercom.rb` will also be sent.
258
292
 
259
293
  ## Running tests/specs
260
294
 
@@ -6,6 +6,7 @@ require 'intercom-rails/proxy/company'
6
6
  require 'intercom-rails/script_tag'
7
7
  require 'intercom-rails/script_tag_helper'
8
8
  require 'intercom-rails/custom_data_helper'
9
+ require 'intercom-rails/shutdown_helper'
9
10
  require 'intercom-rails/auto_include_filter'
10
11
  require 'intercom-rails/config'
11
12
  require 'intercom-rails/import'
@@ -80,6 +80,7 @@ module IntercomRails
80
80
  end
81
81
 
82
82
  config_accessor :app_id
83
+ config_accessor :session_duration
83
84
  config_accessor :api_secret
84
85
  config_accessor :api_key
85
86
  config_accessor :library_url
@@ -9,7 +9,7 @@ module IntercomRails
9
9
 
10
10
  include ::ActionView::Helpers::JavaScriptHelper
11
11
 
12
- attr_reader :user_details, :company_details, :show_everywhere
12
+ attr_reader :user_details, :company_details, :show_everywhere, :session_duration
13
13
  attr_accessor :secret, :widget_options, :controller, :nonce
14
14
 
15
15
  def initialize(options = {})
@@ -17,6 +17,7 @@ module IntercomRails
17
17
  self.widget_options = widget_options_from_config.merge(options[:widget] || {})
18
18
  self.controller = options[:controller]
19
19
  @show_everywhere = options[:show_everywhere]
20
+ @session_duration = session_duration_from_config
20
21
  self.user_details = options[:find_current_user_details] ? find_current_user_details : options[:user_details]
21
22
  self.company_details = if options[:find_current_company_details]
22
23
  find_current_company_details
@@ -56,6 +57,7 @@ module IntercomRails
56
57
 
57
58
  def intercom_settings
58
59
  hsh = user_details
60
+ hsh[:session_duration] = @session_duration if @session_duration.present?
59
61
  hsh[:widget] = widget_options if widget_options.present?
60
62
  hsh[:company] = company_details if company_details.present?
61
63
  hsh
@@ -121,6 +123,17 @@ module IntercomRails
121
123
  OpenSSL::HMAC.hexdigest("sha256", secret, (user_details[:user_id] || user_details[:email]).to_s)
122
124
  end
123
125
 
126
+ def session_duration_from_config
127
+ session_duration = IntercomRails.config.session_duration
128
+ if session_duration && valid_session_duration?(session_duration)
129
+ session_duration
130
+ end
131
+ end
132
+
133
+ def valid_session_duration?(session_duration)
134
+ session_duration.is_a?(Integer) && session_duration > 0
135
+ end
136
+
124
137
  def app_id
125
138
  return user_details[:app_id] if user_details[:app_id].present?
126
139
  return IntercomRails.config.app_id if IntercomRails.config.app_id.present?
@@ -0,0 +1,11 @@
1
+ module IntercomRails
2
+ module ShutdownHelper
3
+ # This helper allows to erase cookies when a user log out of an application
4
+ # It is recommanded to call this function every time a user log out of your application
5
+ # specifically if you use both "Acquire" and another Intercom product
6
+ # Do not use before a redirect_to because it will not clear the cookies on a redirection
7
+ def self.intercom_shutdown_helper (controller)
8
+ controller.response.delete_cookie("intercom-session-#{IntercomRails.config.app_id}")
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.2.31"
2
+ VERSION = "0.2.33"
3
3
  end
@@ -9,12 +9,14 @@ module Intercom
9
9
  argument :app_id, :desc => "Your Intercom app-id, which can be found here: https://app.intercom.io/apps/api_keys"
10
10
  argument :api_secret, :desc => "Your Intercom api-secret, used for secure mode", :optional => true
11
11
  argument :api_key, :desc => "An Intercom API key, for various rake tasks", :optional => true
12
+ argument :session_duration, :desc => "user session duration, this should match your app", :optional => true
12
13
 
13
14
  FALSEY_RESPONSES = ['n', 'no']
14
15
  def create_config_file
15
16
  @app_id = app_id
16
17
  @api_secret = api_secret
17
18
  @api_key = api_key
19
+ @session_duration = session_duration
18
20
  @include_for_logged_out_users = false
19
21
 
20
22
  introduction = <<-desc
@@ -3,6 +3,10 @@ IntercomRails.config do |config|
3
3
  #
4
4
  config.app_id = ENV["INTERCOM_APP_ID"] || "<%= @app_id %>"
5
5
 
6
+ # == Intercom session_duration
7
+ #
8
+ config.session_duration = <%= @session_duration %>
9
+
6
10
  # == Intercom secret key
7
11
  # This is required to enable secure mode, you can find it on your Setup
8
12
  # guide in the "Secure Mode" step.
@@ -71,6 +75,7 @@ IntercomRails.config do |config|
71
75
  # == User -> Company association
72
76
  # A Proc that given a user returns an array of companies
73
77
  # that the user belongs to.
78
+ # This is only used for importing users using rake command but it will not inject a list of companies in the intercom widget
74
79
  #
75
80
  # config.user.company_association = Proc.new { |user| user.companies.to_a }
76
81
  # config.user.company_association = Proc.new { |user| [user.company] }
@@ -81,6 +86,11 @@ IntercomRails.config do |config|
81
86
  # could be a company, app or group.
82
87
  #
83
88
  # config.company.current = Proc.new { current_company }
89
+ #
90
+ # Or if you are using devise you can just use the following config
91
+ #
92
+ # config.company.current = Proc.new { current_user.company }
93
+
84
94
 
85
95
  # == Company Custom Data
86
96
  # A hash of additional data you wish to send about a company.
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.31
4
+ version: 0.2.33
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-03-03 00:00:00.000000000 Z
13
+ date: 2016-04-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -180,11 +180,13 @@ files:
180
180
  - lib/intercom-rails/railtie.rb
181
181
  - lib/intercom-rails/script_tag.rb
182
182
  - lib/intercom-rails/script_tag_helper.rb
183
+ - lib/intercom-rails/shutdown_helper.rb
183
184
  - lib/intercom-rails/version.rb
184
185
  - lib/rails/generators/intercom/config/config_generator.rb
185
186
  - lib/rails/generators/intercom/config/intercom.rb.erb
186
187
  homepage: http://www.intercom.io
187
- licenses: []
188
+ licenses:
189
+ - MIT
188
190
  metadata: {}
189
191
  post_install_message:
190
192
  rdoc_options: []
@@ -202,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
204
  version: '0'
203
205
  requirements: []
204
206
  rubyforge_project: intercom-rails
205
- rubygems_version: 2.5.0
207
+ rubygems_version: 2.2.3
206
208
  signing_key:
207
209
  specification_version: 4
208
210
  summary: Rails helper for emitting javascript script tags for Intercom