mixpanel-ruby 1.4.0 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@
2
2
  Gemfile.lock
3
3
  html
4
4
  mixpanel-ruby*.gem
5
+ .bundle
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - rbx-2
8
+
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: "rbx-2"
data/Readme.rdoc CHANGED
@@ -1,3 +1,5 @@
1
+ {<img src="https://travis-ci.org/mixpanel/mixpanel-ruby.svg?branch=master" alt="Build Status" />}[https://travis-ci.org/mixpanel/mixpanel-ruby]
2
+
1
3
  = mixpanel-ruby: The official Mixpanel Ruby library
2
4
 
3
5
  mixpanel-ruby is a library for tracking events and sending \Mixpanel profile
@@ -38,12 +40,15 @@ For more information please visit:
38
40
  The official Mixpanel gem is built with simplicity and broad applicability in
39
41
  mind, but there are also third party Ruby libraries that can work with the library
40
42
  to provide useful features in common situations. One in particular is
41
- MetaEvents[https://github.com/swiftype/meta_events], a third party gem
43
+ MetaEvents[https://github.com/swiftype/meta_events], a third party gem
42
44
  which provides support for client-side tracking in Rails applications,
43
45
  super-properties-like persistent properties, and a DSL for defining your events.
44
46
 
45
47
  == Changes
46
48
 
49
+ == 1.4.0
50
+ * Allow unset to unset multiple properties
51
+
47
52
  == 1.3.0
48
53
  * Added Consumer#request method, demo with Faraday integration
49
54
 
@@ -250,6 +250,7 @@ module Mixpanel
250
250
 
251
251
  def fix_property_dates(h)
252
252
  h.inject({}) do |ret,(k,v)|
253
+ v = v.respond_to?(:new_offset) ? v.new_offset('0') : v
253
254
  ret[k] = v.respond_to?(:strftime) ? v.strftime('%Y-%m-%dT%H:%M:%S') : v
254
255
  ret
255
256
  end
@@ -82,7 +82,7 @@ module Mixpanel
82
82
  # tracker = Mixpanel::Tracker.new
83
83
  #
84
84
  # # Import event that user "12345"'s credit card was declined
85
- # tracker.import("12345", "Credit Card Declined", {
85
+ # tracker.import("API_KEY", "12345", "Credit Card Declined", {
86
86
  # 'time' => 1310111365
87
87
  # })
88
88
  #
@@ -1,3 +1,3 @@
1
1
  module Mixpanel
2
- VERSION = '1.4.0'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -10,8 +10,9 @@ spec = Gem::Specification.new do |spec|
10
10
  spec.authors = [ 'Mixpanel' ]
11
11
  spec.email = 'support@mixpanel.com'
12
12
  spec.homepage = 'https://mixpanel.com/help/reference/ruby'
13
+ spec.license = 'Apache License 2.0'
13
14
 
14
- spec.add_development_dependency('rake')
15
- spec.add_development_dependency('rspec')
16
- spec.add_development_dependency('webmock')
15
+ spec.add_development_dependency 'rake'
16
+ spec.add_development_dependency 'rspec', '~> 3.0.0'
17
+ spec.add_development_dependency 'webmock', '~> 1.18.0'
17
18
  end
@@ -10,28 +10,28 @@ describe Mixpanel::Consumer do
10
10
  it 'should send a request to api.mixpanel.com/track on events' do
11
11
  stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
12
12
  subject.send(:event, {'data' => 'TEST EVENT MESSAGE'}.to_json)
13
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
13
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
14
14
  with(:body => {'data' => 'IlRFU1QgRVZFTlQgTUVTU0FHRSI=', 'verbose' => '1' })
15
15
  end
16
16
 
17
17
  it 'should send a request to api.mixpanel.com/people on profile updates' do
18
18
  stub_request(:any, 'https://api.mixpanel.com/engage').to_return({:body => '{"status": 1, "error": null}'})
19
19
  subject.send(:profile_update, {'data' => 'TEST EVENT MESSAGE'}.to_json)
20
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/engage').
20
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/engage').
21
21
  with(:body => {'data' => 'IlRFU1QgRVZFTlQgTUVTU0FHRSI=', 'verbose' => '1' })
22
22
  end
23
23
 
24
24
  it 'should send a request to api.mixpanel.com/import on event imports' do
25
25
  stub_request(:any, 'https://api.mixpanel.com/import').to_return({:body => '{"status": 1, "error": null}'})
26
26
  subject.send(:import, {'data' => 'TEST EVENT MESSAGE', 'api_key' => 'API_KEY','verbose' => '1' }.to_json)
27
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/import').
27
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/import').
28
28
  with(:body => {'data' => 'IlRFU1QgRVZFTlQgTUVTU0FHRSI=', 'api_key' => 'API_KEY', 'verbose' => '1' })
29
29
  end
30
30
 
31
31
  it 'should encode long messages without newlines' do
32
32
  stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
33
33
  subject.send(:event, {'data' => 'BASE64-ENCODED VERSION OF BIN. THIS METHOD COMPLIES WITH RFC 2045. LINE FEEDS ARE ADDED TO EVERY 60 ENCODED CHARACTORS. IN RUBY 1.8 WE NEED TO JUST CALL ENCODE64 AND REMOVE THE LINE FEEDS, IN RUBY 1.9 WE CALL STRIC_ENCODED64 METHOD INSTEAD'}.to_json)
34
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
34
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
35
35
  with(:body => {'data' => 'IkJBU0U2NC1FTkNPREVEIFZFUlNJT04gT0YgQklOLiBUSElTIE1FVEhPRCBDT01QTElFUyBXSVRIIFJGQyAyMDQ1LiBMSU5FIEZFRURTIEFSRSBBRERFRCBUTyBFVkVSWSA2MCBFTkNPREVEIENIQVJBQ1RPUlMuIElOIFJVQlkgMS44IFdFIE5FRUQgVE8gSlVTVCBDQUxMIEVOQ09ERTY0IEFORCBSRU1PVkUgVEhFIExJTkUgRkVFRFMsIElOIFJVQlkgMS45IFdFIENBTEwgU1RSSUNfRU5DT0RFRDY0IE1FVEhPRCBJTlNURUFEIg==', 'verbose' => '1'})
36
36
  end
37
37
 
@@ -60,7 +60,7 @@ describe Mixpanel::Consumer do
60
60
  end
61
61
 
62
62
  after(:each) do
63
- subject.called.should be_true
63
+ expect(subject.called).to be_truthy
64
64
  end
65
65
 
66
66
  it_behaves_like 'consumer'
@@ -78,10 +78,10 @@ describe Mixpanel::BufferedConsumer do
78
78
  it 'should not send a request for a single message until flush is called' do
79
79
  stub_request(:any, 'https://api.mixpanel.com/track').to_return({:body => '{"status": 1, "error": null}'})
80
80
  subject.send(:event, {'data' => 'TEST EVENT 1'}.to_json)
81
- WebMock.should have_not_requested(:post, 'https://api.mixpanel.com/track')
81
+ expect(WebMock).to have_not_requested(:post, 'https://api.mixpanel.com/track')
82
82
 
83
83
  subject.flush()
84
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
84
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
85
85
  with(:body => {'data' => 'WyJURVNUIEVWRU5UIDEiXQ==', 'verbose' => '1' })
86
86
  end
87
87
 
@@ -92,7 +92,7 @@ describe Mixpanel::BufferedConsumer do
92
92
  subject.send(:event, {'data' => "x #{i}"}.to_json)
93
93
  end
94
94
 
95
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
95
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
96
96
  with(:body => {'data' => 'WyJ4IDAiLCJ4IDEiLCJ4IDIiLCJ4IDMiLCJ4IDQiLCJ4IDUiLCJ4IDYiLCJ4IDciLCJ4IDgiLCJ4IDkiXQ==', 'verbose' => '1' })
97
97
  end
98
98
 
@@ -104,10 +104,10 @@ describe Mixpanel::BufferedConsumer do
104
104
  subject.send(:import, {'data' => 'TEST EVENT 2', 'api_key' => 'KEY 2'}.to_json)
105
105
  subject.flush
106
106
 
107
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/import').
107
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/import').
108
108
  with(:body => {'data' => 'IlRFU1QgRVZFTlQgMSI=', 'api_key' => 'KEY 1', 'verbose' => '1' })
109
109
 
110
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/import').
110
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/import').
111
111
  with(:body => {'data' => 'IlRFU1QgRVZFTlQgMSI=', 'api_key' => 'KEY 2', 'verbose' => '1' })
112
112
  end
113
113
  end
@@ -6,7 +6,7 @@ require 'time'
6
6
  describe Mixpanel::Events do
7
7
  before(:each) do
8
8
  @time_now = Time.parse('Jun 6 1972, 16:23:04')
9
- Time.stub(:now).and_return(@time_now)
9
+ allow(Time).to receive(:now).and_return(@time_now)
10
10
 
11
11
  @log = []
12
12
  @events = Mixpanel::Events.new('TEST TOKEN') do |type, message|
@@ -18,7 +18,7 @@ describe Mixpanel::Events do
18
18
  @events.track('TEST ID', 'Test Event', {
19
19
  'Circumstances' => 'During a test'
20
20
  })
21
- @log.should eq([[:event, 'data' => {
21
+ expect(@log).to eq([[:event, 'data' => {
22
22
  'event' => 'Test Event',
23
23
  'properties' => {
24
24
  'Circumstances' => 'During a test',
@@ -35,7 +35,7 @@ describe Mixpanel::Events do
35
35
  @events.import('API_KEY', 'TEST ID', 'Test Event', {
36
36
  'Circumstances' => 'During a test'
37
37
  })
38
- @log.should eq([[:import, {
38
+ expect(@log).to eq([[:import, {
39
39
  'api_key' => 'API_KEY',
40
40
  'data' => {
41
41
  'event' => 'Test Event',
@@ -4,7 +4,7 @@ require 'mixpanel-ruby/people'
4
4
  describe Mixpanel::People do
5
5
  before(:each) do
6
6
  @time_now = Time.parse('Jun 6 1972, 16:23:04')
7
- Time.stub(:now).and_return(@time_now)
7
+ allow(Time).to receive(:now).and_return(@time_now)
8
8
 
9
9
  @log = []
10
10
  @people = Mixpanel::People.new('TEST TOKEN') do |type, message|
@@ -17,7 +17,7 @@ describe Mixpanel::People do
17
17
  '$firstname' => 'David',
18
18
  '$lastname' => 'Bowie',
19
19
  })
20
- @log.should eq([[:profile_update, 'data' => {
20
+ expect(@log).to eq([[:profile_update, 'data' => {
21
21
  '$token' => 'TEST TOKEN',
22
22
  '$distinct_id' => 'TEST ID',
23
23
  '$time' => @time_now.to_i * 1000,
@@ -32,7 +32,21 @@ describe Mixpanel::People do
32
32
  @people.set("TEST ID", {
33
33
  'created_at' => DateTime.new(2013, 1, 2, 3, 4, 5)
34
34
  })
35
- @log.should eq([[:profile_update, 'data' => {
35
+ expect(@log).to eq([[:profile_update, 'data' => {
36
+ '$token' => 'TEST TOKEN',
37
+ '$distinct_id' => 'TEST ID',
38
+ '$time' => @time_now.to_i * 1000,
39
+ '$set' => {
40
+ 'created_at' => '2013-01-02T03:04:05'
41
+ }
42
+ }]])
43
+ end
44
+
45
+ it 'should convert offset datetimes to UTC' do
46
+ @people.set("TEST ID", {
47
+ 'created_at' => DateTime.new(2013, 1, 1, 18, 4, 5, '-9')
48
+ })
49
+ expect(@log).to eq([[:profile_update, 'data' => {
36
50
  '$token' => 'TEST TOKEN',
37
51
  '$distinct_id' => 'TEST ID',
38
52
  '$time' => @time_now.to_i * 1000,
@@ -47,7 +61,7 @@ describe Mixpanel::People do
47
61
  '$firstname' => 'David',
48
62
  '$lastname' => 'Bowie',
49
63
  })
50
- @log.should eq([[:profile_update, 'data' => {
64
+ expect(@log).to eq([[:profile_update, 'data' => {
51
65
  '$token' => 'TEST TOKEN',
52
66
  '$distinct_id' => 'TEST ID',
53
67
  '$time' => @time_now.to_i * 1000,
@@ -60,7 +74,7 @@ describe Mixpanel::People do
60
74
 
61
75
  it 'should send a well formed engage/add message' do
62
76
  @people.increment("TEST ID", {'Albums Released' => 10})
63
- @log.should eq([[:profile_update, 'data' => {
77
+ expect(@log).to eq([[:profile_update, 'data' => {
64
78
  '$token' => 'TEST TOKEN',
65
79
  '$distinct_id' => 'TEST ID',
66
80
  '$time' => @time_now.to_i * 1000,
@@ -72,7 +86,7 @@ describe Mixpanel::People do
72
86
 
73
87
  it 'should send an engage/add message with a value of 1' do
74
88
  @people.plus_one("TEST ID", 'Albums Released')
75
- @log.should eq([[:profile_update, 'data' => {
89
+ expect(@log).to eq([[:profile_update, 'data' => {
76
90
  '$token' => 'TEST TOKEN',
77
91
  '$distinct_id' => 'TEST ID',
78
92
  '$time' => @time_now.to_i * 1000,
@@ -84,7 +98,7 @@ describe Mixpanel::People do
84
98
 
85
99
  it 'should send a well formed engage/append message' do
86
100
  @people.append("TEST ID", {'Albums' => 'Diamond Dogs'})
87
- @log.should eq([[:profile_update, 'data' => {
101
+ expect(@log).to eq([[:profile_update, 'data' => {
88
102
  '$token' => 'TEST TOKEN',
89
103
  '$distinct_id' => 'TEST ID',
90
104
  '$time' => @time_now.to_i * 1000,
@@ -96,7 +110,7 @@ describe Mixpanel::People do
96
110
 
97
111
  it 'should send a well formed engage/union message' do
98
112
  @people.union("TEST ID", {'Albums' => ['Diamond Dogs']})
99
- @log.should eq([[:profile_update, 'data' => {
113
+ expect(@log).to eq([[:profile_update, 'data' => {
100
114
  '$token' => 'TEST TOKEN',
101
115
  '$distinct_id' => 'TEST ID',
102
116
  '$time' => @time_now.to_i * 1000,
@@ -108,7 +122,7 @@ describe Mixpanel::People do
108
122
 
109
123
  it 'should send a well formed unset message' do
110
124
  @people.unset('TEST ID', 'Albums')
111
- @log.should eq([[:profile_update, 'data' => {
125
+ expect(@log).to eq([[:profile_update, 'data' => {
112
126
  '$token' => 'TEST TOKEN',
113
127
  '$distinct_id' => 'TEST ID',
114
128
  '$time' => @time_now.to_i * 1000,
@@ -118,7 +132,7 @@ describe Mixpanel::People do
118
132
 
119
133
  it 'should send a well formed unset message with multiple properties' do
120
134
  @people.unset('TEST ID', ['Albums', 'Vinyls'])
121
- @log.should eq([[:profile_update, 'data' => {
135
+ expect(@log).to eq([[:profile_update, 'data' => {
122
136
  '$token' => 'TEST TOKEN',
123
137
  '$distinct_id' => 'TEST ID',
124
138
  '$time' => @time_now.to_i * 1000,
@@ -131,7 +145,7 @@ describe Mixpanel::People do
131
145
  '$time' => DateTime.new(1999,12,24,14, 02, 53),
132
146
  'SKU' => '1234567'
133
147
  })
134
- @log.should eq([[:profile_update, 'data' => {
148
+ expect(@log).to eq([[:profile_update, 'data' => {
135
149
  '$token' => 'TEST TOKEN',
136
150
  '$distinct_id' => 'TEST ID',
137
151
  '$time' => @time_now.to_i * 1000,
@@ -147,7 +161,7 @@ describe Mixpanel::People do
147
161
 
148
162
  it 'should send a well formed engage/unset message for $transaction' do
149
163
  @people.clear_charges("TEST ID")
150
- @log.should eq([[:profile_update, 'data' => {
164
+ expect(@log).to eq([[:profile_update, 'data' => {
151
165
  '$token' => 'TEST TOKEN',
152
166
  '$distinct_id' => 'TEST ID',
153
167
  '$time' => @time_now.to_i * 1000,
@@ -157,7 +171,7 @@ describe Mixpanel::People do
157
171
 
158
172
  it 'should send a well formed engage/delete message' do
159
173
  @people.delete_user("TEST ID")
160
- @log.should eq([[:profile_update, 'data' => {
174
+ expect(@log).to eq([[:profile_update, 'data' => {
161
175
  '$token' => 'TEST TOKEN',
162
176
  '$distinct_id' => 'TEST ID',
163
177
  '$time' => @time_now.to_i * 1000,
@@ -6,7 +6,7 @@ require 'uri'
6
6
  describe Mixpanel::Tracker do
7
7
  before(:each) do
8
8
  @time_now = Time.parse('Jun 6 1972, 16:23:04')
9
- Time.stub(:now).and_return(@time_now)
9
+ allow(Time).to receive(:now).and_return(@time_now)
10
10
  end
11
11
 
12
12
  it 'should send an alias message to mixpanel no matter what the consumer is' do
@@ -15,7 +15,7 @@ describe Mixpanel::Tracker do
15
15
  mixpanel = Mixpanel::Tracker.new('TEST TOKEN') {|*args| }
16
16
  mixpanel.alias('TEST ALIAS', 'TEST ID')
17
17
 
18
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
18
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
19
19
  with(:body => {:data => 'eyJldmVudCI6IiRjcmVhdGVfYWxpYXMiLCJwcm9wZXJ0aWVzIjp7ImRpc3RpbmN0X2lkIjoiVEVTVCBJRCIsImFsaWFzIjoiVEVTVCBBTElBUyIsInRva2VuIjoiVEVTVCBUT0tFTiJ9fQ==', 'verbose' => '1'})
20
20
  end
21
21
 
@@ -28,13 +28,13 @@ describe Mixpanel::Tracker do
28
28
  mixpanel.track('TEST ID', 'TEST EVENT', {'Circumstances' => 'During test'})
29
29
 
30
30
  body = nil
31
- WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
31
+ expect(WebMock).to have_requested(:post, 'https://api.mixpanel.com/track').
32
32
  with { |req| body = req.body }
33
33
 
34
34
  message_urlencoded = body[/^data=(.*?)(?:&|$)/, 1]
35
35
  message_json = Base64.strict_decode64(URI.unescape(message_urlencoded))
36
36
  message = JSON.load(message_json)
37
- message.should eq({
37
+ expect(message).to eq({
38
38
  'event' => 'TEST EVENT',
39
39
  'properties' => {
40
40
  'Circumstances' => 'During test',
@@ -99,7 +99,7 @@ describe Mixpanel::Tracker do
99
99
  ]
100
100
  ]
101
101
  expect.zip(messages).each do |expect, found|
102
- expect.should eq(found)
102
+ expect(expect).to eq(found)
103
103
  end
104
104
  end
105
105
  end
data/spec/spec_helper.rb CHANGED
@@ -3,9 +3,9 @@ require 'webmock/rspec'
3
3
 
4
4
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
5
5
  RSpec.configure do |config|
6
- config.treat_symbols_as_metadata_keys_with_true_values = true
7
6
  config.run_all_when_everything_filtered = true
8
7
  config.filter_run :focus
8
+ config.raise_errors_for_deprecations!
9
9
 
10
10
  # Run specs in random order to surface order dependencies. If you find an
11
11
  # order dependency and want to debug it, you can fix the order by providing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpanel-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-17 00:00:00.000000000 Z
12
+ date: 2014-08-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -32,33 +32,33 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 3.0.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 3.0.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: webmock
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ! '>='
51
+ - - ~>
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
53
+ version: 1.18.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ! '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.18.0
62
62
  description: The official Mixpanel tracking library for ruby
63
63
  email: support@mixpanel.com
64
64
  executables: []
@@ -67,6 +67,7 @@ extra_rdoc_files: []
67
67
  files:
68
68
  - .gitignore
69
69
  - .rspec
70
+ - .travis.yml
70
71
  - Gemfile
71
72
  - LICENSE
72
73
  - Rakefile
@@ -87,7 +88,8 @@ files:
87
88
  - spec/mixpanel-ruby/tracker_spec.rb
88
89
  - spec/spec_helper.rb
89
90
  homepage: https://mixpanel.com/help/reference/ruby
90
- licenses: []
91
+ licenses:
92
+ - Apache License 2.0
91
93
  post_install_message:
92
94
  rdoc_options: []
93
95
  require_paths: