mixpanel-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -51,7 +51,9 @@ module Mixpanel
51
51
  properties = {
52
52
  'distinct_id' => distinct_id,
53
53
  'token' => @token,
54
- 'time' => Time.now.to_i
54
+ 'time' => Time.now.to_i,
55
+ 'mp_lib' => 'ruby',
56
+ '$lib_version' => Mixpanel::VERSION
55
57
  }.merge(properties)
56
58
  if ip
57
59
  properties['ip'] = ip
@@ -41,10 +41,10 @@ module Mixpanel
41
41
  # and Mixpanel::BufferedConsumer#send
42
42
  def initialize(token, &block)
43
43
  super(token, &block)
44
+ @token = token
44
45
  @people = People.new(token, &block)
45
46
  end
46
47
 
47
-
48
48
  # Creates a distinct_id alias. \Events and updates with an alias
49
49
  # will be considered by mixpanel to have the same source, and
50
50
  # refer to the same profile.
@@ -52,10 +52,19 @@ module Mixpanel
52
52
  # Multiple aliases can map to the same real_id, once a real_id is
53
53
  # used to track events or send updates, it should never be used as
54
54
  # an alias itself.
55
- def alias(alias_id, real_id)
56
- track(real_id, '$create_alias', {
57
- 'alias' => alias_id
58
- })
55
+ #
56
+ # Alias requests are always sent synchronously, directly to
57
+ # the \Mixpanel service, regardless of how the tracker is configured.
58
+ def alias(alias_id, real_id, events_endpoint=nil)
59
+ consumer = Mixpanel::Consumer.new(events_endpoint)
60
+ message = {
61
+ 'event' => '$create_alias',
62
+ 'properties' => {
63
+ 'distinct_id' => real_id,
64
+ 'token' => @token,
65
+ }
66
+ }.to_json
67
+ consumer.send(:event, message)
59
68
  end
60
69
  end
61
70
  end
@@ -1,3 +1,3 @@
1
1
  module Mixpanel
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -9,21 +9,14 @@ describe Mixpanel::Tracker do
9
9
  Time.stub!(:now).and_return(@time_now)
10
10
  end
11
11
 
12
- it 'should send a well formed alias message' do
13
- log = []
14
- mixpanel = Mixpanel::Tracker.new('TEST TOKEN') do |type, message|
15
- log << [ type, JSON.load(message) ]
16
- end
12
+ it 'should send an alias message to mixpanel no matter what the consumer is' do
13
+ WebMock.reset!
14
+ stub_request(:any, 'https://api.mixpanel.com/track').to_return({ :body => "1" })
15
+ mixpanel = Mixpanel::Tracker.new('TEST TOKEN') {|*args| }
17
16
  mixpanel.alias('TEST ALIAS', 'TEST ID')
18
- log.should eq([[ :event, {
19
- 'event' => '$create_alias',
20
- 'properties' => {
21
- 'alias' => 'TEST ALIAS',
22
- 'distinct_id' => 'TEST ID',
23
- 'token' => 'TEST TOKEN',
24
- 'time' => 76695784
25
- }
26
- }]])
17
+
18
+ WebMock.should have_requested(:post, 'https://api.mixpanel.com/track').
19
+ with(:body => { :data => 'eyJldmVudCI6IiRjcmVhdGVfYWxpYXMiLCJwcm9wZXJ0aWVzIjp7ImRpc3RpbmN0X2lkIjoiVEVTVCBJRCIsInRva2VuIjoiVEVTVCBUT0tFTiJ9fQ==' })
27
20
  end
28
21
 
29
22
  it 'should send a request to the track api with the default consumer' do
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: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: