mixpanel_client 4.0.0 → 4.0.1
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/changelog.md +3 -2
- data/lib/mixpanel/client.rb +16 -12
- data/lib/mixpanel/exceptions.rb +1 -0
- data/lib/mixpanel/version.rb +1 -1
- data/license +1 -1
- data/manual_test/parallel.rb +10 -8
- data/mixpanel_client.gemspec +0 -1
- data/readme.md +43 -40
- data/spec/mixpanel_client/mixpanel_client_spec.rb +42 -14
- metadata +2 -3
- data/rubocop-todo.yml +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5db50334f0523f186df3366c7e79565ea7eca601
|
4
|
+
data.tar.gz: e28c9cf521c8d160a6d3b6ef1086bf7de6efb4a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b07b4bdc7b798cc10fda6e61502ed858a0530b24b9404a9ac5fc266c130c0e3829c0c19de28b694f8de2f8eab174bac186a80d97a28e5e0d3d8243272869d39
|
7
|
+
data.tar.gz: 28924015e8b5fc7f5b1404821e54ba9c474ce94edc84c8b12d18bfb628931c1ff1a768b36f43c4775abcec021c8fdc12024e5bec8b61d7507f8d10df0d8d3f92
|
data/.rubocop.yml
CHANGED
data/changelog.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
### v4.0.1
|
2
|
+
* Raise ConfigurationError if api_key or api_secret are not present
|
3
|
+
|
1
4
|
### v4.0.0
|
2
5
|
* Dropped support for Ruby 1.8.x
|
3
6
|
* Code cleanup via rubocop
|
@@ -66,5 +69,3 @@
|
|
66
69
|
### v1.0.0
|
67
70
|
* Changed "Mixpanel" class name to "MixpanelClient" to prevent naming collision in other
|
68
71
|
libraries. [a710a84e8ba4b6f018b7](https://github.com/keolo/mixpanel_client/commit/a710a84e8ba4b6f018b7404ab9fabc8f08b4a4f3)
|
69
|
-
|
70
|
-
|
data/lib/mixpanel/client.rb
CHANGED
@@ -19,29 +19,32 @@ module Mixpanel
|
|
19
19
|
# Configure the client
|
20
20
|
#
|
21
21
|
# @example
|
22
|
-
# config = {
|
22
|
+
# config = {api_key: '123', api_secret: '456'}
|
23
23
|
# client = Mixpanel::Client.new(config)
|
24
24
|
#
|
25
25
|
# @param [Hash] config consisting of an 'api_key' and an 'api_secret'
|
26
26
|
def initialize(config)
|
27
|
-
@api_key = config[:api_key]
|
28
|
-
@api_secret = config[:api_secret]
|
29
|
-
@parallel
|
27
|
+
@api_key = config[:api_key] || config['api_key']
|
28
|
+
@api_secret = config[:api_secret] || config['api_secret']
|
29
|
+
@parallel = config[:parallel] || config['parallel'] || false
|
30
|
+
|
31
|
+
fail ConfigurationError if @api_key.nil? || @api_secret.nil?
|
30
32
|
end
|
31
33
|
|
32
34
|
# Return mixpanel data as a JSON object or CSV string
|
33
35
|
#
|
34
36
|
# @example
|
35
|
-
# data = client.request(
|
37
|
+
# data = client.request(
|
38
|
+
# 'events/properties',
|
36
39
|
# event: '["test-event"]',
|
37
40
|
# name: 'hello',
|
38
41
|
# values: '["uno", "dos"]',
|
39
42
|
# type: 'general',
|
40
43
|
# unit: 'hour',
|
41
|
-
# interval:
|
42
|
-
# limit:
|
44
|
+
# interval: 24,
|
45
|
+
# limit: 5,
|
43
46
|
# bucket: 'contents'
|
44
|
-
#
|
47
|
+
# )
|
45
48
|
#
|
46
49
|
# @resource [String] mixpanel api resource endpoint
|
47
50
|
# @options [Hash] options variables used to make a specific request for
|
@@ -71,16 +74,17 @@ module Mixpanel
|
|
71
74
|
# Return mixpanel URI to the data
|
72
75
|
#
|
73
76
|
# @example
|
74
|
-
# uri = client.request_uri(
|
77
|
+
# uri = client.request_uri(
|
78
|
+
# 'events/properties',
|
75
79
|
# event: '["test-event"]',
|
76
80
|
# name: 'hello',
|
77
81
|
# values: '["uno", "dos"]',
|
78
82
|
# type: 'general',
|
79
83
|
# unit: 'hour',
|
80
|
-
# interval:
|
81
|
-
# limit:
|
84
|
+
# interval: 24,
|
85
|
+
# limit: 5,
|
82
86
|
# bucket: 'contents'
|
83
|
-
#
|
87
|
+
# )
|
84
88
|
#
|
85
89
|
# @resource [String] mixpanel api resource endpoint
|
86
90
|
# @options [Hash] options variables used to make a specific request for
|
data/lib/mixpanel/exceptions.rb
CHANGED
data/lib/mixpanel/version.rb
CHANGED
data/license
CHANGED
data/manual_test/parallel.rb
CHANGED
@@ -13,20 +13,22 @@ config = YAML.load_file(File.join(
|
|
13
13
|
))['mixpanel']
|
14
14
|
|
15
15
|
client = Mixpanel::Client.new(
|
16
|
-
api_key:
|
16
|
+
api_key: config[:api_key],
|
17
17
|
api_secret: config[:api_secret],
|
18
|
-
parallel:
|
18
|
+
parallel: true
|
19
19
|
)
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
uno = client.request(
|
22
|
+
'events/top',
|
23
|
+
type: 'general'
|
23
24
|
)
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
dos = client.request(
|
27
|
+
'events/names',
|
28
|
+
type: 'general'
|
27
29
|
)
|
28
30
|
|
29
31
|
client.run_parallel_requests
|
30
32
|
|
31
|
-
puts
|
32
|
-
puts
|
33
|
+
puts uno.response.handled_response.inspect
|
34
|
+
puts dos.response.handled_response.inspect
|
data/mixpanel_client.gemspec
CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
20
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
21
|
s.require_paths = ['lib']
|
22
|
-
s.add_runtime_dependency('json', '~> 1.6') if RUBY_VERSION < '1.9'
|
23
22
|
s.add_runtime_dependency('typhoeus', '~> 0.6.7')
|
24
23
|
s.add_development_dependency('bundler', '>=1.5.3')
|
25
24
|
s.add_development_dependency('rake', '>=10.1.1')
|
data/readme.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
# Mixpanel API Client
|
1
|
+
# Mixpanel Data API Client
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/mixpanel_client)
|
2
4
|
|
3
5
|
Ruby access to the [Mixpanel](http://mixpanel.com/) web analytics tool.
|
4
6
|
|
@@ -17,10 +19,13 @@ or if you use a Gemfile
|
|
17
19
|
require 'rubygems'
|
18
20
|
require 'mixpanel_client'
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
client = Mixpanel::Client.new(
|
23
|
+
api_key: 'changeme',
|
24
|
+
api_secret: 'changeme'
|
25
|
+
)
|
22
26
|
|
23
|
-
data = client.request(
|
27
|
+
data = client.request(
|
28
|
+
'events/properties',
|
24
29
|
event: 'splash features',
|
25
30
|
name: 'feature',
|
26
31
|
values: '["uno", "dos"]',
|
@@ -28,21 +33,22 @@ or if you use a Gemfile
|
|
28
33
|
unit: 'day',
|
29
34
|
from_date: '2013-12-1',
|
30
35
|
to_date: '2014-3-1',
|
31
|
-
limit:
|
32
|
-
|
36
|
+
limit: 5
|
37
|
+
)
|
33
38
|
|
34
39
|
puts data.inspect
|
35
40
|
|
36
41
|
# The API also supports passing a time interval rather than an explicit date range
|
37
|
-
data = client.request(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
data = client.request(
|
43
|
+
'events/properties',
|
44
|
+
event: 'splash features',
|
45
|
+
name: 'feature',
|
46
|
+
values: '["uno", "dos"]',
|
47
|
+
type: 'unique',
|
48
|
+
unit: 'day',
|
49
|
+
interval: 7,
|
50
|
+
limit: 5
|
51
|
+
)
|
46
52
|
|
47
53
|
|
48
54
|
# use the import API, which allows one to specify a time in the past, unlike the track API.
|
@@ -56,23 +62,31 @@ or if you use a Gemfile
|
|
56
62
|
|
57
63
|
## Parallel
|
58
64
|
|
65
|
+
You may also make requests in parallel by passing in the `parallel: true` option.
|
66
|
+
|
59
67
|
require 'rubygems'
|
60
68
|
require 'mixpanel_client'
|
61
69
|
|
62
|
-
|
63
|
-
|
70
|
+
client = Mixpanel::Client.new(
|
71
|
+
api_key: 'changeme',
|
72
|
+
api_secret: 'changeme',
|
73
|
+
parallel: true
|
74
|
+
)
|
64
75
|
|
65
|
-
first_request = client.request(
|
66
|
-
|
67
|
-
|
76
|
+
first_request = client.request(
|
77
|
+
'events/properties',
|
78
|
+
...
|
79
|
+
)
|
68
80
|
|
69
|
-
second_request = client.request(
|
70
|
-
|
71
|
-
|
81
|
+
second_request = client.request(
|
82
|
+
'events/properties',
|
83
|
+
...
|
84
|
+
)
|
72
85
|
|
73
|
-
third_request = client.request(
|
74
|
-
|
75
|
-
|
86
|
+
third_request = client.request(
|
87
|
+
'events/properties',
|
88
|
+
...
|
89
|
+
)
|
76
90
|
|
77
91
|
...
|
78
92
|
|
@@ -98,20 +112,9 @@ Run external specs.
|
|
98
112
|
vi config/mixpanel.yml
|
99
113
|
rake spec:externals
|
100
114
|
|
101
|
-
|
102
|
-
Update version
|
103
|
-
|
104
|
-
vi lib/mixpanel/version.rb
|
105
|
-
|
106
|
-
Commit and push local changes
|
107
|
-
|
108
|
-
git commit -am "Some message."
|
109
|
-
git push
|
110
|
-
git status
|
115
|
+
Run rubocop and fix offences.
|
111
116
|
|
112
|
-
|
113
|
-
|
114
|
-
rake release
|
117
|
+
rubocop
|
115
118
|
|
116
119
|
|
117
120
|
## Changelog
|
@@ -136,4 +139,4 @@ Feel free to add your name and link here.
|
|
136
139
|
|
137
140
|
## Copyright
|
138
141
|
|
139
|
-
Copyright (c) 2009+ Keolo Keagy. See
|
142
|
+
Copyright (c) 2009+ Keolo Keagy. See [license](license) for details.
|
@@ -35,6 +35,24 @@ describe Mixpanel::Client do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'when making an invalid request' do
|
38
|
+
it 'should raise an error when API key is null' do
|
39
|
+
expect do
|
40
|
+
Mixpanel::Client.new(
|
41
|
+
api_key: nil,
|
42
|
+
api_secret: 'test_secret'
|
43
|
+
)
|
44
|
+
end.to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should raise an error when API secret is null' do
|
48
|
+
expect do
|
49
|
+
Mixpanel::Client.new(
|
50
|
+
api_key: 'test_key',
|
51
|
+
api_secret: nil
|
52
|
+
)
|
53
|
+
end.to raise_error
|
54
|
+
end
|
55
|
+
|
38
56
|
it 'should return an argument error "Wrong number of arguments" if using
|
39
57
|
the deprecated usage' do
|
40
58
|
# Stub Mixpanel request
|
@@ -43,12 +61,16 @@ describe Mixpanel::Client do
|
|
43
61
|
body: '{"legend_size": 0, "data": {"series": [], "values": {}}}'
|
44
62
|
)
|
45
63
|
|
46
|
-
data = lambda do
|
47
|
-
|
48
|
-
|
49
|
-
|
64
|
+
data = lambda do
|
65
|
+
@client.request(
|
66
|
+
nil,
|
67
|
+
:events,
|
68
|
+
event: '["test-event"]',
|
69
|
+
unit: 'hour',
|
70
|
+
interval: 24
|
50
71
|
)
|
51
72
|
end
|
73
|
+
|
52
74
|
data.should raise_error(ArgumentError)
|
53
75
|
end
|
54
76
|
end
|
@@ -62,11 +84,13 @@ describe Mixpanel::Client do
|
|
62
84
|
)
|
63
85
|
|
64
86
|
# No endpoint
|
65
|
-
data = @client.request(
|
66
|
-
|
67
|
-
|
68
|
-
|
87
|
+
data = @client.request(
|
88
|
+
'events',
|
89
|
+
event: '["test-event"]',
|
90
|
+
unit: 'hour',
|
91
|
+
interval: 24
|
69
92
|
)
|
93
|
+
|
70
94
|
data.should eq(
|
71
95
|
'data' => {
|
72
96
|
'series' => [],
|
@@ -81,10 +105,12 @@ describe Mixpanel::Client do
|
|
81
105
|
# Stub Mixpanel import request to return a realistic response
|
82
106
|
stub_request(:get, /^#{@import_uri}.*/).to_return(body: '1')
|
83
107
|
|
84
|
-
data = @client.request(
|
85
|
-
|
86
|
-
|
108
|
+
data = @client.request(
|
109
|
+
'import',
|
110
|
+
data: 'base64_encoded_data',
|
111
|
+
api_key: 'test_key'
|
87
112
|
)
|
113
|
+
|
88
114
|
data.should == [1]
|
89
115
|
end
|
90
116
|
|
@@ -153,9 +179,11 @@ describe Mixpanel::Client do
|
|
153
179
|
args.pop[:expire].should eq expiry.to_i
|
154
180
|
true
|
155
181
|
end.and_return(fake_url)
|
156
|
-
|
157
|
-
|
158
|
-
|
182
|
+
|
183
|
+
@client.request(
|
184
|
+
'events/top',
|
185
|
+
type: 'general',
|
186
|
+
expire: expiry
|
159
187
|
)
|
160
188
|
end
|
161
189
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixpanel_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keolo Keagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -176,7 +176,6 @@ files:
|
|
176
176
|
- manual_test/parallel.rb
|
177
177
|
- mixpanel_client.gemspec
|
178
178
|
- readme.md
|
179
|
-
- rubocop-todo.yml
|
180
179
|
- spec/mixpanel_client/events_externalspec.rb
|
181
180
|
- spec/mixpanel_client/mixpanel_client_spec.rb
|
182
181
|
- spec/mixpanel_client/properties_externalspec.rb
|
data/rubocop-todo.yml
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-03-15 09:50:10 -0700 using RuboCop version 0.19.0.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 60
|
9
|
-
#LineLength:
|
10
|
-
# Max: 262
|