ramen-rails 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile.lock +8 -6
- data/README.md +39 -0
- data/lib/ramen-rails/railtie.rb +3 -4
- data/lib/ramen-rails/ramen_after_filter.rb +10 -1
- data/lib/ramen-rails/script_tag.rb +63 -0
- data/lib/ramen-rails/script_tag_helper.rb +2 -24
- data/lib/ramen-rails/version.rb +1 -1
- data/ramen-rails.gemspec +6 -5
- data/spec/lib/ramen_after_filter_spec.rb +13 -4
- data/spec/lib/script_tag_helper_spec.rb +27 -1
- data/spec/spec_helper.rb +1 -0
- metadata +39 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee40bc6fca9b914f2858387ecb699be14f91d46
|
4
|
+
data.tar.gz: 37f05f73081f823fd3abf946e348d793e76627f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 55ca55c3733132e9a258c15ac87b9a22b14c90048c920e97b4fe514e45bb17a12352aa6f655c36b24596bcbac0ffabf06b0d6d7822729df80bf6b2dc7364f090
|
7
|
+
data.tar.gz: 67f18b37beaa3b76a892f08bd2b2ee4a25d307fd5b6d8e0121badbaf5b11a7fbdbe4a2d0d9118548dcf12922489f7a731d052cb3e492f5efd90452b71150e741
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ramen-rails (0.0.
|
5
|
-
activesupport
|
4
|
+
ramen-rails (0.0.4)
|
5
|
+
activesupport (~> 4.2.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -64,6 +64,7 @@ GEM
|
|
64
64
|
rspec-support (~> 3.2.0)
|
65
65
|
rspec-support (3.2.2)
|
66
66
|
thread_safe (0.3.5)
|
67
|
+
timecop (0.7.3)
|
67
68
|
tzinfo (1.2.2)
|
68
69
|
thread_safe (~> 0.1)
|
69
70
|
|
@@ -71,8 +72,9 @@ PLATFORMS
|
|
71
72
|
ruby
|
72
73
|
|
73
74
|
DEPENDENCIES
|
74
|
-
actionpack
|
75
|
-
hashie
|
76
|
-
rake
|
75
|
+
actionpack (~> 4.2.0)
|
76
|
+
hashie (~> 3.4.0)
|
77
|
+
rake (~> 10.4.2)
|
77
78
|
ramen-rails!
|
78
|
-
rspec
|
79
|
+
rspec (~> 3.2.0)
|
80
|
+
timecop (~> 0.7.3)
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# ramen-rails
|
2
|
+
[![Build Status](https://travis-ci.org/ramen-dev/ramen-rails.svg)](https://travis-ci.org/ramen-dev/ramen-rails)
|
3
|
+
|
4
|
+
This is a Rails helper for [Ramen](https://ramen.is). Ramen is a product that helps
|
5
|
+
B2B SaaS product managers build better products by given them tools to better understand
|
6
|
+
what their customers need, and how satisfied their customers are with the results.
|
7
|
+
|
8
|
+
This gem will automatically inject the `ramen.js` script tag into pages.
|
9
|
+
|
10
|
+
# Installation
|
11
|
+
Add this to your Gemfile:
|
12
|
+
|
13
|
+
```
|
14
|
+
gem "ramen-rails"
|
15
|
+
```
|
16
|
+
|
17
|
+
Then run:
|
18
|
+
|
19
|
+
```
|
20
|
+
bundle install
|
21
|
+
```
|
22
|
+
|
23
|
+
# Usage
|
24
|
+
|
25
|
+
The following command will add `ramen.rb` to your `config/initializers`.
|
26
|
+
You can get your ID and SECRET in your Ramen Management Console.
|
27
|
+
|
28
|
+
```
|
29
|
+
rails g ramen:config ORGANIZATION_ID ORGANIZATION_SECRET
|
30
|
+
```
|
31
|
+
|
32
|
+
# Thanks
|
33
|
+
This gem was heavily inspired by the [intercom-rails](https://github.com/intercom/intercom-rails)
|
34
|
+
gem. We <3 Intercom at Ramen. If you're looking for a nice way to have conversations
|
35
|
+
with your customers in your web application, give them a holler.
|
36
|
+
|
37
|
+
|
38
|
+
# License
|
39
|
+
MIT-LICENSE for life.
|
data/lib/ramen-rails/railtie.rb
CHANGED
@@ -4,13 +4,12 @@ require 'ramen-rails/ramen_after_filter'
|
|
4
4
|
module RamenRails
|
5
5
|
class Railtie < Rails::Railtie
|
6
6
|
initializer "ramen_rails.script_tag_helper.rb" do |app|
|
7
|
-
ActionView::Base.send :include,
|
8
|
-
ScriptTagHelper
|
7
|
+
ActionView::Base.send :include, ScriptTagHelper
|
9
8
|
end
|
10
9
|
|
11
10
|
initializer "ramen_rails.auto_include_filter.rb" do |app|
|
12
|
-
ActionController::Base.send :
|
13
|
-
|
11
|
+
ActionController::Base.send :include, AutoInclude
|
12
|
+
ActionController::Base.send :after_filter, :add_ramen_script_tag
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module RamenRails
|
2
2
|
|
3
|
+
module AutoInclude
|
4
|
+
def add_ramen_script_tag
|
5
|
+
RamenAfterFilter.filter(self)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class RamenAfterFilter
|
10
|
+
|
4
11
|
include ScriptTagHelper
|
5
12
|
CLOSING_BODY_TAG = %r{</body>}
|
6
13
|
|
@@ -118,7 +125,8 @@ module RamenRails
|
|
118
125
|
|
119
126
|
obj = {}
|
120
127
|
[:url, :id, :value, :name].each do |attr|
|
121
|
-
obj[attr] =
|
128
|
+
obj[attr] = company.send(attr) if company.respond_to?(attr) &&
|
129
|
+
company.send(attr).present?
|
122
130
|
end
|
123
131
|
|
124
132
|
obj
|
@@ -129,6 +137,7 @@ module RamenRails
|
|
129
137
|
obj = {}
|
130
138
|
obj[:organization_id] = ramen_org_id
|
131
139
|
obj[:user] = {}
|
140
|
+
obj[:timestamp] = Time.now.to_i
|
132
141
|
|
133
142
|
user = ramen_user_object
|
134
143
|
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "active_support/json"
|
2
|
+
require "active_support/core_ext/hash/indifferent_access"
|
3
|
+
|
4
|
+
module RamenRails
|
5
|
+
class ScriptTag
|
6
|
+
class EmptySettings < StandardError; end
|
7
|
+
|
8
|
+
def self.generate(template, ramen_settings, options = {})
|
9
|
+
st = new(template, ramen_settings, options)
|
10
|
+
st.generate
|
11
|
+
end
|
12
|
+
|
13
|
+
attr_accessor :template, :ramen_settings, :options
|
14
|
+
def initialize(template, ramen_settings, options = {})
|
15
|
+
self.template = template
|
16
|
+
self.ramen_settings = ramen_settings
|
17
|
+
self.options = options
|
18
|
+
end
|
19
|
+
|
20
|
+
def generate
|
21
|
+
if ramen_settings.blank?
|
22
|
+
raise EmptySettings.new("need to pass ramen_script_tag a non-empty ramen_settings argument")
|
23
|
+
end
|
24
|
+
|
25
|
+
add_auth_hash!
|
26
|
+
|
27
|
+
ramen_script = <<-RAMEN_SCRIPT
|
28
|
+
<script id="RamenSettingsScriptTag">
|
29
|
+
window.ramenSettings = #{ActiveSupport::JSON.encode(ramen_settings)};
|
30
|
+
</script>
|
31
|
+
<script src="https://cdn.ramen.is/assets/ramen.js" async></script>
|
32
|
+
RAMEN_SCRIPT
|
33
|
+
|
34
|
+
if controller
|
35
|
+
controller.
|
36
|
+
instance_variable_set(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE, true)
|
37
|
+
end
|
38
|
+
|
39
|
+
ramen_script.respond_to?(:html_safe) ? ramen_script.html_safe : ramen_script
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_auth_hash!
|
43
|
+
return unless ramen_settings[:user].present? &&
|
44
|
+
options[:organization_secret].present? &&
|
45
|
+
ramen_settings[:auth_hash].blank?
|
46
|
+
|
47
|
+
user = ramen_settings[:user]
|
48
|
+
|
49
|
+
if ramen_settings[:timestamp]
|
50
|
+
secret_string = "#{user[:email]}:#{user[:id]}:#{user[:name]}:#{ramen_settings[:timestamp]}:#{options[:organization_secret]}"
|
51
|
+
else
|
52
|
+
secret_string = "#{user[:email]}:#{user[:id]}:#{user[:name]}:#{options[:organization_secret]}"
|
53
|
+
end
|
54
|
+
|
55
|
+
ramen_settings[:auth_hash] = (Digest::SHA2.new << secret_string).to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def controller
|
59
|
+
template.try :controller
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -1,33 +1,11 @@
|
|
1
|
-
require "
|
2
|
-
require "active_support/core_ext/hash/indifferent_access"
|
1
|
+
require "ramen-rails/script_tag"
|
3
2
|
|
4
3
|
module RamenRails
|
5
4
|
SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE = :@_ramen_script_tag_helper_called
|
6
5
|
|
7
6
|
module ScriptTagHelper
|
8
|
-
|
9
|
-
class EmptySettings < StandardError; end
|
10
|
-
|
11
7
|
def ramen_script_tag(ramen_settings, options = {})
|
12
|
-
|
13
|
-
raise EmptySettings.new("need to pass ramen_script_tag a non-empty ramen_settings argument")
|
14
|
-
end
|
15
|
-
|
16
|
-
if ramen_settings[:user].present? && options[:organization_secret].present? && ramen_settings[:auth_hash].blank?
|
17
|
-
user_details = ramen_settings[:user]
|
18
|
-
secret_string = "#{user_details[:email]}:#{user_details[:id]}:#{user_details[:name]}:#{options[:organization_secret]}"
|
19
|
-
ramen_settings[:auth_hash] = (Digest::SHA2.new << secret_string).to_s
|
20
|
-
end
|
21
|
-
|
22
|
-
ramen_script = <<-RAMEN_SCRIPT
|
23
|
-
<script id="RamenSettingsScriptTag">
|
24
|
-
var ramenSettings = #{ActiveSupport::JSON.encode(ramen_settings)};
|
25
|
-
</script>
|
26
|
-
<script src="https://cdn.ramen.is/assets/ramen.js" async></script>
|
27
|
-
RAMEN_SCRIPT
|
28
|
-
|
29
|
-
controller.instance_variable_set(RamenRails::SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE, true) if defined?(controller)
|
30
|
-
ramen_script.respond_to?(:html_safe) ? ramen_script.html_safe : ramen_script
|
8
|
+
ScriptTag.generate(self, ramen_settings, options)
|
31
9
|
end
|
32
10
|
end
|
33
11
|
end
|
data/lib/ramen-rails/version.rb
CHANGED
data/ramen-rails.gemspec
CHANGED
@@ -13,12 +13,13 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.description = %q{Ramen helps B2B SaaS product teams build better products through workflow-enhance customer development}
|
14
14
|
|
15
15
|
|
16
|
-
s.add_development_dependency "actionpack"
|
17
|
-
s.add_development_dependency "rake"
|
18
|
-
s.add_development_dependency "rspec"
|
19
|
-
s.add_development_dependency "hashie"
|
16
|
+
s.add_development_dependency "actionpack", "~>4.0.0"
|
17
|
+
s.add_development_dependency "rake", "~>10.4.2"
|
18
|
+
s.add_development_dependency "rspec", "~>3.2.0"
|
19
|
+
s.add_development_dependency "hashie", "~>3.4.0"
|
20
|
+
s.add_development_dependency "timecop", "~>0.7.3"
|
20
21
|
|
21
|
-
s.add_dependency "activesupport"
|
22
|
+
s.add_dependency "activesupport", "~>4.0.0"
|
22
23
|
|
23
24
|
s.rubyforge_project = "ramen-rails"
|
24
25
|
|
@@ -37,10 +37,19 @@ describe 'After filter' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should attach tag" do
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
Timecop.freeze do
|
41
|
+
ts = Time.now.to_i
|
42
|
+
auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:5678").to_s
|
43
|
+
ts_auth_hash = (Digest::SHA2.new << "ryan@ramen.is:person-1234:Ryan Angilly:#{ts}:5678").to_s
|
44
|
+
|
45
|
+
filter = RamenRails::RamenAfterFilter.filter(@dummy)
|
46
|
+
|
47
|
+
expect(@dummy.response.body).to_not include(auth_hash)
|
48
|
+
expect(@dummy.response.body).to include(ts_auth_hash)
|
49
|
+
expect(@dummy.response.body).to include("script")
|
50
|
+
expect(@dummy.response.body).to include("Angilly")
|
51
|
+
expect(@dummy.response.body).to_not include("company")
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
describe "and a company" do
|
@@ -22,7 +22,7 @@ describe 'Script Tag Helper' do
|
|
22
22
|
it "should raise if the script tag helper is passed a blank object" do
|
23
23
|
expect do
|
24
24
|
@template.ramen_script_tag({})
|
25
|
-
end.to raise_error(RamenRails::
|
25
|
+
end.to raise_error(RamenRails::ScriptTag::EmptySettings)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should render the tag" do
|
@@ -66,6 +66,32 @@ describe 'Script Tag Helper' do
|
|
66
66
|
expect(output).to include(auth_hash)
|
67
67
|
end
|
68
68
|
|
69
|
+
it "should work timestamp into hash if provided" do
|
70
|
+
ts = Time.now.to_i
|
71
|
+
ramen_settings = {
|
72
|
+
timestamp: ts,
|
73
|
+
organization_id: rand(1_000_000),
|
74
|
+
user: {
|
75
|
+
email: 'ryan@ramen.is',
|
76
|
+
name: 'Ryan Angilly',
|
77
|
+
id: '346656'
|
78
|
+
}
|
79
|
+
}
|
80
|
+
|
81
|
+
options = {organization_secret: "1234"}
|
82
|
+
|
83
|
+
not_auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:1234").to_s
|
84
|
+
auth_hash = (Digest::SHA2.new << "ryan@ramen.is:346656:Ryan Angilly:#{ts}:1234").to_s
|
85
|
+
|
86
|
+
output = @template.ramen_script_tag(ramen_settings, options)
|
87
|
+
|
88
|
+
expect(output).to include("Ryan Angilly")
|
89
|
+
expect(output).to include("auth_hash")
|
90
|
+
expect(output).not_to include(not_auth_hash)
|
91
|
+
expect(output).to include(auth_hash)
|
92
|
+
|
93
|
+
end
|
94
|
+
|
69
95
|
it "should not override auth_hash if it is provided" do
|
70
96
|
ramen_settings = {
|
71
97
|
organization_id: rand(1_000_000),
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,85 +1,99 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ramen-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Angilly
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.0.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 10.4.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 10.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.2.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: hashie
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.4.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 3.4.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: timecop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.7.3
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.7.3
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: activesupport
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 4.0.0
|
76
90
|
type: :runtime
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 4.0.0
|
83
97
|
description: Ramen helps B2B SaaS product teams build better products through workflow-enhance
|
84
98
|
customer development
|
85
99
|
email:
|
@@ -90,9 +104,11 @@ extra_rdoc_files: []
|
|
90
104
|
files:
|
91
105
|
- ".ruby-gemset"
|
92
106
|
- ".ruby-version"
|
107
|
+
- ".travis.yml"
|
93
108
|
- Gemfile
|
94
109
|
- Gemfile.lock
|
95
110
|
- MIT-LICENSE
|
111
|
+
- README.md
|
96
112
|
- Rakefile
|
97
113
|
- lib/rails/generators/ramen/config/config_generator.rb
|
98
114
|
- lib/rails/generators/ramen/config/ramen.rb.erb
|
@@ -100,6 +116,7 @@ files:
|
|
100
116
|
- lib/ramen-rails/config.rb
|
101
117
|
- lib/ramen-rails/railtie.rb
|
102
118
|
- lib/ramen-rails/ramen_after_filter.rb
|
119
|
+
- lib/ramen-rails/script_tag.rb
|
103
120
|
- lib/ramen-rails/script_tag_helper.rb
|
104
121
|
- lib/ramen-rails/version.rb
|
105
122
|
- ramen-rails.gemspec
|