intercom-rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,13 +5,13 @@ module IntercomRails
5
5
  # Helper methods for generating Intercom javascript script tags.
6
6
  module ScriptTagHelper
7
7
  # @param user_details [Hash] a customizable hash of user details
8
- # @param widget_options [Hash] an optional hash for widget customisation
8
+ # @param options [Hash] an optional hash for secure mode and widget customisation
9
9
  # @option user_details [String] :app_id Your application id (get it here)
10
10
  # @option user_details [String] :user_id unique id of this user within your application
11
11
  # @option user_details [String] :email email address for this user
12
12
  # @option user_details [String] :name the users name, _optional_ but useful for identify people in the Intercom App.
13
13
  # @option user_details [Hash] :custom_data custom attributes you'd like saved for this user on Intercom. See
14
- # @option widget_options [String] :activator a css selector for an element which when clicked should show the Intercom widget
14
+ # @option options [String] :activator a css selector for an element which when clicked should show the Intercom widget
15
15
  # @return [String] Intercom script tag
16
16
  # @example basic example
17
17
  # <%= intercom_script_tag({ :app_id => "your-app-id",
@@ -28,8 +28,12 @@ module IntercomRails
28
28
  # :name => current_user.name }
29
29
  # {:activator => "#Intercom"}
30
30
  # ) %>
31
- def intercom_script_tag(user_details, widget_options={})
32
- intercom_settings = user_details.merge({:widget => widget_options}).with_indifferent_access
31
+ def intercom_script_tag(user_details, options={})
32
+ if options[:secret]
33
+ secret_string = "#{options[:secret]}#{user_details[:email].blank? ? user_details[:id] : user_details[:email]}"
34
+ user_details[:user_hash] = Digest::SHA1.hexdigest(secret_string)
35
+ end
36
+ intercom_settings = user_details.merge({:widget => options[:widget]}).with_indifferent_access
33
37
  intercom_settings_with_dates_as_timestamps = convert_dates_to_unix_timestamps(intercom_settings)
34
38
  intercom_settings_with_dates_as_timestamps.reject! { |key, value| %w(email name user_id).include?(key.to_s) && value.nil? }
35
39
  intercom_script = <<-INTERCOM_SCRIPT
@@ -63,4 +67,4 @@ module IntercomRails
63
67
  object
64
68
  end
65
69
  end
66
- end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -21,4 +21,9 @@ class IntercomRailsTest < MiniTest::Unit::TestCase
21
21
  assert(!intercom_script_tag({standard_attribute => nil}).include?("\"#{standard_attribute}\":"), "should strip #{standard_attribute} when nil")
22
22
  end
23
23
  end
24
- end
24
+
25
+ def test_secure_mode
26
+ assert_match(/.user_hash.\s*:\s*"#{Digest::SHA1.hexdigest('abcdefgh' + 'ciaran@intercom.io')}"/, intercom_script_tag({:email => "ciaran@intercom.io"}, {:secret => 'abcdefgh'}))
27
+ assert_match(/.user_hash.\s*:\s*"#{Digest::SHA1.hexdigest('abcdefgh' + '1234')}"/, intercom_script_tag({:id => 1234}, {:secret => 'abcdefgh'}))
28
+ end
29
+ 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.3
4
+ version: 0.0.4
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-05-03 00:00:00.000000000Z
14
+ date: 2012-08-14 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
18
- requirement: &70285909407560 !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>'
@@ -23,10 +23,15 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70285909407560
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>'
30
+ - !ruby/object:Gem::Version
31
+ version: '3.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: minitest
29
- requirement: &70285909407140 !ruby/object:Gem::Requirement
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  none: false
31
36
  requirements:
32
37
  - - ! '>='
@@ -34,10 +39,15 @@ dependencies:
34
39
  version: '0'
35
40
  type: :development
36
41
  prerelease: false
37
- version_requirements: *70285909407140
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: rake
40
- requirement: &70285909437140 !ruby/object:Gem::Requirement
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ! '>='
@@ -45,7 +55,12 @@ dependencies:
45
55
  version: '0'
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *70285909437140
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
49
64
  description: Intercom (https://www.intercom.io) is a customer relationship management
50
65
  and messaging tool for web app owners. This library makes it easier to use the correct
51
66
  javascript tracking code in your rails applications.
@@ -86,10 +101,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
101
  version: '0'
87
102
  requirements: []
88
103
  rubyforge_project: intercom-rails
89
- rubygems_version: 1.8.10
104
+ rubygems_version: 1.8.23
90
105
  signing_key:
91
106
  specification_version: 3
92
107
  summary: Rails helper for emitting javascript script tags for Intercom
93
108
  test_files:
94
109
  - test/intercom-rails/script_tag_helper_test.rb
95
- has_rdoc: