mixpanel-ruby 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.rdoc +7 -1
- data/lib/mixpanel-ruby/consumer.rb +5 -14
- data/lib/mixpanel-ruby/error.rb +46 -0
- data/lib/mixpanel-ruby/events.rb +13 -8
- data/lib/mixpanel-ruby/people.rb +23 -17
- data/lib/mixpanel-ruby/tracker.rb +8 -7
- data/lib/mixpanel-ruby/version.rb +1 -1
- data/mixpanel-ruby.gemspec +1 -0
- data/spec/mixpanel-ruby/consumer_spec.rb +2 -1
- data/spec/mixpanel-ruby/error_spec.rb +76 -0
- data/spec/mixpanel-ruby/events_spec.rb +2 -1
- data/spec/mixpanel-ruby/people_spec.rb +19 -2
- data/spec/mixpanel-ruby/tracker_spec.rb +2 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffb9a7cb934ae663374cf0850ba2049e77ad6844
|
4
|
+
data.tar.gz: 577cf98aaeb43e608a7d50e0b37d49b2437dd298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e768a749828219fd77e9d3b4c29810d2f92a47b6ec8d4f6e0ab92f977d6f540b1c57bba0881f73d18fb59073a1e97da8688fe0a3cc8d4d10aefe6825aa36870
|
7
|
+
data.tar.gz: c19c92bcbb59663e617ba24eb6df74662e67e08605cbb535040185d5d66c28206c70d5f34268d1e98a0e98558707772dc338f57c61f1bc6cfcd0a127bc7bd9a4
|
data/Readme.rdoc
CHANGED
@@ -13,7 +13,7 @@ updates to \Mixpanel from your ruby applications.
|
|
13
13
|
|
14
14
|
require 'mixpanel-ruby'
|
15
15
|
|
16
|
-
tracker = Mixpanel::Tracker.new(
|
16
|
+
tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
17
17
|
|
18
18
|
# Track an event on behalf of user "User1"
|
19
19
|
tracker.track('User1', 'A Mixpanel Event')
|
@@ -49,6 +49,12 @@ In particular, for Rails apps, the following projects are currently actively mai
|
|
49
49
|
|
50
50
|
== Changes
|
51
51
|
|
52
|
+
== 2.2.0
|
53
|
+
* Add Mixpanel::ErrorHandler to simplify custom error handling.
|
54
|
+
* Modify Mixpanel::People#fix_property_dates to handle ActiveSupport::TimeWithZone.
|
55
|
+
* Increase open and ssl timeouts from 2s to 10s.
|
56
|
+
* Fix Doc inconsistancy: always pass token on Mixpanel::tracker.new.
|
57
|
+
|
52
58
|
== 2.1.0
|
53
59
|
* Add Mixpanel::Tracker#generate_tracking_url, which generates {pixel tracking urls}[https://mixpanel.com/docs/api-documentation/pixel-based-event-tracking].
|
54
60
|
* Rescue JSONErrors in the consumer and raise Mixpanel::ServerError in Mixpanel::Consumer#send!.
|
@@ -1,17 +1,8 @@
|
|
1
1
|
require 'base64'
|
2
|
-
require 'net/https'
|
3
2
|
require 'json'
|
3
|
+
require 'net/https'
|
4
4
|
|
5
5
|
module Mixpanel
|
6
|
-
class MixpanelError < StandardError
|
7
|
-
end
|
8
|
-
|
9
|
-
class ConnectionError < MixpanelError
|
10
|
-
end
|
11
|
-
|
12
|
-
class ServerError < MixpanelError
|
13
|
-
end
|
14
|
-
|
15
6
|
@@init_http = nil
|
16
7
|
|
17
8
|
# This method exists for backwards compatibility. The preferred
|
@@ -44,7 +35,7 @@ module Mixpanel
|
|
44
35
|
# either by passing in an argument with a #send! method when you construct
|
45
36
|
# the tracker, or just passing a block to Mixpanel::Tracker.new
|
46
37
|
#
|
47
|
-
# tracker = Mixpanel::Tracker.new(
|
38
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN) do |type, message|
|
48
39
|
# # type will be one of :event, :profile_update or :import
|
49
40
|
# @kestrel.set(ANALYTICS_QUEUE, [type, message].to_json)
|
50
41
|
# end
|
@@ -134,10 +125,10 @@ module Mixpanel
|
|
134
125
|
|
135
126
|
client = Net::HTTP.new(uri.host, uri.port)
|
136
127
|
client.use_ssl = true
|
137
|
-
client.open_timeout =
|
128
|
+
client.open_timeout = 10
|
138
129
|
client.continue_timeout = 10
|
139
130
|
client.read_timeout = 10
|
140
|
-
client.ssl_timeout =
|
131
|
+
client.ssl_timeout = 10
|
141
132
|
|
142
133
|
Mixpanel.with_http(client)
|
143
134
|
|
@@ -157,7 +148,7 @@ module Mixpanel
|
|
157
148
|
#
|
158
149
|
# buffered_consumer = Mixpanel::BufferedConsumer.new
|
159
150
|
# begin
|
160
|
-
# buffered_tracker = Mixpanel::Tracker.new(
|
151
|
+
# buffered_tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN) do |type, message|
|
161
152
|
# buffered_consumer.send!(type, message)
|
162
153
|
# end
|
163
154
|
# # Do some tracking here
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Mixpanel
|
2
|
+
|
3
|
+
# Mixpanel specific errors that are thrown in the gem.
|
4
|
+
# In the default consumer we catch all errors and raise
|
5
|
+
# Mixpanel specific errors that can be handled using a
|
6
|
+
# custom error handler.
|
7
|
+
class MixpanelError < StandardError
|
8
|
+
end
|
9
|
+
|
10
|
+
class ConnectionError < MixpanelError
|
11
|
+
end
|
12
|
+
|
13
|
+
class ServerError < MixpanelError
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
# The default behavior of the gem is to silence all errors
|
18
|
+
# thrown in the consumer. If you wish to handle MixpanelErrors
|
19
|
+
# yourself you can pass an instance of a class that extends
|
20
|
+
# Mixpanel::ErrorHandler to Mixpanel::Tracker on initialize.
|
21
|
+
#
|
22
|
+
# require 'logger'
|
23
|
+
#
|
24
|
+
# class MyErrorHandler < Mixpanel::ErrorHandler
|
25
|
+
#
|
26
|
+
# def initialize
|
27
|
+
# @logger = Logger.new('mylogfile.log')
|
28
|
+
# @logger.level = Logger::ERROR
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# def handle(error)
|
32
|
+
# logger.error "#{error.inspect}\n Backtrace: #{error.backtrace}"
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# my_error_handler = MyErrorHandler.new
|
38
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN, my_error_handler)
|
39
|
+
class ErrorHandler
|
40
|
+
|
41
|
+
# Override #handle to customize error handling
|
42
|
+
def handle(error)
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/mixpanel-ruby/events.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
require 'mixpanel-ruby/consumer'
|
2
1
|
require 'time'
|
3
2
|
|
3
|
+
require 'mixpanel-ruby/consumer'
|
4
|
+
require 'mixpanel-ruby/error'
|
5
|
+
|
4
6
|
module Mixpanel
|
5
7
|
|
6
8
|
# Handles formatting Mixpanel event tracking messages
|
@@ -8,7 +10,7 @@ module Mixpanel
|
|
8
10
|
# is a subclass of this class, and the best way to
|
9
11
|
# track events is to instantiate a Mixpanel::Tracker
|
10
12
|
#
|
11
|
-
# tracker = Mixpanel::Tracker.new # Has all of the methods of Mixpanel::Event
|
13
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN) # Has all of the methods of Mixpanel::Event
|
12
14
|
# tracker.track(...)
|
13
15
|
#
|
14
16
|
class Events
|
@@ -18,10 +20,11 @@ module Mixpanel
|
|
18
20
|
# is to use Mixpanel::Tracker
|
19
21
|
#
|
20
22
|
# # tracker has all of the methods of Mixpanel::Events
|
21
|
-
# tracker = Mixpanel::Tracker.new(
|
23
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
22
24
|
#
|
23
|
-
def initialize(token, &block)
|
25
|
+
def initialize(token, error_handler=nil, &block)
|
24
26
|
@token = token
|
27
|
+
@error_handler = error_handler || ErrorHandler.new
|
25
28
|
|
26
29
|
if block
|
27
30
|
@sink = block
|
@@ -37,7 +40,7 @@ module Mixpanel
|
|
37
40
|
# describing that event. Properties are provided as a Hash with
|
38
41
|
# string keys and strings, numbers or booleans as values.
|
39
42
|
#
|
40
|
-
# tracker = Mixpanel::Tracker.new
|
43
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
41
44
|
#
|
42
45
|
# # Track that user "12345"'s credit card was declined
|
43
46
|
# tracker.track("12345", "Credit Card Declined")
|
@@ -68,7 +71,8 @@ module Mixpanel
|
|
68
71
|
ret = true
|
69
72
|
begin
|
70
73
|
@sink.call(:event, message.to_json)
|
71
|
-
rescue MixpanelError
|
74
|
+
rescue MixpanelError => e
|
75
|
+
@error_handler.handle(e)
|
72
76
|
ret = false
|
73
77
|
end
|
74
78
|
|
@@ -83,7 +87,7 @@ module Mixpanel
|
|
83
87
|
# we pass the time of the method call as the time the event occured, if you
|
84
88
|
# wish to override this pass a timestamp in the properties hash.
|
85
89
|
#
|
86
|
-
# tracker = Mixpanel::Tracker.new
|
90
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
87
91
|
#
|
88
92
|
# # Track that user "12345"'s credit card was declined
|
89
93
|
# tracker.import("API_KEY", "12345", "Credit Card Declined")
|
@@ -118,7 +122,8 @@ module Mixpanel
|
|
118
122
|
ret = true
|
119
123
|
begin
|
120
124
|
@sink.call(:import, message.to_json)
|
121
|
-
rescue MixpanelError
|
125
|
+
rescue MixpanelError => e
|
126
|
+
@error_handler.handle(e)
|
122
127
|
ret = false
|
123
128
|
end
|
124
129
|
|
data/lib/mixpanel-ruby/people.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
require 'mixpanel-ruby/consumer'
|
2
|
-
require 'json'
|
3
1
|
require 'date'
|
2
|
+
require 'json'
|
4
3
|
require 'time'
|
5
4
|
|
5
|
+
require 'mixpanel-ruby/consumer'
|
6
|
+
require 'mixpanel-ruby/error'
|
7
|
+
|
6
8
|
module Mixpanel
|
7
9
|
|
8
10
|
# Handles formatting Mixpanel profile updates and
|
@@ -17,11 +19,12 @@ module Mixpanel
|
|
17
19
|
# You likely won't need to instantiate instances of Mixpanel::People
|
18
20
|
# directly. The best way to get an instance of Mixpanel::People is
|
19
21
|
#
|
20
|
-
# tracker = Mixpanel::Tracker.new(
|
22
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
21
23
|
# tracker.people # An instance of Mixpanel::People
|
22
24
|
#
|
23
|
-
def initialize(token, &block)
|
25
|
+
def initialize(token, error_handler=nil, &block)
|
24
26
|
@token = token
|
27
|
+
@error_handler = error_handler || ErrorHandler.new
|
25
28
|
|
26
29
|
if block
|
27
30
|
@sink = block
|
@@ -35,7 +38,7 @@ module Mixpanel
|
|
35
38
|
# keys, and values that are strings, numbers, booleans, or
|
36
39
|
# DateTimes
|
37
40
|
#
|
38
|
-
# tracker = Mixpanel::Tracker.new
|
41
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
39
42
|
# # Sets properties on profile with id "1234"
|
40
43
|
# tracker.people.set("1234", {
|
41
44
|
# 'company' => 'Acme',
|
@@ -61,7 +64,7 @@ module Mixpanel
|
|
61
64
|
# in the profile. That means you can call set_once many times
|
62
65
|
# without changing an original value.
|
63
66
|
#
|
64
|
-
# tracker = Mixpanel::Tracker.new
|
67
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
65
68
|
# tracker.people.set_once("12345", {
|
66
69
|
# 'First Login Date': DateTime.now
|
67
70
|
# });
|
@@ -83,7 +86,7 @@ module Mixpanel
|
|
83
86
|
# property. If no property exists with a given name, the value
|
84
87
|
# will be added to zero.
|
85
88
|
#
|
86
|
-
# tracker = Mixpanel::Tracker.new
|
89
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
87
90
|
# tracker.people.increment("12345", {
|
88
91
|
# 'Coins Spent' => 7,
|
89
92
|
# 'Coins Earned' => -7, # Use a negative number to subtract
|
@@ -104,7 +107,7 @@ module Mixpanel
|
|
104
107
|
# by one. Calling #plus_one(distinct_id, property_name) is the same as calling
|
105
108
|
# #increment(distinct_id, {property_name => 1})
|
106
109
|
#
|
107
|
-
# tracker = Mixpanel::Tracker.new
|
110
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
108
111
|
# tracker.people.plus_one("12345", "Albums Released")
|
109
112
|
#
|
110
113
|
def plus_one(distinct_id, property_name, ip=nil, optional_params={})
|
@@ -115,7 +118,7 @@ module Mixpanel
|
|
115
118
|
# If the given properties don't exist, a new list-valued
|
116
119
|
# property will be created.
|
117
120
|
#
|
118
|
-
# tracker = Mixpanel::Tracker.new
|
121
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
119
122
|
# tracker.people.append("12345", {
|
120
123
|
# 'Login Dates' => DateTime.now,
|
121
124
|
# 'Alter Ego Names' => 'Ziggy Stardust'
|
@@ -138,7 +141,7 @@ module Mixpanel
|
|
138
141
|
# property. After a union, every element in the list associated
|
139
142
|
# with a property will be unique.
|
140
143
|
#
|
141
|
-
# tracker = Mixpanel::Tracker.new
|
144
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
142
145
|
# tracker.people.union("12345", {
|
143
146
|
# 'Levels Completed' => ['Suffragette City']
|
144
147
|
# });
|
@@ -156,7 +159,7 @@ module Mixpanel
|
|
156
159
|
|
157
160
|
# Removes properties and their values from a profile.
|
158
161
|
#
|
159
|
-
# tracker = Mixpanel::Tracker.new
|
162
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
160
163
|
#
|
161
164
|
# # removes a single property and its value from a profile
|
162
165
|
# tracker.people.unset("12345", "Overdue Since")
|
@@ -178,7 +181,7 @@ module Mixpanel
|
|
178
181
|
# Records a payment to you to a profile. Charges recorded with
|
179
182
|
# #track_charge will appear in the \Mixpanel revenue report.
|
180
183
|
#
|
181
|
-
# tracker = Mixpanel::Tracker.new
|
184
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
182
185
|
#
|
183
186
|
# # records a charge of $25.32 from user 12345
|
184
187
|
# tracker.people.track_charge("12345", 25.32)
|
@@ -228,7 +231,8 @@ module Mixpanel
|
|
228
231
|
ret = true
|
229
232
|
begin
|
230
233
|
@sink.call(:profile_update, message.to_json)
|
231
|
-
rescue MixpanelError
|
234
|
+
rescue MixpanelError => e
|
235
|
+
@error_handler.handle(e)
|
232
236
|
ret = false
|
233
237
|
end
|
234
238
|
|
@@ -237,10 +241,12 @@ module Mixpanel
|
|
237
241
|
|
238
242
|
private
|
239
243
|
|
240
|
-
def fix_property_dates(
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
+
def fix_property_dates(properties)
|
245
|
+
properties.inject({}) do |ret, (key, value)|
|
246
|
+
value = value.respond_to?(:new_offset) ? value.new_offset('0') : value
|
247
|
+
value = value.respond_to?(:utc) ? value.utc : value # Handle ActiveSupport::TimeWithZone
|
248
|
+
|
249
|
+
ret[key] = value.respond_to?(:strftime) ? value.strftime('%Y-%m-%dT%H:%M:%S') : value
|
244
250
|
ret
|
245
251
|
end
|
246
252
|
end
|
@@ -42,10 +42,10 @@ module Mixpanel
|
|
42
42
|
# If a block is provided, it is passed a type (one of :event or :profile_update)
|
43
43
|
# and a string message. This same format is accepted by Mixpanel::Consumer#send!
|
44
44
|
# and Mixpanel::BufferedConsumer#send!
|
45
|
-
def initialize(token, &block)
|
46
|
-
super(token, &block)
|
45
|
+
def initialize(token, error_handler=nil, &block)
|
46
|
+
super(token, error_handler, &block)
|
47
47
|
@token = token
|
48
|
-
@people = People.new(token, &block)
|
48
|
+
@people = People.new(token, error_handler, &block)
|
49
49
|
end
|
50
50
|
|
51
51
|
# A call to #track is a report that an event has occurred. #track
|
@@ -55,7 +55,7 @@ module Mixpanel
|
|
55
55
|
# as a Hash with string keys and strings, numbers or booleans as
|
56
56
|
# values.
|
57
57
|
#
|
58
|
-
# tracker = Mixpanel::Tracker.new
|
58
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
59
59
|
#
|
60
60
|
# # Track that user "12345"'s credit card was declined
|
61
61
|
# tracker.track("12345", "Credit Card Declined")
|
@@ -79,7 +79,7 @@ module Mixpanel
|
|
79
79
|
# as a Hash with string keys and strings, numbers or booleans as
|
80
80
|
# values.
|
81
81
|
#
|
82
|
-
# tracker = Mixpanel::Tracker.new
|
82
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
83
83
|
#
|
84
84
|
# # Import event that user "12345"'s credit card was declined
|
85
85
|
# tracker.import("API_KEY", "12345", "Credit Card Declined", {
|
@@ -125,7 +125,8 @@ module Mixpanel
|
|
125
125
|
ret = true
|
126
126
|
begin
|
127
127
|
consumer.send!(:event, message.to_json)
|
128
|
-
rescue MixpanelError
|
128
|
+
rescue MixpanelError => e
|
129
|
+
@error_handler.handle(e)
|
129
130
|
ret = false
|
130
131
|
end
|
131
132
|
|
@@ -140,7 +141,7 @@ module Mixpanel
|
|
140
141
|
# strings, numbers or booleans as values. For more information, please see:
|
141
142
|
# https://mixpanel.com/docs/api-documentation/pixel-based-event-tracking
|
142
143
|
#
|
143
|
-
# tracker = Mixpanel::Tracker.new
|
144
|
+
# tracker = Mixpanel::Tracker.new(YOUR_MIXPANEL_TOKEN)
|
144
145
|
#
|
145
146
|
# # generate pixel tracking url in order to track that user
|
146
147
|
# # "12345"'s credit card was declined
|
data/mixpanel-ruby.gemspec
CHANGED
@@ -14,6 +14,7 @@ spec = Gem::Specification.new do |spec|
|
|
14
14
|
|
15
15
|
spec.required_ruby_version = '>= 2.0.0'
|
16
16
|
|
17
|
+
spec.add_development_dependency 'activesupport', '~> 4.0'
|
17
18
|
spec.add_development_dependency 'rake', '~> 0'
|
18
19
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
19
20
|
spec.add_development_dependency 'webmock', '~> 1.18'
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'mixpanel-ruby/error.rb'
|
4
|
+
require 'mixpanel-ruby/events.rb'
|
5
|
+
|
6
|
+
class TestErrorHandler < Mixpanel::ErrorHandler
|
7
|
+
def initialize(log)
|
8
|
+
@log = log
|
9
|
+
end
|
10
|
+
|
11
|
+
def handle(error)
|
12
|
+
@log << error.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe Mixpanel::ErrorHandler do
|
17
|
+
it "should respond to #handle`" do
|
18
|
+
error_handler = Mixpanel::ErrorHandler.new
|
19
|
+
expect(error_handler.respond_to?(:handle)).to be true
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'without a customer error_handler' do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@tracker = Mixpanel::Tracker.new('TEST TOKEN') do |type, message|
|
26
|
+
raise Mixpanel::MixpanelError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should silence errors in track calls" do
|
31
|
+
expect {
|
32
|
+
expect(@tracker.track('TEST ID', 'Test Event')).to be false
|
33
|
+
}.to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should handle errors in import calls" do
|
37
|
+
expect {
|
38
|
+
expect(@tracker.import('TEST API KEY', 'TEST DISTINCT_ID', 'Test Event')).to be false
|
39
|
+
}.to_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should handle errors in people calls" do
|
43
|
+
expect {
|
44
|
+
expect(@tracker.people.set('TEST ID', {})).to be false
|
45
|
+
}.to_not raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'with a custom error_handler' do
|
51
|
+
|
52
|
+
before(:each) do
|
53
|
+
@log = []
|
54
|
+
@error_handler = TestErrorHandler.new(@log)
|
55
|
+
@tracker = Mixpanel::Tracker.new('TEST TOKEN', @error_handler) do |type, message|
|
56
|
+
raise Mixpanel::MixpanelError
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should handle errors in track calls" do
|
61
|
+
@tracker.track('TEST ID', 'Test Event', {})
|
62
|
+
expect(@log).to eq(['Mixpanel::MixpanelError'])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should handle errors in import calls" do
|
66
|
+
@tracker.import('TEST API KEY', 'TEST DISTINCT_ID', 'Test Event')
|
67
|
+
expect(@log).to eq(['Mixpanel::MixpanelError'])
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should handle errors in people calls" do
|
71
|
+
@tracker.people.set('TEST ID', {})
|
72
|
+
expect(@log).to eq(['Mixpanel::MixpanelError'])
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'active_support/time'
|
3
|
+
|
2
4
|
require 'mixpanel-ruby/people'
|
3
5
|
|
4
6
|
describe Mixpanel::People do
|
@@ -44,14 +46,29 @@ describe Mixpanel::People do
|
|
44
46
|
|
45
47
|
it 'should convert offset datetimes to UTC' do
|
46
48
|
@people.set("TEST ID", {
|
47
|
-
'created_at' => DateTime.new(2013, 1, 1, 18, 4, 5, '-
|
49
|
+
'created_at' => DateTime.new(2013, 1, 1, 18, 4, 5, '-8')
|
48
50
|
})
|
49
51
|
expect(@log).to eq([[:profile_update, 'data' => {
|
50
52
|
'$token' => 'TEST TOKEN',
|
51
53
|
'$distinct_id' => 'TEST ID',
|
52
54
|
'$time' => @time_now.to_i * 1000,
|
53
55
|
'$set' => {
|
54
|
-
'created_at' => '2013-01-
|
56
|
+
'created_at' => '2013-01-02T02:04:05'
|
57
|
+
}
|
58
|
+
}]])
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should convert offset ActiveSupport::TimeWithZone objects to UTC' do
|
62
|
+
Time.zone = 'Pacific Time (US & Canada)'
|
63
|
+
@people.set("TEST ID", {
|
64
|
+
'created_at' => Time.zone.local(2013, 1, 1, 18, 4, 5)
|
65
|
+
})
|
66
|
+
expect(@log).to eq([[:profile_update, 'data' => {
|
67
|
+
'$token' => 'TEST TOKEN',
|
68
|
+
'$distinct_id' => 'TEST ID',
|
69
|
+
'$time' => @time_now.to_i * 1000,
|
70
|
+
'$set' => {
|
71
|
+
'created_at' => '2013-01-02T02:04:05'
|
55
72
|
}
|
56
73
|
}]])
|
57
74
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixpanel-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mixpanel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rake
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,12 +84,14 @@ files:
|
|
70
84
|
- demo/simple_messages.rb
|
71
85
|
- lib/mixpanel-ruby.rb
|
72
86
|
- lib/mixpanel-ruby/consumer.rb
|
87
|
+
- lib/mixpanel-ruby/error.rb
|
73
88
|
- lib/mixpanel-ruby/events.rb
|
74
89
|
- lib/mixpanel-ruby/people.rb
|
75
90
|
- lib/mixpanel-ruby/tracker.rb
|
76
91
|
- lib/mixpanel-ruby/version.rb
|
77
92
|
- mixpanel-ruby.gemspec
|
78
93
|
- spec/mixpanel-ruby/consumer_spec.rb
|
94
|
+
- spec/mixpanel-ruby/error_spec.rb
|
79
95
|
- spec/mixpanel-ruby/events_spec.rb
|
80
96
|
- spec/mixpanel-ruby/people_spec.rb
|
81
97
|
- spec/mixpanel-ruby/tracker_spec.rb
|