heap 0.3.0 → 1.0.0
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 +4 -4
- data/.travis.yml +16 -0
- data/Gemfile +11 -8
- data/Gemfile187 +23 -0
- data/LICENSE.txt +2 -2
- data/README.md +120 -0
- data/Rakefile +8 -22
- data/VERSION +1 -1
- data/heap.gemspec +42 -43
- data/lib/heap.rb +10 -23
- data/lib/heap/client.rb +192 -0
- data/lib/heap/errors.rb +18 -0
- data/lib/heap/validations.rb +57 -0
- data/test/client_add_user_properties_test.rb +124 -0
- data/test/client_test.rb +78 -0
- data/test/client_track_test.rb +151 -0
- data/test/heap_test.rb +23 -0
- data/test/helper.rb +4 -17
- metadata +51 -52
- data/CHANGELOG.mdown +0 -18
- data/Gemfile.lock +0 -91
- data/README.mdown +0 -99
- data/lib/generators/heap/install_generator.rb +0 -12
- data/lib/generators/templates/heap.rb +0 -2
- data/lib/heap/events.rb +0 -22
- data/lib/heap/railtie.rb +0 -9
- data/lib/heap/view_helpers.rb +0 -28
- data/test/test_heap.rb +0 -35
- data/test/test_view_helper.rb +0 -47
data/lib/heap/events.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
class Heap
|
2
|
-
def self.event(event,identity=nil,properties=nil)
|
3
|
-
return unless self.app_id
|
4
|
-
body = {
|
5
|
-
app_id: self.app_id.to_s,
|
6
|
-
event: event
|
7
|
-
}
|
8
|
-
body[:identity] = identity if identity
|
9
|
-
body[:properties] = properties if properties.is_a? Hash
|
10
|
-
post("/track",body:body.to_json)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.identify(identity,properties)
|
14
|
-
return unless self.app_id
|
15
|
-
body= {
|
16
|
-
app_id: self.app_id.to_s,
|
17
|
-
identity: identity
|
18
|
-
}
|
19
|
-
body[:properties] = properties if properties.is_a? Hash
|
20
|
-
post("/identify",body:body.to_json)
|
21
|
-
end
|
22
|
-
end
|
data/lib/heap/railtie.rb
DELETED
data/lib/heap/view_helpers.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
class Heap
|
4
|
-
module ViewHelpers
|
5
|
-
def heap_analytics(properties = {})
|
6
|
-
config = properties.map {|k,v| "#{k}: #{v}"}.join(", ") if properties.is_a? Hash
|
7
|
-
heap_js_block %Q{
|
8
|
-
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var n=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(n?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(a,o);for(var r=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["clearEventProperties","identify","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=r(p[c])};
|
9
|
-
heap.load("#{Heap.app_id}", {#{config}});
|
10
|
-
}
|
11
|
-
end
|
12
|
-
|
13
|
-
def heap_identify(handle, properties = nil)
|
14
|
-
body = properties.map {|k,v| ", #{k}: \"#{v}\""}.join if properties.is_a? Hash
|
15
|
-
heap_js_block %Q{heap.identify({#{Heap.default_handle_type}: "#{handle}" #{body}});}
|
16
|
-
end
|
17
|
-
|
18
|
-
def heap_set_event_properties(properties = {})
|
19
|
-
heap_js_block %Q{heap.setEventProperties(#{properties.to_json});}
|
20
|
-
end
|
21
|
-
|
22
|
-
def heap_js_block(content)
|
23
|
-
javascript_tag :type => "text/javascript" do
|
24
|
-
raw content.html_safe
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
data/test/test_heap.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestHeap < MiniTest::Test
|
4
|
-
should "post events to https://heapanalytics.com/api/track" do
|
5
|
-
stub_request(:post, "https://heapanalytics.com/api/track").
|
6
|
-
with(:body => {:app_id => '123', :event => 'test', :identity => 'test@example.com', :properties => {:property1 => 'hello', :property2 => 'world'}},
|
7
|
-
:headers => {'Content-Type'=>'application/json'}).
|
8
|
-
to_return(:body => "OK")
|
9
|
-
|
10
|
-
Heap.app_id = 123
|
11
|
-
result = Heap.event('test','test@example.com', :property1 => 'hello', :property2 => 'world')
|
12
|
-
assert_equal result.to_s, "OK"
|
13
|
-
end
|
14
|
-
|
15
|
-
should "post identities to https://heapanalytics.com/api/identify" do
|
16
|
-
stub_request(:post, "https://heapanalytics.com/api/identify").
|
17
|
-
with(:body => {:app_id => '123', :identity => 'test@example.com', :properties => {:property1 => 'hello', :property2 => 'world'}},
|
18
|
-
:headers => {'Content-Type'=>'application/json'}).
|
19
|
-
to_return(:body => "{}")
|
20
|
-
|
21
|
-
Heap.app_id = 123
|
22
|
-
result = Heap.identify('test@example.com', :property1 => 'hello', :property2 => 'world')
|
23
|
-
assert_equal result.to_s, "{}"
|
24
|
-
end
|
25
|
-
|
26
|
-
should "default to email handler" do
|
27
|
-
assert_equal Heap.default_handle_type, 'email'
|
28
|
-
end
|
29
|
-
|
30
|
-
should "allow to change the handler" do
|
31
|
-
Heap.default_handle_type = 'handle'
|
32
|
-
assert_equal Heap.default_handle_type, 'handle'
|
33
|
-
Heap.default_handle_type = nil
|
34
|
-
end
|
35
|
-
end
|
data/test/test_view_helper.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class String
|
4
|
-
def html_safe
|
5
|
-
self
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
class HeapHelperTest < MiniTest::Test
|
10
|
-
include Heap::ViewHelpers
|
11
|
-
|
12
|
-
def javascript_tag(options = {})
|
13
|
-
yield
|
14
|
-
end
|
15
|
-
|
16
|
-
def raw(js)
|
17
|
-
js
|
18
|
-
end
|
19
|
-
|
20
|
-
should "produce correct identify handle type" do
|
21
|
-
handle = '123'
|
22
|
-
assert_equal heap_identify(handle), "heap.identify({email: \"#{handle}\" });"
|
23
|
-
end
|
24
|
-
|
25
|
-
should "set event properties from arbitrary key-value pairs" do
|
26
|
-
js = heap_set_event_properties({
|
27
|
-
:first => "first value",
|
28
|
-
"second" => 2,
|
29
|
-
:third => true
|
30
|
-
})
|
31
|
-
|
32
|
-
assert_equal js, %Q/heap.setEventProperties({"first":"first value","second":2,"third":true});/
|
33
|
-
end
|
34
|
-
|
35
|
-
should "set load properties key-value pairs" do
|
36
|
-
|
37
|
-
Heap.app_id = '123'
|
38
|
-
|
39
|
-
js = heap_analytics({
|
40
|
-
forceSSL: true,
|
41
|
-
secureCookie: true,
|
42
|
-
disableTextCapture: true
|
43
|
-
})
|
44
|
-
|
45
|
-
assert_includes js, %Q/heap.load("123", {forceSSL: true, secureCookie: true, disableTextCapture: true});/
|
46
|
-
end
|
47
|
-
end
|