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.
@@ -1,2 +0,0 @@
1
- # change this to your Heap ID, or use a environment variable to set your ID
2
- Heap.app_id = ENV["HEAP_ID"]
@@ -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
@@ -1,9 +0,0 @@
1
- require 'heap/view_helpers'
2
-
3
- class Heap
4
- class Railtie < Rails::Railtie
5
- initializer "heap.view_helpers" do
6
- ActiveSupport.on_load( :action_view ){ include Heap::ViewHelpers }
7
- end
8
- end
9
- end
@@ -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
@@ -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
@@ -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