heap 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 330313ec277d5228071e1ba15c111b557ca30f1b
4
+ data.tar.gz: 82925987e6fc300ed9894ed3f07bed3200a5ec7a
5
+ SHA512:
6
+ metadata.gz: 8e6b894665ec72fdc535163397898bfb8a80dc892ede8b1d7b879c97d9625cebc38be3954108a2ae9faa9381848fcdd0bce0120d98e474b5c9ea4124ba86a77c
7
+ data.tar.gz: 5be0df3fe09fa297b7b957f36c958e702490e104c7119b2776c38c7a0c8774f426741edd43ac684329e1373c2e75454a72f89385e6ba76b4752da7cab3f1542c
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "httparty", "~> 0.13"
4
+
5
+ group :development do
6
+ gem "shoulda", ">= 0"
7
+ gem "rdoc", "~> 3.12"
8
+ gem "bundler", "~> 1.0"
9
+ gem "jeweler", "~> 2.0.1"
10
+ gem "simplecov", ">= 0"
11
+ gem "webmock", "~>1.20"
12
+ end
@@ -0,0 +1,91 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.8)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ descendants_tracker (0.0.4)
15
+ thread_safe (~> 0.3, >= 0.3.1)
16
+ docile (1.1.5)
17
+ faraday (0.9.0)
18
+ multipart-post (>= 1.2, < 3)
19
+ git (1.2.8)
20
+ github_api (0.12.2)
21
+ addressable (~> 2.3)
22
+ descendants_tracker (~> 0.0.4)
23
+ faraday (~> 0.8, < 0.10)
24
+ hashie (>= 3.3)
25
+ multi_json (>= 1.7.5, < 2.0)
26
+ nokogiri (~> 1.6.3)
27
+ oauth2
28
+ hashie (3.3.2)
29
+ highline (1.6.21)
30
+ httparty (0.13.3)
31
+ json (~> 1.8)
32
+ multi_xml (>= 0.5.2)
33
+ i18n (0.6.11)
34
+ jeweler (2.0.1)
35
+ builder
36
+ bundler (>= 1.0)
37
+ git (>= 1.2.5)
38
+ github_api
39
+ highline (>= 1.6.15)
40
+ nokogiri (>= 1.5.10)
41
+ rake
42
+ rdoc
43
+ json (1.8.1)
44
+ jwt (1.2.0)
45
+ mini_portile (0.6.1)
46
+ minitest (5.4.3)
47
+ multi_json (1.10.1)
48
+ multi_xml (0.5.5)
49
+ multipart-post (2.0.0)
50
+ nokogiri (1.6.5)
51
+ mini_portile (~> 0.6.0)
52
+ oauth2 (1.0.0)
53
+ faraday (>= 0.8, < 0.10)
54
+ jwt (~> 1.0)
55
+ multi_json (~> 1.3)
56
+ multi_xml (~> 0.5)
57
+ rack (~> 1.2)
58
+ rack (1.5.2)
59
+ rake (10.4.0)
60
+ rdoc (3.12.2)
61
+ json (~> 1.4)
62
+ safe_yaml (1.0.4)
63
+ shoulda (3.5.0)
64
+ shoulda-context (~> 1.0, >= 1.0.1)
65
+ shoulda-matchers (>= 1.4.1, < 3.0)
66
+ shoulda-context (1.2.1)
67
+ shoulda-matchers (2.7.0)
68
+ activesupport (>= 3.0.0)
69
+ simplecov (0.9.1)
70
+ docile (~> 1.1.0)
71
+ multi_json (~> 1.0)
72
+ simplecov-html (~> 0.8.0)
73
+ simplecov-html (0.8.0)
74
+ thread_safe (0.3.4)
75
+ tzinfo (1.2.2)
76
+ thread_safe (~> 0.1)
77
+ webmock (1.20.4)
78
+ addressable (>= 2.3.6)
79
+ crack (>= 0.3.2)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ bundler (~> 1.0)
86
+ httparty (~> 0.13)
87
+ jeweler (~> 2.0.1)
88
+ rdoc (~> 3.12)
89
+ shoulda
90
+ simplecov
91
+ webmock (~> 1.20)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Dennis de Reus
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # Heap
2
+
3
+ Heap is a simple rubygem that makes is simple to integrate your application with [heap analytics](heapanalytics.com). It provides:
4
+
5
+ * Helpers to easily integrate heap into your Rails application
6
+ * An easy way to submit events to heap directly from your code
7
+ * The possibility to set additional attributes on your users directly from your app
8
+
9
+ ## Installation
10
+
11
+ Installation is simple via:
12
+
13
+ gem install heap
14
+
15
+ For Rails applications, run the following command to add an initiatlizer for your heap `app_id`:
16
+
17
+ rails generate heap:install
18
+
19
+ To enable the tracking code on your website, place the following in just before the closing `</head>` tag in your layout:
20
+
21
+ <%= heap_analytics %>
22
+
23
+ ## Usage
24
+
25
+ After installing, you will have access to `Heap.event` and `Heap.identify` in your ruby code. For Rails, Heap provides 2 helpers to include the tracking code, and to identify individual users.
26
+
27
+ Heap needs your application ID to successfully submit data to heapanalytics.com. You can set this directly using `Heap.app_id = 123`, or in Rails, by using the provided generator to generate an initializer at config/initializers/heap.rb
28
+
29
+ ### Identifying your users
30
+
31
+ The `heap_identify` view helper can be used to supply heap with attributes for your users. The helper takes 2 arguments:
32
+
33
+ * [String] email: The e-mail address used to identify your visitor in Heap
34
+ * [Hash, optional] properties: A hash containing additional properties for your users (Hashes with multiple levels are currently not supported)
35
+
36
+ Example:
37
+
38
+ <%= heap_identify(current_user.email, name: current_user.name, role: current_user.role) if signed_in? %>
39
+
40
+ ### Tracking server-side events
41
+
42
+ In case you want to track server-side events -- for example when sending a welcome e-mail to a new user --, you can do so using `Heap.event`. `Heap.event` takes 3 arguments:
43
+
44
+ * [String] event: A description of the event
45
+ * [String] identity: The e-mail address used to identify your user
46
+ * [Hash, optional] properties: A hash containing additional properties for the event (Hashes with multiple levels are currently not supported)
47
+
48
+ Example:
49
+
50
+ Heap.event("Welcome e-mail sent", "user@example.com", promotion:'second gem free', segment:'ruby developers')
51
+
52
+ ### Adding server-side user attributes
53
+
54
+ To update or set properties on your users directly from your application, use `Heap.identify`. `Heap.identify` takes 2 arguments:
55
+
56
+ * [String] identity: The e-mail address used to identify your user
57
+ * [Hash] properties: A hash containing additional properties for your users (Hashes with multiple levels are currently not supported)
58
+
59
+ Example:
60
+
61
+ Heap.identify("user@example.com", segment:'ruby developers', age: 25)
62
+
63
+ ## Contributing to Heap
64
+
65
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
66
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
67
+ * Fork the project.
68
+ * Start a feature/bugfix branch.
69
+ * Commit and push until you are happy with your contribution.
70
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
71
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
72
+
73
+ ## Copyright
74
+
75
+ The Heap gem is licensed under the MIT license. Copyright (c) 2014 Dennis de Reus. See LICENSE.txt for further details.
76
+
77
+ The Heap gem is a personal project and not affiliated to heapanalytics.com
78
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "heap"
18
+ gem.homepage = "http://github.com/HectorMalot/heap"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Easy integration of heapanalytics into your ruby app}
21
+ gem.description = %Q{Easy integration of heapanalytics into your ruby app}
22
+ gem.email = "dennisdereus@gmail.com"
23
+ gem.authors = ["Dennis de Reus"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "heap #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,12 @@
1
+ require 'rails/generators/base'
2
+
3
+ class Heap
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+ def copy_initializer
8
+ template "heap.rb", "config/initializers/heap.rb"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,2 @@
1
+ # change this to your Heap ID, or use a environment variable to set your ID
2
+ Heap.app_id = ENV["HEAP_ID"]
@@ -0,0 +1,17 @@
1
+ require 'httparty'
2
+ require 'heap/events'
3
+ require 'heap/railtie' if defined?(Rails)
4
+
5
+ class Heap
6
+ include HTTParty
7
+ base_uri 'https://heapanalytics.com/api'
8
+ headers "Content-Type" => "application/json"
9
+
10
+ def self.app_id=(obj)
11
+ @@app_id = obj
12
+ end
13
+
14
+ def self.app_id
15
+ @@app_id
16
+ end
17
+ end
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,9 @@
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
@@ -0,0 +1,20 @@
1
+ class Heap
2
+ module ViewHelpers
3
+ def heap_analytics
4
+ javascript_tag :type => "text/javascript" do
5
+ raw %Q{
6
+ window.heap=window.heap||[],heap.load=function(t,e){window.heap.appid=t,window.heap.config=e;var a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"===document.location.protocol?"https:":"http:") + "/" + "/cdn.heapanalytics.com/js/heap.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(t){return function(){heap.push([t].concat(Array.prototype.slice.call(arguments,0)))}},p=["clearEventProperties","identify","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
7
+ heap.load("#{Heap.app_id}");
8
+ }.html_safe
9
+ end
10
+ end
11
+
12
+ def heap_identify(email, properties=nil)
13
+ body = properties.map {|k,v| ", #{k}: \"#{v}\""}.join if properties.is_a? Hash
14
+ javascript_tag do
15
+ raw %Q{heap.identify({email: "#{email}" #{body}}); }.html_safe
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ require 'bundler'
15
+ begin
16
+ Bundler.setup(:default, :development)
17
+ rescue Bundler::BundlerError => e
18
+ $stderr.puts e.message
19
+ $stderr.puts "Run `bundle install` to install missing gems"
20
+ exit e.status_code
21
+ end
22
+
23
+ require 'heap'
24
+ require 'minitest/autorun'
25
+ require 'shoulda'
26
+ require 'webmock/minitest'
27
+
28
+ class MiniTest::Test
29
+ end
30
+
31
+ MiniTest.autorun
@@ -0,0 +1,25 @@
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
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dennis de Reus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.13'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shoulda
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.20'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.20'
111
+ description: Easy integration of heapanalytics into your ruby app
112
+ email: dennisdereus@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.mdown
118
+ files:
119
+ - ".document"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.mdown
124
+ - Rakefile
125
+ - VERSION
126
+ - lib/generators/heap/install_generator.rb
127
+ - lib/generators/templates/heap.rb
128
+ - lib/heap.rb
129
+ - lib/heap/events.rb
130
+ - lib/heap/railtie.rb
131
+ - lib/heap/view_helpers.rb
132
+ - test/helper.rb
133
+ - test/test_heap.rb
134
+ homepage: http://github.com/HectorMalot/heap
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Easy integration of heapanalytics into your ruby app
158
+ test_files: []