intercom-rails 0.0.2 → 0.0.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.
- data/MIT-LICENSE +1 -1
- data/README.rdoc +15 -5
- data/lib/intercom-rails/script_tag_helper.rb +3 -1
- data/lib/intercom-rails/version.rb +1 -1
- data/test/intercom-rails/script_tag_helper_test.rb +8 -0
- metadata +8 -8
data/MIT-LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2011- Intercom
|
3
|
+
Copyright (c) 2011- Intercom, Inc. (https://www.intercom.io)
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.rdoc
CHANGED
@@ -9,9 +9,22 @@ Add this to your Gemfile:
|
|
9
9
|
|
10
10
|
gem "intercom-rails"
|
11
11
|
|
12
|
+
Then run:
|
13
|
+
|
12
14
|
<code>bundle install</code>
|
13
15
|
|
14
16
|
== Usage
|
17
|
+
|
18
|
+
Take note of your app_id from here: You can find your app id here: https://www.intercom.io/apps/api_keys
|
19
|
+
|
20
|
+
=== rails generator
|
21
|
+
|
22
|
+
The <strong>intercom:install</strong> rails generator will add <code>intercom_script_tag</code> to your application layout. It provides a great start that will work well for most people and is easily customised.
|
23
|
+
|
24
|
+
<code>rails g intercom:install YOUR-APP-ID</code>
|
25
|
+
|
26
|
+
=== manual install
|
27
|
+
|
15
28
|
In your layout file:
|
16
29
|
|
17
30
|
<% if logged_in? %>
|
@@ -29,13 +42,10 @@ In your layout file:
|
|
29
42
|
:custom_data allows you to specify any app/user/situational data to associate with the current_user. It will be visible in Intercom, and you'll be able to search/filter/send messages based on it.
|
30
43
|
|
31
44
|
e.g.
|
32
|
-
|
33
|
-
:plan => "Pro"
|
34
|
-
|
35
|
-
or
|
45
|
+
:plan => "Pro",
|
36
46
|
:dashboard_page => 'http://dashboard.example.com/user-id'
|
37
47
|
|
38
|
-
See IntercomRails::ScriptTagHelper for more details.
|
48
|
+
See {IntercomRails::ScriptTagHelper} for more details.
|
39
49
|
|
40
50
|
== Contributors
|
41
51
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "active_support/json"
|
2
|
+
require "active_support/core_ext/hash/indifferent_access"
|
2
3
|
|
3
4
|
module IntercomRails
|
4
5
|
# Helper methods for generating Intercom javascript script tags.
|
@@ -28,8 +29,9 @@ module IntercomRails
|
|
28
29
|
# {:activator => "#Intercom"}
|
29
30
|
# ) %>
|
30
31
|
def intercom_script_tag(user_details, widget_options={})
|
31
|
-
intercom_settings = user_details.merge({:widget => widget_options})
|
32
|
+
intercom_settings = user_details.merge({:widget => widget_options}).with_indifferent_access
|
32
33
|
intercom_settings_with_dates_as_timestamps = convert_dates_to_unix_timestamps(intercom_settings)
|
34
|
+
intercom_settings_with_dates_as_timestamps.reject! { |key, value| %w(email name user_id).include?(key.to_s) && value.nil? }
|
33
35
|
intercom_script = <<-INTERCOM_SCRIPT
|
34
36
|
<script id="IntercomSettingsScriptTag">
|
35
37
|
var intercomSettings = #{ActiveSupport::JSON.encode(intercom_settings_with_dates_as_timestamps)};
|
@@ -13,4 +13,12 @@ class IntercomRailsTest < MiniTest::Unit::TestCase
|
|
13
13
|
assert_match(/.created_at.\s*:\s*#{now.to_i}/, intercom_script_tag({:created_at => now}))
|
14
14
|
assert_match(/.something.\s*:\s*#{now.to_i}/, intercom_script_tag({:custom_data => {"something" => now}}))
|
15
15
|
end
|
16
|
+
|
17
|
+
def test_strips_out_nil_entries_for_standard_attributes
|
18
|
+
%w(name email user_id).each do |standard_attribute|
|
19
|
+
assert_match(/.#{standard_attribute}.\s*:\s*"value"/, intercom_script_tag({standard_attribute => 'value'}))
|
20
|
+
assert(!intercom_script_tag({standard_attribute.to_sym => nil}).include?("\"#{standard_attribute}\":"), "should strip #{standard_attribute} when nil")
|
21
|
+
assert(!intercom_script_tag({standard_attribute => nil}).include?("\"#{standard_attribute}\":"), "should strip #{standard_attribute} when nil")
|
22
|
+
end
|
23
|
+
end
|
16
24
|
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.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-03
|
14
|
+
date: 2012-05-03 00:00:00.000000000Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
18
|
-
requirement: &
|
18
|
+
requirement: &70285909407560 !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ! '>'
|
@@ -23,10 +23,10 @@ dependencies:
|
|
23
23
|
version: '3.0'
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements: *
|
26
|
+
version_requirements: *70285909407560
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
|
-
requirement: &
|
29
|
+
requirement: &70285909407140 !ruby/object:Gem::Requirement
|
30
30
|
none: false
|
31
31
|
requirements:
|
32
32
|
- - ! '>='
|
@@ -34,10 +34,10 @@ dependencies:
|
|
34
34
|
version: '0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
|
-
version_requirements: *
|
37
|
+
version_requirements: *70285909407140
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: rake
|
40
|
-
requirement: &
|
40
|
+
requirement: &70285909437140 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
@@ -45,7 +45,7 @@ dependencies:
|
|
45
45
|
version: '0'
|
46
46
|
type: :development
|
47
47
|
prerelease: false
|
48
|
-
version_requirements: *
|
48
|
+
version_requirements: *70285909437140
|
49
49
|
description: Intercom (https://www.intercom.io) is a customer relationship management
|
50
50
|
and messaging tool for web app owners. This library makes it easier to use the correct
|
51
51
|
javascript tracking code in your rails applications.
|