intercom-rails 0.3.2 → 0.3.3

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: 08651bb54d9b9c588783f70646f08de114e2d7fc
4
- data.tar.gz: 9bb02e0bdcb79a59d7e3a5ba6cde2ad7f5982caa
3
+ metadata.gz: fad8f8d2ec8aa23c29149ded67376d397692901d
4
+ data.tar.gz: bcc4e82069fe43a4058dee9aba24d30976f2f002
5
5
  SHA512:
6
- metadata.gz: 72371243fbae2337000a1f3eb7dbf0beb32bb98ff3cf08b1430f04e7f7be2e755685910518742ae884a605359927247e6b2adcdba6d5da51d3bc08e5a231368c
7
- data.tar.gz: a5b853032d971f3c50ef477982f065f3c55b3739ebc02a64f91e91f432b05c466e9ab08c37a76aabf305d2f4b6cbab6744a9613772adb51cbd3104db6d5af805
6
+ metadata.gz: 46d75b65e5324ef4df39e0858d2ae8d76186acb325a51b63e41237d2bc17d936dd6e4bedf4c3bbbb88c64d29b9eb4c021022117a30ddfdb41f069d524b03a262
7
+ data.tar.gz: 6a5707a85610968b143730224ae3ffc90af1bd49ceafc7b97d82c87a2214877ef71d0a80eeb2e18f25e050f7dcff16d3f51c71866f96898fd84facee3444bbc8
@@ -17,13 +17,21 @@ Then run:
17
17
  bundle install
18
18
  ```
19
19
 
20
- Take note of your `app_id` from [here](https://app.intercom.io/apps/api_keys) and generate a config file:
20
+ Take note of your `app_id` from [here](https://app.intercom.io/a/apps/_/settings/api-keys) and generate a config file:
21
21
 
22
22
  ```
23
23
  rails generate intercom:config YOUR-APP-ID
24
24
  ```
25
25
 
26
- To make installing Intercom as easy as possible, where possible a `<script>` tag **will be automatically inserted before the closing `</body>` tag**. For most Rails apps, **you won't need to do any extra config**. Having trouble? Check out troubleshooting below.
26
+ To make installing Intercom easy, where possible a `<script>` tag **will be automatically inserted before the closing `</body>` tag**. For most Rails apps, **you won't need to do any extra config**. Having trouble? Check out troubleshooting below.
27
+
28
+
29
+ ### Live Chat / Acquire
30
+ With our [Acquire package](https://www.intercom.io/live-chat), Intercom Messenger now works with logged out users and visitors to your web site. Include the Intercom snippet on every page by setting:
31
+
32
+ ```ruby
33
+ config.include_for_logged_out_users = true
34
+ ```
27
35
 
28
36
  ### Disabling automatic insertion
29
37
 
@@ -151,6 +159,8 @@ e.g.
151
159
  :is_paid => Proc.new { |user| user.plan.present? },
152
160
  :email_verified => :email_verified?
153
161
  }
162
+ # or If User::custom_data method returns a hash
163
+ config.user.custom_data = Proc.new { |user| user.custom_data }
154
164
  ```
155
165
 
156
166
  In some situations you'll want to set some custom data attribute specific to a request.
@@ -230,13 +240,6 @@ config.company.custom_data = {
230
240
  }
231
241
  ```
232
242
 
233
- ### Live Chat / Acquire
234
- With our [Acquire package](https://www.intercom.io/live-chat), Intercom Messenger now works with logged out users and visitors to your web site. Include the Intercom snippet on every page by setting:
235
-
236
- ```ruby
237
- config.include_for_logged_out_users = true
238
- ```
239
-
240
243
  ### Messenger
241
244
  Intercom includes an in-app messenger which allows a user to read messages and start conversations.
242
245
 
@@ -258,6 +261,12 @@ You can customize the CSS selector, by setting
258
261
  config.inbox.custom_activator = '.intercom-link'
259
262
  ```
260
263
 
264
+ You can hide default launcher button, by setting
265
+
266
+ ```ruby
267
+ config.hide_default_launcher = true
268
+ ```
269
+
261
270
  You can read more about configuring the messenger in your applications settings, within Intercom.
262
271
 
263
272
  ### Environments
@@ -363,6 +372,24 @@ The SHA-256 hash is available using `csp_sha256` just after generating the tag i
363
372
  <% add_entry_to_csp_whitelist(intercom_script_tag.csp_sha256) %>
