mixpanel_client 3.1.2 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +16 -1
- data/lib/mixpanel/client.rb +11 -4
- data/lib/mixpanel/version.rb +1 -1
- data/mixpanel_client.gemspec +1 -0
- data/spec/mixpanel_client/mixpanel_client_spec.rb +38 -0
- data/spec/mixpanel_client/uri_spec.rb +4 -0
- metadata +16 -15
data/README.md
CHANGED
@@ -32,6 +32,16 @@ or if you use a Gemfile
|
|
32
32
|
|
33
33
|
puts data.inspect
|
34
34
|
|
35
|
+
|
36
|
+
# use the import API, which allows one to specify a time in the past, unlike the track API.
|
37
|
+
# note that you need to include your api token in the data. More details at:
|
38
|
+
# https://mixpanel.com/docs/api-documentation/importing-events-older-than-31-days
|
39
|
+
data_to_import = {'event' => 'firstLogin', 'properties' => {'distinct_id' => guid, 'time' => time_as_integer_seconds_since_epoch, 'token' => api_token}}
|
40
|
+
require 'base64' # co-located with the Base64 call below for clarity
|
41
|
+
encoded_data = Base64.encode64(data_to_import.to_json)
|
42
|
+
data = client.request('import', {:data => encoded_data, :api_key => api_key})
|
43
|
+
# data == [1] # => true # you can only import one event at a time
|
44
|
+
|
35
45
|
## Parallel
|
36
46
|
|
37
47
|
require 'rubygems'
|
@@ -94,6 +104,10 @@ Create tag v2.0.2 and build and push mixpanel_client-2.0.2.gem to Rubygems
|
|
94
104
|
|
95
105
|
## Changelog
|
96
106
|
|
107
|
+
### v3.1.3
|
108
|
+
* Added support for the import API.
|
109
|
+
* Allow setting of custom expiry.
|
110
|
+
|
97
111
|
### v3.1.2
|
98
112
|
* Gem updates
|
99
113
|
|
@@ -164,7 +178,8 @@ Feel free to add your name and link here.
|
|
164
178
|
[Grzegorz Forysinski](http://github.com/railwaymen)
|
165
179
|
[Nathan Chong](http://github.com/paramaw)
|
166
180
|
[Paul McMahon](http://github.com/pwim)
|
167
|
-
[Chad Etzel](http://github.com/jazzychad)
|
181
|
+
[Chad Etzel](http://github.com/jazzychad)
|
182
|
+
[Kevin Burnett](http://github.com/burnettk)
|
168
183
|
|
169
184
|
## Copyright
|
170
185
|
|
data/lib/mixpanel/client.rb
CHANGED
@@ -11,6 +11,7 @@ module Mixpanel
|
|
11
11
|
class Client
|
12
12
|
BASE_URI = 'https://mixpanel.com/api/2.0'
|
13
13
|
DATA_URI = 'https://data.mixpanel.com/api/2.0'
|
14
|
+
IMPORT_URI = 'https://api.mixpanel.com'
|
14
15
|
|
15
16
|
attr_reader :uri
|
16
17
|
attr_accessor :api_key, :api_secret, :parallel
|
@@ -53,7 +54,7 @@ module Mixpanel
|
|
53
54
|
parallel_request
|
54
55
|
else
|
55
56
|
response = URI.get(@uri)
|
56
|
-
response = %Q|[#{response.split("\n").join(',')}]| if resource
|
57
|
+
response = %Q|[#{response.split("\n").join(',')}]| if %w(export import).include?(resource)
|
57
58
|
Utils.to_hash(response, @format)
|
58
59
|
end
|
59
60
|
end
|
@@ -103,7 +104,7 @@ module Mixpanel
|
|
103
104
|
end
|
104
105
|
|
105
106
|
def hydra
|
106
|
-
@hydra ||= ::Typhoeus::Hydra.new
|
107
|
+
@hydra ||= ::Typhoeus::Hydra.new
|
107
108
|
end
|
108
109
|
|
109
110
|
private
|
@@ -116,12 +117,18 @@ module Mixpanel
|
|
116
117
|
normalized_options.merge!(
|
117
118
|
:format => @format,
|
118
119
|
:api_key => @api_key,
|
119
|
-
:expire => Time.now.to_i + 600
|
120
|
+
:expire => options[:expire] ? options[:expire].to_i : Time.now.to_i + 600
|
120
121
|
).merge!(:sig => Utils.generate_signature(normalized_options, @api_secret))
|
121
122
|
end
|
122
123
|
|
123
124
|
def self.base_uri_for_resource(resource)
|
124
|
-
resource == 'export'
|
125
|
+
if resource == 'export'
|
126
|
+
DATA_URI
|
127
|
+
elsif resource == 'import'
|
128
|
+
IMPORT_URI
|
129
|
+
else
|
130
|
+
BASE_URI
|
131
|
+
end
|
125
132
|
end
|
126
133
|
end
|
127
134
|
end
|
data/lib/mixpanel/version.rb
CHANGED
data/mixpanel_client.gemspec
CHANGED
@@ -48,6 +48,18 @@ describe Mixpanel::Client do
|
|
48
48
|
data.should == {"data"=>{"series"=>[], "values"=>{}}, "legend_size"=>0}
|
49
49
|
end
|
50
50
|
|
51
|
+
it 'should work when it receives an integer response on import' do
|
52
|
+
@import_uri = Regexp.escape(Mixpanel::Client::IMPORT_URI)
|
53
|
+
# Stub Mixpanel import request to return a realistic response
|
54
|
+
stub_request(:get, /^#{@import_uri}.*/).to_return(:body => '1')
|
55
|
+
|
56
|
+
data = @client.request('import', {
|
57
|
+
:data => 'base64_encoded_data',
|
58
|
+
:api_key => 'test_key'
|
59
|
+
})
|
60
|
+
data.should == [1]
|
61
|
+
end
|
62
|
+
|
51
63
|
it 'should work with an endpoint, method, and type' do
|
52
64
|
# Stub Mixpanel request
|
53
65
|
stub_request(:get, /^#{@uri}.*/).to_return(:body => '{"events": [], "type": "general"}')
|
@@ -68,6 +80,32 @@ describe Mixpanel::Client do
|
|
68
80
|
}.to_not change { options }
|
69
81
|
end
|
70
82
|
|
83
|
+
context 'with a custom expiry time' do
|
84
|
+
# Stub Mixpanel request
|
85
|
+
before { stub_request(:get, /^#{@uri}.*/).to_return(:body => '{"events": [], "type": "general"}') }
|
86
|
+
let(:expiry) { Time.now + 100000 }
|
87
|
+
let(:fake_url) { Mixpanel::Client::BASE_URI }
|
88
|
+
|
89
|
+
specify 'Client#request should return a hash with empty events and type' do
|
90
|
+
# With endpoint
|
91
|
+
data = @client.request('events/top', {
|
92
|
+
:type => 'general',
|
93
|
+
:expire => expiry
|
94
|
+
})
|
95
|
+
data.should == {"events"=>[], "type"=>"general"}
|
96
|
+
end
|
97
|
+
|
98
|
+
specify 'Mixpanel::URI instance should receive the custom expiry time in the options[:expiry] instead of 600s' do
|
99
|
+
Mixpanel::URI.should_receive(:mixpanel).with do |*args|
|
100
|
+
args.pop[:expire].should == expiry.to_i
|
101
|
+
true
|
102
|
+
end.and_return(fake_url)
|
103
|
+
@client.request('events/top', {
|
104
|
+
:type => 'general',
|
105
|
+
:expire => expiry
|
106
|
+
})
|
107
|
+
end
|
108
|
+
end
|
71
109
|
|
72
110
|
context "with parallel option enabled" do
|
73
111
|
before :all do
|
@@ -15,6 +15,10 @@ describe Mixpanel::URI do
|
|
15
15
|
resource, params = ['export', {:c => 'see', :a => 'ey'}]
|
16
16
|
Mixpanel::URI.mixpanel(resource, params).should == "#{Mixpanel::Client::DATA_URI}/export?a=ey&c=see"
|
17
17
|
end
|
18
|
+
it 'should return a uri with a the correct endpoint when doing an import' do
|
19
|
+
resource, params = ['import', {:c => 'see', :a => 'ey'}]
|
20
|
+
Mixpanel::URI.mixpanel(resource, params).should == "#{Mixpanel::Client::IMPORT_URI}/import?a=ey&c=see"
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
describe '.encode' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixpanel_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
16
|
-
requirement: &
|
16
|
+
requirement: &70291980662280 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.5.4
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70291980662280
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70291980661760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.2'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70291980661760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &70291980661280 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 0.9.2.2
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70291980661280
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &70291980660640 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '3.11'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70291980660640
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rspec
|
60
|
-
requirement: &
|
60
|
+
requirement: &70291980659940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 2.5.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70291980659940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
|
-
requirement: &
|
71
|
+
requirement: &70291980659300 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: 1.9.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70291980659300
|
80
80
|
description: Simple ruby client interface to the Mixpanel API.
|
81
81
|
email:
|
82
82
|
- keolo@dreampointmedia.com
|
@@ -107,7 +107,8 @@ files:
|
|
107
107
|
- spec/mixpanel_client/uri_spec.rb
|
108
108
|
- spec/spec_helper.rb
|
109
109
|
homepage: http://github.com/keolo/mixpanel_client
|
110
|
-
licenses:
|
110
|
+
licenses:
|
111
|
+
- MIT
|
111
112
|
post_install_message:
|
112
113
|
rdoc_options: []
|
113
114
|
require_paths:
|