heap 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/Gemfile +5 -3
- data/Gemfile187 +3 -3
- data/README.md +7 -4
- data/Rakefile +6 -0
- data/VERSION +1 -1
- data/heap.gemspec +18 -12
- data/lib/heap/client.rb +5 -2
- data/lib/heap/validations.rb +20 -0
- data/test/client_add_user_properties_test.rb +70 -12
- data/test/client_test.rb +10 -2
- data/test/client_track_test.rb +82 -16
- data/test/helper.rb +26 -0
- metadata +42 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d13ef266e73536e3f334d975408393051f3240f4
|
4
|
+
data.tar.gz: fd288e976a5ac65d67495377491c2dfc493c658d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9b4129ae78fcd15b1a75bd045464671b79ebb9856924f088ff2926e1f69eb228bff0d5e9c529fb782aac39fb55c1dac34b3c23ce27a381222894d8396944b1e
|
7
|
+
data.tar.gz: 2eeee128759cd9438df09755827576264e7766e4bbd8308394aee20280b45bc886bec4b2861411bb79c908aed4206249e32953fb7e17366c9ede2d2f25505d7f
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -7,9 +7,11 @@ gem 'faraday_middleware', '>= 0.8.0'
|
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
9
9
|
group :development do
|
10
|
-
gem 'minitest', '>= 0'
|
11
|
-
gem 'yard', '>= 0.8.7.6'
|
12
|
-
gem 'rdoc', '>= 3.12'
|
13
10
|
gem 'bundler', '>= 1.0'
|
11
|
+
gem 'coveralls', '>= 0.8.10'
|
14
12
|
gem 'jeweler', '>= 2.0.1'
|
13
|
+
gem 'minitest', '>= 5.8.4'
|
14
|
+
gem 'rdoc', '>= 3.12'
|
15
|
+
gem 'simplecov', '>= 0.11.2'
|
16
|
+
gem 'yard', '>= 0.8.7.6'
|
15
17
|
end
|
data/Gemfile187
CHANGED
@@ -7,10 +7,10 @@ gem 'faraday_middleware', '~> 0.8.0'
|
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
9
9
|
group :development do
|
10
|
-
gem 'minitest', '>= 0'
|
11
|
-
gem 'yard', '>= 0.8.7.6'
|
12
|
-
gem 'rdoc', '>= 3.12'
|
13
10
|
gem 'bundler', '>= 1.0'
|
11
|
+
gem 'minitest', '>= 5.8.4'
|
12
|
+
gem 'rdoc', '>= 4.2.2'
|
13
|
+
gem 'yard', '>= 0.8.7.6'
|
14
14
|
|
15
15
|
# NOTE: The latest versions of these dependencies do not support Ruby 1.8.7.
|
16
16
|
gem 'jeweler', '~> 1.8.8'
|
data/README.md
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Heap Server-Side API Client for Ruby
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/heap/heap-ruby.svg?branch=master)](https://travis-ci.org/heap/heap-ruby)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/heap/heap-ruby/badge.svg?branch=master)](https://coveralls.io/github/heap/heap-ruby?branch=master)
|
5
|
+
[![Dependency Status](https://gemnasium.com/heap/heap-ruby.svg)](https://gemnasium.com/heap/heap-ruby)
|
4
6
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/heap/heap-ruby/master/frames)
|
5
7
|
[![Gem Version](https://badge.fury.io/rb/heap.svg)](https://badge.fury.io/rb/heap)
|
6
8
|
|
7
|
-
This is a Ruby
|
9
|
+
This is a [Ruby](https://www.ruby-lang.org/) client for the
|
10
|
+
[Heap](https://heapanalytics.com/)
|
8
11
|
[server-side API](https://heapanalytics.com/docs/server-side).
|
9
12
|
|
10
13
|
|
@@ -79,14 +82,14 @@ end
|
|
79
82
|
The properties are optional.
|
80
83
|
|
81
84
|
```ruby
|
82
|
-
Heap.track '
|
85
|
+
Heap.track 'event-name', 'user-identity', property: 'value'
|
83
86
|
```
|
84
87
|
|
85
88
|
[Add properties](https://heapanalytics.com/docs/server-side#identify) to a
|
86
89
|
user.
|
87
90
|
|
88
91
|
```ruby
|
89
|
-
Heap.add_user_properties 'user-
|
92
|
+
Heap.add_user_properties 'user-identity', plan: 'premium1'
|
90
93
|
```
|
91
94
|
|
92
95
|
If the global API client instance stored in `Heap` is not a good fit for your
|
@@ -94,7 +97,7 @@ application's architecture, create your own client instances.
|
|
94
97
|
|
95
98
|
```ruby
|
96
99
|
heap_client = Heap.new app_id: 'YOUR_APP_ID'
|
97
|
-
heap_client.track 'user-
|
100
|
+
heap_client.track 'user-identity', 'event-name', property: 'value'
|
98
101
|
```
|
99
102
|
|
100
103
|
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
data/heap.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: heap 1.0.
|
5
|
+
# stub: heap 1.0.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "heap"
|
9
|
-
s.version = "1.0.
|
9
|
+
s.version = "1.0.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Victor Costan"]
|
14
|
-
s.date = "2016-
|
14
|
+
s.date = "2016-03-08"
|
15
15
|
s.description = "Implements Heap's server-side API"
|
16
16
|
s.email = "victor@heapanalytics.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -49,28 +49,34 @@ Gem::Specification.new do |s|
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
50
|
s.add_runtime_dependency(%q<faraday>, [">= 0.8.11"])
|
51
51
|
s.add_runtime_dependency(%q<faraday_middleware>, [">= 0.8.0"])
|
52
|
-
s.add_development_dependency(%q<minitest>, [">= 0"])
|
53
|
-
s.add_development_dependency(%q<yard>, [">= 0.8.7.6"])
|
54
|
-
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
55
52
|
s.add_development_dependency(%q<bundler>, [">= 1.0"])
|
53
|
+
s.add_development_dependency(%q<coveralls>, [">= 0.8.10"])
|
56
54
|
s.add_development_dependency(%q<jeweler>, [">= 2.0.1"])
|
55
|
+
s.add_development_dependency(%q<minitest>, [">= 5.8.4"])
|
56
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
57
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.11.2"])
|
58
|
+
s.add_development_dependency(%q<yard>, [">= 0.8.7.6"])
|
57
59
|
else
|
58
60
|
s.add_dependency(%q<faraday>, [">= 0.8.11"])
|
59
61
|
s.add_dependency(%q<faraday_middleware>, [">= 0.8.0"])
|
60
|
-
s.add_dependency(%q<minitest>, [">= 0"])
|
61
|
-
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
62
|
-
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
63
62
|
s.add_dependency(%q<bundler>, [">= 1.0"])
|
63
|
+
s.add_dependency(%q<coveralls>, [">= 0.8.10"])
|
64
64
|
s.add_dependency(%q<jeweler>, [">= 2.0.1"])
|
65
|
+
s.add_dependency(%q<minitest>, [">= 5.8.4"])
|
66
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
67
|
+
s.add_dependency(%q<simplecov>, [">= 0.11.2"])
|
68
|
+
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
65
69
|
end
|
66
70
|
else
|
67
71
|
s.add_dependency(%q<faraday>, [">= 0.8.11"])
|
68
72
|
s.add_dependency(%q<faraday_middleware>, [">= 0.8.0"])
|
69
|
-
s.add_dependency(%q<minitest>, [">= 0"])
|
70
|
-
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
71
|
-
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
72
73
|
s.add_dependency(%q<bundler>, [">= 1.0"])
|
74
|
+
s.add_dependency(%q<coveralls>, [">= 0.8.10"])
|
73
75
|
s.add_dependency(%q<jeweler>, [">= 2.0.1"])
|
76
|
+
s.add_dependency(%q<minitest>, [">= 5.8.4"])
|
77
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0.11.2"])
|
79
|
+
s.add_dependency(%q<yard>, [">= 0.8.7.6"])
|
74
80
|
end
|
75
81
|
end
|
76
82
|
|
data/lib/heap/client.rb
CHANGED
@@ -29,6 +29,7 @@ class HeapAPI::Client
|
|
29
29
|
#
|
30
30
|
# @param [Hash<Symbol, Object>] options initial values for attributes
|
31
31
|
# @option options [String] app_id the Heap application ID from
|
32
|
+
# https://heapanalytics.com/app/install
|
32
33
|
# @option options [Hash<Symbol, Object>] js_options default heap.js advanced
|
33
34
|
# options
|
34
35
|
# @option options [Boolean] stubbed if true, all the requests to the Heap API
|
@@ -66,12 +67,12 @@ class HeapAPI::Client
|
|
66
67
|
def faraday_adapter_args=(new_args)
|
67
68
|
raise RuntimeError, 'Faraday connection already initialized' if @connection
|
68
69
|
unless new_args.instance_of? Array
|
69
|
-
raise
|
70
|
+
raise ArgumentError, "Arguments must be an Array"
|
70
71
|
end
|
71
72
|
@faraday_adapter_args = new_args
|
72
73
|
end
|
73
74
|
|
74
|
-
#
|
75
|
+
# Assigns custom properties to an existing user.
|
75
76
|
#
|
76
77
|
# @param [String] identity an e-mail, handle, or Heap-generated user ID
|
77
78
|
# @param [Hash<String, String|Number>] properties key-value properties
|
@@ -81,6 +82,7 @@ class HeapAPI::Client
|
|
81
82
|
# @see https://heapanalytics.com/docs/server-side#identify
|
82
83
|
def add_user_properties(identity, properties)
|
83
84
|
ensure_valid_app_id!
|
85
|
+
ensure_valid_identity! identity
|
84
86
|
ensure_valid_properties! properties
|
85
87
|
|
86
88
|
body = {
|
@@ -109,6 +111,7 @@ class HeapAPI::Client
|
|
109
111
|
|
110
112
|
event_name = event.to_s
|
111
113
|
ensure_valid_event_name! event_name
|
114
|
+
ensure_valid_identity! identity
|
112
115
|
|
113
116
|
body = {
|
114
117
|
:app_id => @app_id,
|
data/lib/heap/validations.rb
CHANGED
@@ -23,6 +23,26 @@ class HeapAPI::Client
|
|
23
23
|
end
|
24
24
|
private :ensure_valid_event_name!
|
25
25
|
|
26
|
+
# Validates identity, making sure it is a valid string or integer.
|
27
|
+
#
|
28
|
+
# @param [String|Integer] identity
|
29
|
+
# @raise ArgumentError if identity is of an invalid type or too long.
|
30
|
+
# @return [HeapAPI::Client] self
|
31
|
+
def ensure_valid_identity!(identity)
|
32
|
+
identity = identity.to_s if identity.kind_of?(Integer)
|
33
|
+
|
34
|
+
if identity.kind_of?(String) || identity.kind_of?(Symbol)
|
35
|
+
if identity.to_s.length > 255
|
36
|
+
raise ArgumentError, "Identity field too long; " +
|
37
|
+
"#{identity.to_s.length} is above the 255-character limit"
|
38
|
+
end
|
39
|
+
else
|
40
|
+
raise ArgumentError,
|
41
|
+
"Unsupported type for identity value #{identity.inspect}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
private :ensure_valid_identity!
|
45
|
+
|
26
46
|
# Validates a bag of properties sent to a Heap server-side API.
|
27
47
|
#
|
28
48
|
# @param [Hash<String, String|Number>] properties key-value property bag;
|
@@ -16,17 +16,57 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
16
16
|
def test_add_user_properties_without_app_id
|
17
17
|
@heap.app_id = nil
|
18
18
|
exception = assert_raises RuntimeError do
|
19
|
-
@heap.add_user_properties 'test-
|
19
|
+
@heap.add_user_properties 'test-identity', 'key' => 'value'
|
20
20
|
end
|
21
21
|
assert_equal RuntimeError, exception.class
|
22
22
|
assert_equal 'Heap app_id not set', exception.message
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_add_user_properties_with_invalid_property_object
|
26
|
+
exception = assert_raises ArgumentError do
|
27
|
+
@heap.add_user_properties 'test-identity', false
|
28
|
+
end
|
29
|
+
assert_equal ArgumentError, exception.class
|
30
|
+
assert_equal 'Properties object does not implement #each',
|
31
|
+
exception.message
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_add_user_properties_with_long_string_identity
|
35
|
+
long_identity = 'A' * 256
|
36
|
+
|
37
|
+
exception = assert_raises ArgumentError do
|
38
|
+
@heap.add_user_properties long_identity, 'key' => 'value'
|
39
|
+
end
|
40
|
+
assert_equal ArgumentError, exception.class
|
41
|
+
assert_equal "Identity field too long; " +
|
42
|
+
'256 is above the 255-character limit', exception.message
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_add_user_properties_with_long_symbol_identity
|
46
|
+
long_identity = ('A' * 256).to_sym
|
47
|
+
|
48
|
+
exception = assert_raises ArgumentError do
|
49
|
+
@heap.add_user_properties long_identity, 'key' => 'value'
|
50
|
+
end
|
51
|
+
assert_equal ArgumentError, exception.class
|
52
|
+
assert_equal "Identity field too long; " +
|
53
|
+
'256 is above the 255-character limit', exception.message
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_add_user_properties_with_array_identity
|
57
|
+
exception = assert_raises ArgumentError do
|
58
|
+
@heap.add_user_properties([], 'key' => 'value')
|
59
|
+
end
|
60
|
+
assert_equal ArgumentError, exception.class
|
61
|
+
assert_equal 'Unsupported type for identity value []', exception.message
|
62
|
+
end
|
63
|
+
|
64
|
+
|
25
65
|
def test_add_user_properties_with_long_property_name
|
26
66
|
long_name = 'A' * 1025
|
27
67
|
|
28
68
|
exception = assert_raises ArgumentError do
|
29
|
-
@heap.add_user_properties 'test-
|
69
|
+
@heap.add_user_properties 'test-identity', long_name => 'value'
|
30
70
|
end
|
31
71
|
assert_equal ArgumentError, exception.class
|
32
72
|
assert_equal "Property name #{long_name} too long; " +
|
@@ -36,7 +76,8 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
36
76
|
def test_add_user_properties_with_long_string_property_value
|
37
77
|
long_value = 'A' * 1025
|
38
78
|
exception = assert_raises ArgumentError do
|
39
|
-
@heap.add_user_properties 'test-
|
79
|
+
@heap.add_user_properties 'test-identity',
|
80
|
+
'long_value_name' => long_value
|
40
81
|
end
|
41
82
|
assert_equal ArgumentError, exception.class
|
42
83
|
assert_equal "Property long_value_name value \"#{long_value}\" too " +
|
@@ -46,7 +87,8 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
46
87
|
def test_add_user_properties_with_long_symbol_property_value
|
47
88
|
long_value = ('A' * 1025).to_sym
|
48
89
|
exception = assert_raises ArgumentError do
|
49
|
-
@heap.add_user_properties 'test-
|
90
|
+
@heap.add_user_properties 'test-identity',
|
91
|
+
'long_value_name' => long_value
|
50
92
|
end
|
51
93
|
assert_equal ArgumentError, exception.class
|
52
94
|
assert_equal "Property long_value_name value :#{long_value} too long; " +
|
@@ -55,19 +97,18 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
55
97
|
|
56
98
|
def test_add_user_properties_with_array_property_value
|
57
99
|
exception = assert_raises ArgumentError do
|
58
|
-
@heap.add_user_properties 'test-
|
100
|
+
@heap.add_user_properties 'test-identity', 'array_value_name' => []
|
59
101
|
end
|
60
102
|
assert_equal ArgumentError, exception.class
|
61
103
|
assert_equal 'Unsupported type for property array_value_name value []',
|
62
104
|
exception.message
|
63
105
|
end
|
64
106
|
|
65
|
-
|
66
107
|
def test_add_user_properties
|
67
108
|
@stubs.post '/api/identify' do |env|
|
68
109
|
golden_body = {
|
69
110
|
'app_id' => 'test-app-id',
|
70
|
-
'identity' => 'test-
|
111
|
+
'identity' => 'test-identity',
|
71
112
|
'properties' => { 'foo' => 'bar', 'heap' => 'hurray' }
|
72
113
|
}
|
73
114
|
assert_equal 'application/json', env[:request_headers]['Content-Type']
|
@@ -77,17 +118,34 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
77
118
|
[200, { 'Content-Type' => 'text/plain; encoding=utf8' }, '']
|
78
119
|
end
|
79
120
|
|
80
|
-
assert_equal @heap, @heap.add_user_properties('test-
|
121
|
+
assert_equal @heap, @heap.add_user_properties('test-identity',
|
81
122
|
'foo' => 'bar', :heap => :hurray)
|
82
123
|
end
|
83
124
|
|
125
|
+
def test_add_user_properties_with_integer_identity
|
126
|
+
@stubs.post '/api/identify' do |env|
|
127
|
+
golden_body = {
|
128
|
+
'app_id' => 'test-app-id',
|
129
|
+
'identity' => '123456789',
|
130
|
+
'properties' => { 'foo' => 'bar' }
|
131
|
+
}
|
132
|
+
assert_equal 'application/json', env[:request_headers]['Content-Type']
|
133
|
+
assert_equal @heap.user_agent, env[:request_headers]['User-Agent']
|
134
|
+
assert_equal golden_body, JSON.parse(env[:body])
|
135
|
+
|
136
|
+
[200, { 'Content-Type' => 'text/plain; encoding=utf8' }, '']
|
137
|
+
end
|
138
|
+
|
139
|
+
assert_equal @heap, @heap.add_user_properties(123456789, 'foo' => 'bar')
|
140
|
+
end
|
141
|
+
|
84
142
|
def test_add_user_properties_error
|
85
143
|
@stubs.post '/api/identify' do |env|
|
86
144
|
[400, { 'Content-Type' => 'text/plain; encoding=utf8' }, 'Bad request']
|
87
145
|
end
|
88
146
|
|
89
147
|
exception = assert_raises HeapAPI::Error do
|
90
|
-
@heap.add_user_properties 'test-
|
148
|
+
@heap.add_user_properties 'test-identity', 'foo' => 'bar'
|
91
149
|
end
|
92
150
|
|
93
151
|
assert_equal HeapAPI::ApiError, exception.class
|
@@ -101,7 +159,7 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
101
159
|
@heap.faraday_adapter = :net_http
|
102
160
|
@heap.faraday_adapter_args = []
|
103
161
|
|
104
|
-
assert_equal @heap, @heap.add_user_properties('test-
|
162
|
+
assert_equal @heap, @heap.add_user_properties('test-identity',
|
105
163
|
'language/ruby' => 1, 'heap/heap-ruby' => 1)
|
106
164
|
end
|
107
165
|
|
@@ -110,7 +168,7 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
110
168
|
@heap.faraday_adapter_args = []
|
111
169
|
|
112
170
|
assert_raises HeapAPI::Error do
|
113
|
-
@heap.add_user_properties 'test-
|
171
|
+
@heap.add_user_properties 'test-identity',
|
114
172
|
'language/ruby' => 1, 'heap/heap-ruby' => 1
|
115
173
|
end
|
116
174
|
end
|
@@ -118,7 +176,7 @@ class ClientAddUserPropertiesTest < MiniTest::Test
|
|
118
176
|
def test_add_user_properties_with_stubbed_connection
|
119
177
|
@heap.stubbed = true
|
120
178
|
|
121
|
-
assert_equal @heap, @heap.add_user_properties('test-
|
179
|
+
assert_equal @heap, @heap.add_user_properties('test-identity',
|
122
180
|
'foo' => 'bar', :heap => :hurray)
|
123
181
|
end
|
124
182
|
end
|
data/test/client_test.rb
CHANGED
@@ -36,18 +36,26 @@ class ClientTest < MiniTest::Test
|
|
36
36
|
assert_equal [stubs], @heap.faraday_adapter_args
|
37
37
|
end
|
38
38
|
|
39
|
+
def test_faraday_adapter_args_setter_with_invalid_value
|
40
|
+
exception = assert_raises ArgumentError do
|
41
|
+
@heap.faraday_adapter_args = false
|
42
|
+
end
|
43
|
+
assert_equal ArgumentError, exception.class
|
44
|
+
assert_equal 'Arguments must be an Array', exception.message
|
45
|
+
end
|
46
|
+
|
39
47
|
def test_stubbed_setter
|
40
48
|
@heap.app_id = 'test-app-id'
|
41
49
|
@heap.faraday_adapter = :net_http
|
42
50
|
|
43
51
|
@heap.stubbed = true
|
44
|
-
assert_equal @heap, @heap.track('test_stubbed_setter', 'test-
|
52
|
+
assert_equal @heap, @heap.track('test_stubbed_setter', 'test-identity',
|
45
53
|
'language' => 'ruby', 'project' => 'heap/heap-ruby')
|
46
54
|
stubbed_connection = @heap.connection
|
47
55
|
|
48
56
|
@heap.stubbed = false
|
49
57
|
assert_raises HeapAPI::Error do
|
50
|
-
@heap.track 'test_stubbed_setter', 'test-
|
58
|
+
@heap.track 'test_stubbed_setter', 'test-identity',
|
51
59
|
'language' => 'ruby', 'project' => 'heap/heap-ruby'
|
52
60
|
end
|
53
61
|
live_connection = @heap.connection
|
data/test/client_track_test.rb
CHANGED
@@ -17,7 +17,7 @@ class ClientTrackTest < MiniTest::Test
|
|
17
17
|
def test_track_without_app_id
|
18
18
|
@heap.app_id = nil
|
19
19
|
exception = assert_raises RuntimeError do
|
20
|
-
@heap.track 'test_track_without_app_id', 'test-
|
20
|
+
@heap.track 'test_track_without_app_id', 'test-identity'
|
21
21
|
end
|
22
22
|
assert_equal RuntimeError, exception.class
|
23
23
|
assert_equal 'Heap app_id not set', exception.message
|
@@ -25,7 +25,7 @@ class ClientTrackTest < MiniTest::Test
|
|
25
25
|
|
26
26
|
def test_track_without_event_name
|
27
27
|
exception = assert_raises ArgumentError do
|
28
|
-
@heap.track '', 'test-
|
28
|
+
@heap.track '', 'test-identity'
|
29
29
|
end
|
30
30
|
assert_equal ArgumentError, exception.class
|
31
31
|
assert_equal 'Missing or empty event name', exception.message
|
@@ -33,16 +33,55 @@ class ClientTrackTest < MiniTest::Test
|
|
33
33
|
|
34
34
|
def test_track_with_long_event_name
|
35
35
|
exception = assert_raises ArgumentError do
|
36
|
-
@heap.track 'A' * 1025, 'test-
|
36
|
+
@heap.track 'A' * 1025, 'test-identity'
|
37
37
|
end
|
38
38
|
assert_equal ArgumentError, exception.class
|
39
39
|
assert_equal 'Event name too long', exception.message
|
40
40
|
end
|
41
41
|
|
42
|
+
def test_track_with_long_string_identity
|
43
|
+
long_identity = 'A' * 256
|
44
|
+
|
45
|
+
exception = assert_raises ArgumentError do
|
46
|
+
@heap.track 'some-event', long_identity
|
47
|
+
end
|
48
|
+
assert_equal ArgumentError, exception.class
|
49
|
+
assert_equal "Identity field too long; " +
|
50
|
+
'256 is above the 255-character limit', exception.message
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_track_with_long_symbol_identity
|
54
|
+
long_identity = ('A' * 256).to_sym
|
55
|
+
|
56
|
+
exception = assert_raises ArgumentError do
|
57
|
+
@heap.track 'some-event', long_identity
|
58
|
+
end
|
59
|
+
assert_equal ArgumentError, exception.class
|
60
|
+
assert_equal "Identity field too long; " +
|
61
|
+
'256 is above the 255-character limit', exception.message
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_track_with_array_identity
|
65
|
+
exception = assert_raises ArgumentError do
|
66
|
+
@heap.track 'test_track_with_array_property_value', []
|
67
|
+
end
|
68
|
+
assert_equal ArgumentError, exception.class
|
69
|
+
assert_equal 'Unsupported type for identity value []', exception.message
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_track_with_invalid_property_object
|
73
|
+
exception = assert_raises ArgumentError do
|
74
|
+
@heap.track 'test_track_with_long_property_name', 'test-identity', false
|
75
|
+
end
|
76
|
+
assert_equal ArgumentError, exception.class
|
77
|
+
assert_equal 'Properties object does not implement #each',
|
78
|
+
exception.message
|
79
|
+
end
|
80
|
+
|
42
81
|
def test_track_with_long_property_name
|
43
82
|
long_name = 'A' * 1025
|
44
83
|
exception = assert_raises ArgumentError do
|
45
|
-
@heap.track 'test_track_with_long_property_name', 'test-
|
84
|
+
@heap.track 'test_track_with_long_property_name', 'test-identity',
|
46
85
|
long_name => 'value'
|
47
86
|
end
|
48
87
|
assert_equal ArgumentError, exception.class
|
@@ -53,8 +92,8 @@ class ClientTrackTest < MiniTest::Test
|
|
53
92
|
def test_track_with_long_string_property_value
|
54
93
|
long_value = 'A' * 1025
|
55
94
|
exception = assert_raises ArgumentError do
|
56
|
-
@heap.track 'test_track_with_long_string_property_value',
|
57
|
-
'long_value_name' => long_value
|
95
|
+
@heap.track 'test_track_with_long_string_property_value',
|
96
|
+
'test-identity', 'long_value_name' => long_value
|
58
97
|
end
|
59
98
|
assert_equal ArgumentError, exception.class
|
60
99
|
assert_equal "Property long_value_name value \"#{long_value}\" too " +
|
@@ -64,19 +103,46 @@ class ClientTrackTest < MiniTest::Test
|
|
64
103
|
def test_track_with_long_symbol_property_value
|
65
104
|
long_value = ('A' * 1025).to_sym
|
66
105
|
exception = assert_raises ArgumentError do
|
67
|
-
@heap.track 'test_track_with_long_symbol_property_value',
|
68
|
-
'long_value_name' => long_value
|
106
|
+
@heap.track 'test_track_with_long_symbol_property_value',
|
107
|
+
'test-identity', 'long_value_name' => long_value
|
69
108
|
end
|
70
109
|
assert_equal ArgumentError, exception.class
|
71
110
|
assert_equal "Property long_value_name value :#{long_value} too long; " +
|
72
111
|
'1025 is above the 1024-character limit', exception.message
|
73
112
|
end
|
74
113
|
|
114
|
+
def test_track_with_array_property_value
|
115
|
+
exception = assert_raises ArgumentError do
|
116
|
+
@heap.track 'test_track_with_array_property_value', 'test-identity',
|
117
|
+
'array_value_name' => []
|
118
|
+
end
|
119
|
+
assert_equal ArgumentError, exception.class
|
120
|
+
assert_equal 'Unsupported type for property array_value_name value []',
|
121
|
+
exception.message
|
122
|
+
end
|
123
|
+
|
75
124
|
def test_track
|
76
125
|
@stubs.post '/api/track' do |env|
|
77
126
|
golden_body = {
|
78
127
|
'app_id' => 'test-app-id',
|
79
|
-
'identity' => 'test-
|
128
|
+
'identity' => 'test-identity',
|
129
|
+
'event' => 'test_track',
|
130
|
+
}
|
131
|
+
assert_equal 'application/json', env[:request_headers]['Content-Type']
|
132
|
+
assert_equal @heap.user_agent, env[:request_headers]['User-Agent']
|
133
|
+
assert_equal golden_body, JSON.parse(env[:body])
|
134
|
+
|
135
|
+
[200, { 'Content-Type' => 'text/plain; encoding=utf8' }, '']
|
136
|
+
end
|
137
|
+
|
138
|
+
assert_equal @heap, @heap.track('test_track', 'test-identity')
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_track_with_integer_identity
|
142
|
+
@stubs.post '/api/track' do |env|
|
143
|
+
golden_body = {
|
144
|
+
'app_id' => 'test-app-id',
|
145
|
+
'identity' => '123456789',
|
80
146
|
'event' => 'test_track',
|
81
147
|
}
|
82
148
|
assert_equal 'application/json', env[:request_headers]['Content-Type']
|
@@ -86,14 +152,14 @@ class ClientTrackTest < MiniTest::Test
|
|
86
152
|
[200, { 'Content-Type' => 'text/plain; encoding=utf8' }, '']
|
87
153
|
end
|
88
154
|
|
89
|
-
assert_equal @heap, @heap.track('test_track',
|
155
|
+
assert_equal @heap, @heap.track('test_track', 123456789)
|
90
156
|
end
|
91
157
|
|
92
158
|
def test_track_with_properties
|
93
159
|
@stubs.post '/api/track' do |env|
|
94
160
|
golden_body = {
|
95
161
|
'app_id' => 'test-app-id',
|
96
|
-
'identity' => 'test-
|
162
|
+
'identity' => 'test-identity',
|
97
163
|
'event' => 'test_track_with_properties',
|
98
164
|
'properties' => { 'foo' => 'bar', 'heap' => 'hurray' }
|
99
165
|
}
|
@@ -105,7 +171,7 @@ class ClientTrackTest < MiniTest::Test
|
|
105
171
|
end
|
106
172
|
|
107
173
|
assert_equal @heap, @heap.track('test_track_with_properties',
|
108
|
-
'test-
|
174
|
+
'test-identity','foo' => 'bar', :heap => :hurray)
|
109
175
|
end
|
110
176
|
|
111
177
|
def test_track_error
|
@@ -114,7 +180,7 @@ class ClientTrackTest < MiniTest::Test
|
|
114
180
|
end
|
115
181
|
|
116
182
|
exception = assert_raises HeapAPI::Error do
|
117
|
-
@heap.track('test-
|
183
|
+
@heap.track('test-identity', 'test_track')
|
118
184
|
end
|
119
185
|
assert_equal HeapAPI::ApiError, exception.class
|
120
186
|
assert_equal 'Heap API server error: 400 Bad request', exception.message
|
@@ -127,7 +193,7 @@ class ClientTrackTest < MiniTest::Test
|
|
127
193
|
@heap.faraday_adapter = :net_http
|
128
194
|
@heap.faraday_adapter_args = []
|
129
195
|
|
130
|
-
assert_equal @heap, @heap.track('test_track_integration', 'test-
|
196
|
+
assert_equal @heap, @heap.track('test_track_integration', 'test-identity',
|
131
197
|
'language' => 'ruby', 'project' => 'heap/heap-ruby')
|
132
198
|
end
|
133
199
|
|
@@ -136,7 +202,7 @@ class ClientTrackTest < MiniTest::Test
|
|
136
202
|
@heap.faraday_adapter_args = []
|
137
203
|
|
138
204
|
assert_raises HeapAPI::Error do
|
139
|
-
@heap.track('test_track_integration', 'test-
|
205
|
+
@heap.track('test_track_integration', 'test-identity',
|
140
206
|
'language' => 'ruby', 'project' => 'heap/heap-ruby')
|
141
207
|
end
|
142
208
|
end
|
@@ -145,7 +211,7 @@ class ClientTrackTest < MiniTest::Test
|
|
145
211
|
def test_track_with_stubbed_connection
|
146
212
|
@heap.stubbed = true
|
147
213
|
|
148
|
-
assert_equal @heap, @heap.add_user_properties('test-
|
214
|
+
assert_equal @heap, @heap.add_user_properties('test-identity',
|
149
215
|
'foo' => 'bar', :heap => :hurray)
|
150
216
|
end
|
151
217
|
end
|
data/test/helper.rb
CHANGED
@@ -1,3 +1,29 @@
|
|
1
|
+
if RUBY_VERSION >= '1.9' # simplecov only works on MRI 1.9+
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
module SimpleCov::Configuration
|
6
|
+
def clean_filters
|
7
|
+
@filters = []
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
SimpleCov.configure do
|
12
|
+
clean_filters
|
13
|
+
load_adapter 'test_frameworks'
|
14
|
+
end
|
15
|
+
|
16
|
+
SimpleCov.formatters = [
|
17
|
+
SimpleCov::Formatter::HTMLFormatter,
|
18
|
+
Coveralls::SimpleCov::Formatter,
|
19
|
+
]
|
20
|
+
|
21
|
+
ENV["COVERAGE"] && SimpleCov.start do
|
22
|
+
add_filter "/.rvm/"
|
23
|
+
add_filter "/.rbenv/"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
1
27
|
require 'rubygems'
|
2
28
|
require 'bundler'
|
3
29
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Costan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -39,33 +39,61 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '1.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: '0'
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.8.
|
61
|
+
version: 0.8.10
|
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: 0.8.
|
68
|
+
version: 0.8.10
|
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: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.8.4
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.8.4
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rdoc
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,33 +109,33 @@ dependencies:
|
|
81
109
|
- !ruby/object:Gem::Version
|
82
110
|
version: '3.12'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: simplecov
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
88
116
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
117
|
+
version: 0.11.2
|
90
118
|
type: :development
|
91
119
|
prerelease: false
|
92
120
|
version_requirements: !ruby/object:Gem::Requirement
|
93
121
|
requirements:
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
124
|
+
version: 0.11.2
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: yard
|
99
127
|
requirement: !ruby/object:Gem::Requirement
|
100
128
|
requirements:
|
101
129
|
- - ">="
|
102
130
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
131
|
+
version: 0.8.7.6
|
104
132
|
type: :development
|
105
133
|
prerelease: false
|
106
134
|
version_requirements: !ruby/object:Gem::Requirement
|
107
135
|
requirements:
|
108
136
|
- - ">="
|
109
137
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
138
|
+
version: 0.8.7.6
|
111
139
|
description: Implements Heap's server-side API
|
112
140
|
email: victor@heapanalytics.com
|
113
141
|
executables: []
|