364
373
  ```
365
374
 
375
+ ## Deleting your users
376
+ If you delete a user from your system, you should also delete them from Intercom lest they still receive messages.
377
+
378
+ You can do this using the [intercom-ruby](https://github.com/intercom/intercom-ruby) gem. In the example below we're using an ActiveJob to perform the delete in the background.
379
+
380
+ ```
381
+ class User
382
+ after_destroy { DeleteFromIntercom.perform_later(self)
383
+ end
384
+
385
+ class DeleteFromIntercom < ApplicationJob
386
+ def perform(user)
387
+ intercom = Intercom::Client.new
388
+ intercom.users.find(email: user.email).delete
389
+ end
390
+ end
391
+ ```
392
+
366
393
  ## Running tests/specs
367
394
 
368
395
  specs should run on a clean clone of this repo, using the following commands. (developed against ruby 2.1.2 and 1.9.3)
@@ -374,6 +401,24 @@ or
374
401
  bundle exec rspec spec/
375
402
  ```
376
403
 
404
+
405
+ ## Pull Requests
406
+
407
+ - **Add tests!** Your patch won't be accepted if it doesn't have tests.
408
+
409
+ - **Document any change in behaviour**. Make sure the README and any other
410
+ relevant documentation are kept up-to-date.
411
+
412
+ - **Create topic branches**. Don't ask us to pull from your master branch.
413
+
414
+ - **One pull request per feature**. If you want to do more than one thing, send
415
+ multiple pull requests.
416
+
417
+ - **Send coherent history**. Make sure each individual commit in your pull
418
+ request is meaningful. If you had to make multiple intermediate commits while
419
+ developing, please squash them before sending them to us.
420
+
421
+
377
422
  ## Contributors
378
423
 
379
424
  - Dr Nic Williams (@drnic) - provided a rails generator for adding the Intercom javascript tag into your layout.
@@ -32,7 +32,9 @@ module IntercomRails
32
32
  end
33
33
 
34
34
  def include_javascript!
35
- response.body = response.body.gsub(CLOSING_BODY_TAG, intercom_script_tag.to_s + '\\0')
35
+ split = response.body.split("</body>")
36
+ response.body = split.first + intercom_script_tag.to_s + "</body>"
37
+ response.body = response.body + split.last if split.size > 1
36
38
  end
37
39
 
38
40
  def include_javascript?
@@ -21,13 +21,7 @@ module IntercomRails
21
21
 
22
22
  def self.config_writer(name, &block)
23
23
  meta_class.send(:define_method, "#{name}=") do |value|
24
- block.call(value) if block && (block.arity <= 1)
25
-
26
- if block && (block.arity > 1)
27
- field_name = underscored_class_name ? "#{underscored_class_name}.#{name}" : name
28
- block.call(value, field_name)
29
- end
30
-
24
+ validate(name, value, block)
31
25
  instance_variable_set("@#{name}", value)
32
26
  end
33
27
  end
@@ -45,6 +39,17 @@ module IntercomRails
45
39
  end
46
40
 
47
41
  private
42
+
43
+ def self.validate(name, value, block)
44
+ return unless block
45
+ args = [value]
46
+ if block.arity > 1
47
+ field_name = underscored_class_name ? "#{underscored_class_name}.#{name}" : name
48
+ args << field_name
49
+ end
50
+ block.call(*args)
51
+ end
52
+
48
53
  def self.underscored_class_name
49
54
  @underscored_class_name
50
55
  end
@@ -54,9 +59,14 @@ module IntercomRails
54
59
  class Config < ConfigSingleton
55
60
 
56
61
  CUSTOM_DATA_VALIDATOR = Proc.new do |custom_data, field_name|
57
- raise ArgumentError, "#{field_name} custom_data should be a hash" unless custom_data.kind_of?(Hash)
58
- unless custom_data.values.all? { |value| value.kind_of?(Proc) || value.kind_of?(Symbol) }
59
- raise ArgumentError, "all custom_data attributes should be either a Proc or a symbol"
62
+ case custom_data
63
+ when Hash
64
+ unless custom_data.values.all? { |value| value.kind_of?(Proc) || value.kind_of?(Symbol) }
65
+ raise ArgumentError, "all custom_data attributes should be either a Proc or a symbol"
66
+ end
67
+ when Proc, Symbol
68
+ else
69
+ raise ArgumentError, "#{field_name} custom_data should be either be a hash or a Proc/Symbol that returns a hash when called"
60
70
  end
61
71
  end
62
72
 
@@ -97,6 +107,7 @@ module IntercomRails
97
107
  config_accessor :library_url
98
108
  config_accessor :enabled_environments, &ARRAY_VALIDATOR
99
109
  config_accessor :include_for_logged_out_users
110
+ config_accessor :hide_default_launcher
100
111
 
101
112
  def self.api_key=(*)
102
113
  warn "Setting an Intercom API key is no longer supported; remove the `config.api_key = ...` line from config/initializers/intercom.rb"
@@ -116,6 +127,7 @@ module IntercomRails
116
127
 
117
128
  config_group :company do
118
129
  config_accessor :current, &IS_PROC_VALIDATOR
130
+ config_accessor :exclude_if, &IS_PROC_VALIDATOR
119
131
  config_accessor :plan, &IS_PROC_VALIDATOR
120
132
  config_accessor :monthly_spend, &IS_PROC_VALIDATOR
121
133
  config_accessor :custom_data, &CUSTOM_DATA_VALIDATOR
@@ -3,6 +3,7 @@ module IntercomRails
3
3
  def self.convert_dates_to_unix_timestamps(object)
4
4
  return Hash[object.map { |k, v| [k, convert_dates_to_unix_timestamps(v)] }] if object.is_a?(Hash)
5
5
  return object.to_i if object.is_a?(Time) || object.is_a?(DateTime)
6
+ return object.to_time.to_i if object.is_a?(Date)
6
7
  object
7
8
  end
8
9
  end
@@ -129,16 +129,19 @@ module IntercomRails
129
129
 
130
130
  def custom_data_from_config
131
131
  return {} if config.custom_data.blank?
132
- config.custom_data.reduce({}) do |custom_data, (k,v)|
133
- custom_data.merge(k => custom_data_value_from_proc_or_symbol(v))
134
- end
135
- end
136
-
137
- def custom_data_value_from_proc_or_symbol(proc_or_symbol)
138
- if proc_or_symbol.kind_of?(Symbol)
139
- proxied_object.send(proc_or_symbol)
140
- elsif proc_or_symbol.kind_of?(Proc)
141
- proc_or_symbol.call(proxied_object)
132
+ custom_data_value(config.custom_data)
133
+ end
134
+
135
+ def custom_data_value(proc_or_symbol_or_hash)
136
+ case proc_or_symbol_or_hash
137
+ when Symbol
138
+ proxied_object.send(proc_or_symbol_or_hash)
139
+ when Proc
140
+ proc_or_symbol_or_hash.call(proxied_object)
141
+ when Hash
142
+ proc_or_symbol_or_hash.reduce({}) do |custom_data, (k,v)|
143
+ custom_data.merge(k => custom_data_value(v))
144
+ end
142
145
  end
143
146
  end
144
147
 
@@ -24,6 +24,8 @@ module IntercomRails
24
24
  end
25
25
 
26
26
  def valid?
27
+ return false if company.blank? || company.respond_to?(:new_record?) && company.new_record?
28
+ return false if config.company.exclude_if.present? && config.company.exclude_if.call(company)
27
29
  company.present? && identity_present?
28
30
  end
29
31
 
@@ -64,6 +64,7 @@ module IntercomRails
64
64
  hsh[:session_duration] = @session_duration if @session_duration.present?
65
65
  hsh[:widget] = widget_options if widget_options.present?
66
66
  hsh[:company] = company_details if company_details.present?
67
+ hsh[:hide_default_launcher] = Config.hide_default_launcher if Config.hide_default_launcher
67
68
  hsh
68
69
  end
69
70
 
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
@@ -84,6 +84,11 @@ IntercomRails.config do |config|
84
84
  #
85
85
  # config.company.current = Proc.new { current_user.company }
86
86
 
87
+ # == Exclude company
88
+ # A Proc that given a company returns true if the company should be excluded
89
+ # from imports and Javascript inclusion, false otherwise.
90
+ #
91
+ # config.company.exclude_if = Proc.new { |app| app.subdomain == 'demo' }
87
92
 
88
93
  # == Company Custom Data
89
94
  # A hash of additional data you wish to send about a company.
@@ -119,4 +124,7 @@ IntercomRails.config do |config|
119
124
  # uncomment this line and clicks on any element that matches the query will
120
125
  # open the messenger
121
126
  # config.inbox.custom_activator = '.intercom'
127
+ #
128
+ # If you'd like to hide default launcher button uncomment this line
129
+ # config.hide_default_launcher = true
122
130
  end
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
@@ -10,146 +10,146 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-06-28 00:00:00.000000000 Z
13
+ date: 2016-10-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - ">"
19
+ - - '>'
20
20
  - !ruby/object:Gem::Version
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - ">"
26
+ - - '>'
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.0'
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: rake
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - ">="
33
+ - - '>='
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
36
  type: :development
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
- - - ">="
40
+ - - '>='
41
41
  - !ruby/object:Gem::Version
42
42
  version: '0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: actionpack
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">"
47
+ - - '>'
48
48
  - !ruby/object:Gem::Version
49
49
  version: 3.2.12
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - ">"
54
+ - - '>'
55
55
  - !ruby/object:Gem::Version
56
56
  version: 3.2.12
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: rspec
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - "~>"
61
+ - - ~>
62
62
  - !ruby/object:Gem::Version
63
63
  version: '3.1'
64
64
  type: :development
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
- - - "~>"
68
+ - - ~>
69
69
  - !ruby/object:Gem::Version
70
70
  version: '3.1'
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec-rails
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
- - - "~>"
75
+ - - ~>
76
76
  - !ruby/object:Gem::Version
77
77
  version: '3.1'
78
78
  type: :development
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - "~>"
82
+ - - ~>
83
83
  - !ruby/object:Gem::Version
84
84
  version: '3.1'
85
85
  - !ruby/object:Gem::Dependency
86
86
  name: pry
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ">="
89
+ - - '>='
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  type: :development
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
- - - ">="
96
+ - - '>='
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  - !ruby/object:Gem::Dependency
100
100
  name: sinatra
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
103
+ - - ~>
104
104
  - !ruby/object:Gem::Version
105
105
  version: 1.4.5
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - "~>"
110
+ - - ~>
111
111
  - !ruby/object:Gem::Version
112
112
  version: 1.4.5
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: thin
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - "~>"
117
+ - - ~>
118
118
  - !ruby/object:Gem::Version
119
- version: 1.6.2
119
+ version: 1.7.0
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - "~>"
124
+ - - ~>
125
125
  - !ruby/object:Gem::Version
126
- version: 1.6.2
126
+ version: 1.7.0
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: tzinfo
129
129
  requirement: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - ">="
131
+ - - '>='
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">="
138
+ - - '>='
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: gem-release
143
143
  requirement: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ">="
145
+ - - '>='
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  type: :development
149
149
  prerelease: false
150
150
  version_requirements: !ruby/object:Gem::Requirement
151
151
  requirements:
152
- - - ">="
152
+ - - '>='
153
153
  - !ruby/object:Gem::Version
154
154
  version: '0'
155
155
  description: Intercom (https://www.intercom.io) is a customer relationship management
@@ -163,25 +163,25 @@ executables: []
163
163
  extensions: []
164
164
  extra_rdoc_files: []
165
165
  files:
166
- - README.mdown
167
- - Rakefile
168
166
  - lib/data/cacert.pem
169
- - lib/intercom-rails.rb
170
167
  - lib/intercom-rails/auto_include_filter.rb
171
168
  - lib/intercom-rails/config.rb
172
169
  - lib/intercom-rails/custom_data_helper.rb
173
170
  - lib/intercom-rails/date_helper.rb
174
171
  - lib/intercom-rails/exceptions.rb
175
- - lib/intercom-rails/proxy.rb
176
172
  - lib/intercom-rails/proxy/company.rb
177
173
  - lib/intercom-rails/proxy/user.rb
174
+ - lib/intercom-rails/proxy.rb
178
175
  - lib/intercom-rails/railtie.rb
179
176
  - lib/intercom-rails/script_tag.rb
180
177
  - lib/intercom-rails/script_tag_helper.rb
181
178
  - lib/intercom-rails/shutdown_helper.rb
182
179
  - lib/intercom-rails/version.rb
180
+ - lib/intercom-rails.rb
183
181
  - lib/rails/generators/intercom/config/config_generator.rb
184
182
  - lib/rails/generators/intercom/config/intercom.rb.erb
183
+ - Rakefile
184
+ - README.mdown
185
185
  homepage: http://www.intercom.io
186
186
  licenses:
187
187
  - MIT
@@ -192,17 +192,17 @@ require_paths:
192
192
  - lib
193
193
  required_ruby_version: !ruby/object:Gem::Requirement
194
194
  requirements:
195
- - - ">="
195
+ - - '>='
196
196
  - !ruby/object:Gem::Version
197
197
  version: '0'
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ">="
200
+ - - '>='
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  requirements: []
204
204
  rubyforge_project: intercom-rails
205
- rubygems_version: 2.5.1
205
+ rubygems_version: 2.0.14.1
206
206
  signing_key:
207
207
  specification_version: 4
208
208
  summary: Rails helper for emitting javascript script tags for Intercom