mixpanel_client 4.0.0 → 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ad60587553d1e52a0c6d6a1ec10979df8cc8631
4
- data.tar.gz: 7c41a327214234103fe8d4c55176f77d5f1e1263
3
+ metadata.gz: 5db50334f0523f186df3366c7e79565ea7eca601
4
+ data.tar.gz: e28c9cf521c8d160a6d3b6ef1086bf7de6efb4a5
5
5
  SHA512:
6
- metadata.gz: 276355241d2ca211363a21065ab30b30e48a2d97edbef1f13e92b797393f14c46ae276e8f8ce48706bc300beadc968c98d7cb47e19d577932c0dfc2246abda4c
7
- data.tar.gz: 778fa6fce160a6b2092177f11165e71823cf4348c3bea51e75b6bd037f25f8ce1bc09caadca64af91deaf3a8d4080654ab5522c93e26243558eab7714132f7cb
6
+ metadata.gz: 4b07b4bdc7b798cc10fda6e61502ed858a0530b24b9404a9ac5fc266c130c0e3829c0c19de28b694f8de2f8eab174bac186a80d97a28e5e0d3d8243272869d39
7
+ data.tar.gz: 28924015e8b5fc7f5b1404821e54ba9c474ce94edc84c8b12d18bfb628931c1ff1a768b36f43c4775abcec021c8fdc12024e5bec8b61d7507f8d10df0d8d3f92
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # For now we're ignoring rules in the following file. We should gradually
2
2
  # remove rules over time so that we don't need this file anymore.
3
- inherit_from: rubocop-todo.yml
3
+ #inherit_from: rubocop-todo.yml
4
4
 
5
5
  AllCops:
6
6
  Includes:
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
-
@@ -19,29 +19,32 @@ module Mixpanel
19
19
  # Configure the client
20
20
  #
21
21
  # @example
22
- # config = {'api_key' => '123', 'api_secret' => '456'}
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 = config[:parallel] || false
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('events/properties', {
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: 24,
42
- # limit: 5,
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('events/properties', {
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: 24,
81
- # limit: 5,
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
@@ -12,4 +12,5 @@ module Mixpanel
12
12
  class HTTPError < Error; end
13
13
  class TimeoutError < Error; end
14
14
  class ParseError < Error; end
15
+ class ConfigurationError < Error; end
15
16
  end
@@ -10,6 +10,6 @@ module Mixpanel
10
10
  # Return metrics from Mixpanel Data API
11
11
  class Client
12
12
  # Mixpanel::Client library version
13
- VERSION = '4.0.0'
13
+ VERSION = '4.0.1'
14
14
  end
15
15
  end
data/license CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Keolo Keagy
1
+ Copyright (c) 2009+ Keolo Keagy
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -13,20 +13,22 @@ config = YAML.load_file(File.join(
13
13
  ))['mixpanel']
14
14
 
15
15
  client = Mixpanel::Client.new(
16
- api_key: config[:api_key],
16
+ api_key: config[:api_key],
17
17
  api_secret: config[:api_secret],
18
- parallel: true
18
+ parallel: true
19
19
  )
20
20
 
21
- f = client.request('events/top',
22
- type: 'general'
21
+ uno = client.request(
22
+ 'events/top',
23
+ type: 'general'
23
24
  )
24
25
 
25
- s = client.request('events/names',
26
- type: 'general'
26
+ dos = client.request(
27
+ 'events/names',
28
+ type: 'general'
27
29
  )
28
30
 
29
31
  client.run_parallel_requests
30
32
 
31
- puts f.response.handled_response.inspect
32
- puts s.response.handled_response.inspect
33
+ puts uno.response.handled_response.inspect
34
+ puts dos.response.handled_response.inspect
@@ -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 (for API version 2.0)
1
+ # Mixpanel Data API Client
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/mixpanel_client.png)](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
- config = {api_key: 'changeme', api_secret: 'changeme'}
21
- client = Mixpanel::Client.new(config)
22
+ client = Mixpanel::Client.new(
23
+ api_key: 'changeme',
24
+ api_secret: 'changeme'
25
+ )
22
26
 
23
- data = client.request('events/properties', {
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: 5,
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('events/properties', {
38
- event: 'splash features',
39
- name: 'feature',
40
- values: '["uno", "dos"]',
41
- type: 'unique',
42
- unit: 'day',
43
- interval: 7,
44
- limit: 5,
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
- config = {api_key: 'changeme', api_secret: 'changeme', parallel: true}
63
- client = Mixpanel::Client.new(config)
70
+ client = Mixpanel::Client.new(
71
+ api_key: 'changeme',
72
+ api_secret: 'changeme',
73
+ parallel: true
74
+ )
64
75
 
65
- first_request = client.request('events/properties', {
66
- ...
67
- })
76
+ first_request = client.request(
77
+ 'events/properties',
78
+ ...
79
+ )
68
80
 
69
- second_request = client.request('events/properties', {
70
- ...
71
- })
81
+ second_request = client.request(
82
+ 'events/properties',
83
+ ...
84
+ )
72
85
 
73
- third_request = client.request('events/properties', {
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
- ## Releasing Gem
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
- Create tag v2.0.2 and build and push mixpanel_client-2.0.2.gem to Rubygems
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 LICENSE for details.
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@client.request(nil, :events,
47
- event: '["test-event"]',
48
- unit: 'hour',
49
- interval: 24
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('events',
66
- event: '["test-event"]',
67
- unit: 'hour',
68
- interval: 24
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('import',
85
- data: 'base64_encoded_data',
86
- api_key: 'test_key'
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
- @client.request('events/top',
157
- type: 'general',
158
- expire: expiry
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.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-15 00:00:00.000000000 Z
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