mixpanel_client 4.1.5 → 4.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 276a112f1f0c83a360953fb404392ba687bbaa5d
4
- data.tar.gz: 1c0a5f3b4d551b3529282a449ffff42f52d1fc0e
3
+ metadata.gz: a0b1c877cdcf416ba164f8e7b9fe9ab31857b090
4
+ data.tar.gz: bfd32fe4693da8458500b26fe18e2143dd03359b
5
5
  SHA512:
6
- metadata.gz: c6416ca4b99f358b9eeeecdeee63932299e83251b68e38b80d5e50196cdd3809c627d525515b483b2d0267d3694961a6539ba76ad3de8714c5b944e5878bfef9
7
- data.tar.gz: b241d59a34c755e505fb28cb63501f8da0414fa66fcfe2be27d14be536b7b17f359a62ad880da8a4b7936ec893b08196f9fed441f057fc2c51aaa4c9263bf73d
6
+ metadata.gz: 2b6d2372e919718d682ade39e7edf8740e31685c2e6272418c022e2b3374d53927a47e0dfd5a5c72d39a0df4bde2ad2c18943eed0acf01ea7708634989f372ff
7
+ data.tar.gz: 330f9bd86e8436c439944fced484d8919c07279ad7ce1dff5023e15e99a2aa7b9dde581e7cfbb5be71a6029d898be5ab8b9ef7b6cf1489d5cb026c266f82eb65
@@ -0,0 +1,21 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ fixme:
9
+ enabled: true
10
+ rubocop:
11
+ enabled: true
12
+ markdownlint:
13
+ enabled: true
14
+ reek:
15
+ enabled: true
16
+ ratings:
17
+ paths:
18
+ - "**.rb"
19
+ exclude_paths:
20
+ - config/
21
+ - spec/
@@ -1,3 +1,8 @@
1
+ ### v4.1.6
2
+ * Remove deprecated authentication options. Fixes #55.
3
+ * Use `expect` rspec syntax
4
+ * Added codeclimate config
5
+
1
6
  ### v4.1.5
2
7
  * Use new authentication method for mixpanel. Fixes #52.
3
8
  * Use `expect` rspec syntax
@@ -1,3 +1,2 @@
1
1
  mixpanel:
2
- :api_key: 'changeme'
3
2
  :api_secret: 'changeme'
@@ -9,27 +9,36 @@
9
9
  module Mixpanel
10
10
  # Return metrics from Mixpanel Data API
11
11
  class Client
12
- BASE_URI = 'https://mixpanel.com/api/2.0'
13
- DATA_URI = 'https://data.mixpanel.com/api/2.0'
14
- IMPORT_URI = 'https://api.mixpanel.com'
12
+ BASE_URI = 'https://mixpanel.com/api/2.0'.freeze
13
+ DATA_URI = 'https://data.mixpanel.com/api/2.0'.freeze
14
+ IMPORT_URI = 'https://api.mixpanel.com'.freeze
15
15
 
16
16
  attr_reader :uri
17
- attr_accessor :api_key, :api_secret, :parallel, :timeout
17
+ attr_accessor :api_secret, :parallel, :timeout
18
+
19
+ def self.base_uri_for_resource(resource)
20
+ if resource == 'export'
21
+ DATA_URI
22
+ elsif resource == 'import'
23
+ IMPORT_URI
24
+ else
25
+ BASE_URI
26
+ end
27
+ end
18
28
 
19
29
  # Configure the client
20
30
  #
21
31
  # @example
22
- # config = {api_key: '123', api_secret: '456'}
32
+ # config = {api_secret: '456'}
23
33
  # client = Mixpanel::Client.new(config)
24
34
  #
25
- # @param [Hash] config consisting of an 'api_key' and an 'api_secret'
35
+ # @param [Hash] config consisting of an 'api_secret' and additonal options
26
36
  def initialize(config)
27
- @api_key = config[:api_key]
28
37
  @api_secret = config[:api_secret]
29
38
  @parallel = config[:parallel] || false
30
39
  @timeout = config[:timeout] || nil
31
40
 
32
- fail ConfigurationError if @api_key.nil? || @api_secret.nil?
41
+ raise ConfigurationError, 'api_secret is required' if @api_secret.nil?
33
42
  end
34
43
 
35
44
  # Return mixpanel data as a JSON object or CSV string
@@ -97,6 +106,7 @@ module Mixpanel
97
106
  URI.mixpanel(resource, normalize_options(options))
98
107
  end
99
108
 
109
+ # TODO: Extract and refactor
100
110
  # rubocop:disable MethodLength
101
111
  def prepare_parallel_request
102
112
  request = ::Typhoeus::Request.new(@uri, userpwd: "#{@api_secret}:")
@@ -105,19 +115,19 @@ module Mixpanel
105
115
  if response.success?
106
116
  Utils.to_hash(response.body, @format)
107
117
  elsif response.timed_out?
108
- fail TimeoutError
118
+ raise TimeoutError
109
119
  elsif response.code == 0
110
120
  # Could not get an http response, something's wrong
111
- fail HTTPError, response.curl_error_message
121
+ raise HTTPError, response.curl_error_message
112
122
  else
113
123
  # Received a non-successful http response
114
- if response.body && response.body != ''
115
- error_message = JSON.parse(response.body)['error']
116
- else
117
- error_message = response.code.to_s
118
- end
124
+ error_message = if response.body && response.body != ''
125
+ JSON.parse(response.body)['error']
126
+ else
127
+ response.code.to_s
128
+ end
119
129
 
120
- fail HTTPError, error_message
130
+ raise HTTPError, error_message
121
131
  end
122
132
  end
123
133
 
@@ -141,27 +151,7 @@ module Mixpanel
141
151
  # signature
142
152
  def normalize_options(options)
143
153
  normalized_options = options.dup
144
-
145
- normalized_options
146
- .merge!(
147
- format: @format,
148
- expire: request_expires_at(normalized_options)
149
- )
150
- end
151
-
152
- def request_expires_at(options)
153
- ten_minutes_from_now = Time.now.to_i + 600
154
- options[:expire] ? options[:expire].to_i : ten_minutes_from_now
155
- end
156
-
157
- def self.base_uri_for_resource(resource)
158
- if resource == 'export'
159
- DATA_URI
160
- elsif resource == 'import'
161
- IMPORT_URI
162
- else
163
- BASE_URI
164
- end
154
+ normalized_options.merge!(format: @format)
165
155
  end
166
156
  end
167
157
  end
@@ -19,7 +19,10 @@ module Mixpanel
19
19
  end
20
20
 
21
21
  def self.get(uri, timeout, secret)
22
- ::URI.parse(uri).read(read_timeout: timeout, http_basic_authentication: [secret, nil])
22
+ ::URI.parse(uri).read(
23
+ read_timeout: timeout,
24
+ http_basic_authentication: [secret, nil]
25
+ )
23
26
  rescue OpenURI::HTTPError => error
24
27
  raise HTTPError, JSON.parse(error.io.read)['error']
25
28
  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.1.5'
13
+ VERSION = '4.1.6'.freeze
14
14
  end
15
15
  end
@@ -12,7 +12,6 @@ config = YAML.load_file(File.join(
12
12
  ))['mixpanel']
13
13
 
14
14
  client = Mixpanel::Client.new(
15
- api_key: config[:api_key],
16
15
  api_secret: config[:api_secret]
17
16
  )
18
17
 
@@ -20,7 +19,6 @@ data = client.request('events/properties',
20
19
  event: '["test-event"]',
21
20
  type: 'general',
22
21
  unit: 'hour',
23
- name: 'test'
24
- )
22
+ name: 'test')
25
23
 
26
24
  puts data.inspect
@@ -11,10 +11,10 @@ config = YAML.load_file(
11
11
  '..',
12
12
  'config',
13
13
  'mixpanel.yml'
14
- ))['mixpanel']
14
+ )
15
+ )['mixpanel']
15
16
 
16
17
  client = Mixpanel::Client.new(
17
- api_key: config[:api_key],
18
18
  api_secret: config[:api_secret],
19
19
  parallel: true
20
20
  )
data/readme.md CHANGED
@@ -22,7 +22,6 @@ or if you use a Gemfile
22
22
  require 'mixpanel_client'
23
23
 
24
24
  client = Mixpanel::Client.new(
25
- api_key: 'changeme',
26
25
  api_secret: 'changeme'
27
26
  )
28
27
 
@@ -69,7 +68,6 @@ You may also make requests in parallel by passing in the `parallel: true` option
69
68
  require 'mixpanel_client'
70
69
 
71
70
  client = Mixpanel::Client.new(
72
- api_key: 'changeme',
73
71
  api_secret: 'changeme',
74
72
  parallel: true
75
73
  )
@@ -29,8 +29,7 @@ describe 'External calls to mixpanel' do
29
29
  event: '["test-event"]',
30
30
  type: 'general',
31
31
  unit: 'hour',
32
- interval: 24
33
- )
32
+ interval: 24)
34
33
  expect(data).to_not be_a Exception
35
34
  end
36
35
 
@@ -40,8 +39,7 @@ describe 'External calls to mixpanel' do
40
39
  type: 'general',
41
40
  unit: 'hour',
42
41
  interval: 24,
43
- format: 'csv'
44
- )
42
+ format: 'csv')
45
43
  expect(data).to_not be_a Exception
46
44
  end
47
45
 
@@ -51,16 +49,14 @@ describe 'External calls to mixpanel' do
51
49
  type: 'general',
52
50
  unit: 'hour',
53
51
  interval: 24,
54
- bucket: 'test'
55
- )
52
+ bucket: 'test')
56
53
  expect(data).to_not be_a Exception
57
54
  end
58
55
 
59
56
  it 'should return top events' do
60
57
  data = @client.request('events/top',
61
58
  type: 'general',
62
- limit: 10
63
- )
59
+ limit: 10)
64
60
  expect(data).to_not be_a Exception
65
61
  end
66
62
 
@@ -69,8 +65,7 @@ describe 'External calls to mixpanel' do
69
65
  type: 'general',
70
66
  unit: 'hour',
71
67
  interval: 24,
72
- limit: 10
73
- )
68
+ limit: 10)
74
69
  expect(data).to_not be_a Exception
75
70
  end
76
71
 
@@ -80,8 +75,7 @@ describe 'External calls to mixpanel' do
80
75
  event: '["test-event"]',
81
76
  type: 'general',
82
77
  unit: 'hour',
83
- interval: 24
84
- )
78
+ interval: 24)
85
79
  expect(data).to_not be_a Exception
86
80
  end
87
81
 
@@ -92,8 +86,7 @@ describe 'External calls to mixpanel' do
92
86
  type: 'general',
93
87
  unit: 'hour',
94
88
  interval: 24,
95
- format: 'csv'
96
- )
89
+ format: 'csv')
97
90
  expect(data).to_not be_a Exception
98
91
  end
99
92
  end
@@ -3,7 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
3
3
  describe Mixpanel::Client do
4
4
  before :all do
5
5
  @client = Mixpanel::Client.new(
6
- api_key: 'test_key',
7
6
  api_secret: 'test_secret'
8
7
  )
9
8
 
@@ -13,14 +12,12 @@ describe Mixpanel::Client do
13
12
  context 'when initializing a new Mixpanel::Client' do
14
13
  it 'should set a parallel option as false by default' do
15
14
  expect(Mixpanel::Client.new(
16
- api_key: 'test_key',
17
15
  api_secret: 'test_secret'
18
16
  ).parallel).to eq(false)
19
17
  end
20
18
 
21
19
  it 'should be able to set a parallel option when passed' do
22
20
  expect(Mixpanel::Client.new(
23
- api_key: 'test_key',
24
21
  api_secret: 'test_secret',
25
22
  parallel: true
26
23
  ).parallel).to eq(true)
@@ -28,14 +25,12 @@ describe Mixpanel::Client do
28
25
 
29
26
  it 'should set a timeout option as nil by default' do
30
27
  expect(Mixpanel::Client.new(
31
- api_key: 'test_key',
32
28
  api_secret: 'test_secret'
33
29
  ).timeout).to be_nil
34
30
  end
35
31
 
36
32
  it 'should be able to set a timeout option when passed' do
37
33
  expect(Mixpanel::Client.new(
38
- api_key: 'test_key',
39
34
  api_secret: 'test_secret',
40
35
  timeout: 3
41
36
  ).timeout).to eql(3)
@@ -43,22 +38,12 @@ describe Mixpanel::Client do
43
38
  end
44
39
 
45
40
  context 'when making an invalid request' do
46
- it 'should raise an error when API key is null' do
47
- expect do
48
- Mixpanel::Client.new(
49
- api_key: nil,
50
- api_secret: 'test_secret'
51
- )
52
- end.to raise_error
53
- end
54
-
55
41
  it 'should raise an error when API secret is null' do
56
42
  expect do
57
43
  Mixpanel::Client.new(
58
- api_key: 'test_key',
59
44
  api_secret: nil
60
45
  )
61
- end.to raise_error
46
+ end.to raise_error(Mixpanel::ConfigurationError)
62
47
  end
63
48
 
64
49
  it 'should return an argument error "Wrong number of arguments" if using
@@ -154,52 +139,9 @@ describe Mixpanel::Client do
154
139
  end.to_not change { options }
155
140
  end
156
141
 
157
- context 'with a custom expiry time' do
158
- # Stub Mixpanel request
159
- before do
160
- stub_request(:get, /^#{@uri}.*/)
161
- .to_return(
162
- body: '{"events": [], "type": "general"}'
163
- )
164
- end
165
-
166
- let(:expiry) { Time.now + 100_000 }
167
- let(:fake_url) { Mixpanel::Client::BASE_URI }
168
-
169
- specify 'Client#request should return a hash with empty events and
170
- type' do
171
- # With endpoint
172
- data = @client.request(
173
- 'events/top',
174
- type: 'general',
175
- expire: expiry
176
- )
177
-
178
- data.should eq(
179
- 'events' => [],
180
- 'type' => 'general'
181
- )
182
- end
183
-
184
- specify 'Mixpanel::URI instance should receive the custom expiry time in
185
- the options[:expiry] instead of 600s' do
186
- expect(Mixpanel::URI).to receive(:mixpanel) do |*args|
187
- args.pop[:expire].should eq expiry.to_i
188
- true
189
- end.and_return(fake_url)
190
-
191
- @client.request(
192
- 'events/top',
193
- type: 'general',
194
- expire: expiry
195
- )
196
- end
197
- end
198
-
199
142
  context 'with parallel option enabled' do
200
143
  before :all do
201
144
  @parallel_client = Mixpanel::Client.new(
202
- api_key: 'test_key',
203
145
  api_secret: 'test_secret',
204
146
  parallel: true
205
147
  )
@@ -225,7 +167,7 @@ describe Mixpanel::Client do
225
167
 
226
168
  describe '#hydra' do
227
169
  it 'should return a Typhoeus::Hydra object' do
228
- @parallel_client.hydra.should be_a Typhoeus::Hydra
170
+ expect(@parallel_client.hydra).to be_a Typhoeus::Hydra
229
171
  end
230
172
  end
231
173
 
@@ -282,7 +224,7 @@ describe Mixpanel::Client do
282
224
 
283
225
  @parallel_client.run_parallel_requests
284
226
 
285
- first_request.response.handled_response.should eq(
227
+ expect(first_request.response.handled_response).to eq(
286
228
  'data' => {
287
229
  'series' => %w(2010-05-29 2010-05-30 2010-05-31),
288
230
  'values' => {
@@ -299,7 +241,7 @@ describe Mixpanel::Client do
299
241
  'legend_size' => 1
300
242
  )
301
243
 
302
- second_request.response.handled_response.should eq(
244
+ expect(second_request.response.handled_response).to eq(
303
245
  'data' => {
304
246
  'series' => %w(2010-05-29 2010-05-30 2010-05-31),
305
247
  'values' => {
@@ -335,15 +277,15 @@ describe Mixpanel::Client do
335
277
  @client.api_secret
336
278
  )
337
279
 
338
- unsorted_signature.should eq sorted_signature
280
+ expect(unsorted_signature).to eq sorted_signature
339
281
  end
340
282
  end
341
283
 
342
284
  describe '#to_hash' do
343
285
  it 'should return a ruby hash given json as a string' do
344
286
  expect(Mixpanel::Client::Utils.to_hash(
345
- '{"a" : "ey", "b" : "bee"}',
346
- :json
287
+ '{"a" : "ey", "b" : "bee"}',
288
+ :json
347
289
  )).to eq(
348
290
  'a' => 'ey',
349
291
  'b' => 'bee'
@@ -12,7 +12,7 @@ describe 'External calls to mixpanel' do
12
12
  'mixpanel.yml'
13
13
  ))['mixpanel']
14
14
 
15
- config.should_not be_nil
15
+ expect(config).not_to be_nil
16
16
  @client = Mixpanel::Client.new(config)
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ describe 'External calls to mixpanel' do
21
21
  data = lambda do
22
22
  @client.request('properties', {})
23
23
  end
24
- data.should raise_error(Mixpanel::HTTPError)
24
+ expect(data).to raise_error(Mixpanel::HTTPError)
25
25
  end
26
26
 
27
27
  it 'should return events' do
@@ -33,9 +33,8 @@ describe 'External calls to mixpanel' do
33
33
  unit: 'hour',
34
34
  interval: 24,
35
35
  limit: 5,
36
- bucket: 'kicked'
37
- )
38
- data.should_not be_a Exception
36
+ bucket: 'kicked')
37
+ expect(data).not_to be_a Exception
39
38
  end
40
39
  end
41
40
  end
@@ -8,7 +8,7 @@ describe Mixpanel::URI do
8
8
  resource = 'events'
9
9
  params = { c: 'see', a: 'ey' }
10
10
 
11
- Mixpanel::URI.mixpanel(resource, params).should eq(
11
+ expect(Mixpanel::URI.mixpanel(resource, params)).to eq(
12
12
  "#{Mixpanel::Client::BASE_URI}/events?a=ey&c=see"
13
13
  )
14
14
  end
@@ -18,7 +18,7 @@ describe Mixpanel::URI do
18
18
  resource = 'events/top'
19
19
  params = { c: 'see', a: 'ey' }
20
20
 
21
- Mixpanel::URI.mixpanel(resource, params).should eq(
21
+ expect(Mixpanel::URI.mixpanel(resource, params)).to eq(
22
22
  "#{Mixpanel::Client::BASE_URI}/events/top?a=ey&c=see"
23
23
  )
24
24
  end
@@ -28,7 +28,7 @@ describe Mixpanel::URI do
28
28
  resource = 'export'
29
29
  params = { c: 'see', a: 'ey' }
30
30
 
31
- Mixpanel::URI.mixpanel(resource, params).should eq(
31
+ expect(Mixpanel::URI.mixpanel(resource, params)).to eq(
32
32
  "#{Mixpanel::Client::DATA_URI}/export?a=ey&c=see"
33
33
  )
34
34
  end
@@ -37,7 +37,7 @@ describe Mixpanel::URI do
37
37
  import' do
38
38
  resource = 'import'
39
39
  params = { c: 'see', a: 'ey' }
40
- Mixpanel::URI.mixpanel(resource, params).should eq(
40
+ expect(Mixpanel::URI.mixpanel(resource, params)).to eq(
41
41
  "#{Mixpanel::Client::IMPORT_URI}/import?a=ey&c=see"
42
42
  )
43
43
  end
@@ -47,8 +47,9 @@ describe Mixpanel::URI do
47
47
  it 'should return a string with url encoded values.' do
48
48
  params = { hey: '!@#$%^&*()\/"Ü', soo: 'hëllö?' }
49
49
 
50
- Mixpanel::URI.encode(params).should eq(
51
- 'hey=%21%40%23%24%25%5E%26%2A%28%29%5C%2F%22%C3%9C&soo=h%C3%ABll%C3%B6%3F' # rubocop:disable LineLength
50
+ expect(Mixpanel::URI.encode(params)).to eq(
51
+ 'hey=%21%40%23%24%25%5E%26%2A%28%29%5C%2F%22%C3%9C&' +
52
+ 'soo=h%C3%ABll%C3%B6%3F'
52
53
  )
53
54
  end
54
55
  end
@@ -57,7 +58,8 @@ describe Mixpanel::URI do
57
58
  it 'should return a string response' do
58
59
  stub_request(:get, 'http://example.com').to_return(body: 'something')
59
60
 
60
- Mixpanel::URI.get('http://example.com', nil, 'secret').should eq 'something'
61
+ expect(Mixpanel::URI.get('http://example.com', nil, 'secret')).to \
62
+ eq('something')
61
63
  end
62
64
 
63
65
  context 'when timeout is not nil' do
@@ -75,7 +77,8 @@ describe Mixpanel::URI do
75
77
  it 'should return a string response' do
76
78
  stub_request(:get, 'http://example.com').to_return(body: 'something')
77
79
 
78
- Mixpanel::URI.get('http://example.com', 3, 'secret').should eq 'something'
80
+ expect(Mixpanel::URI.get('http://example.com', 3, 'secret')).to \
81
+ eq('something')
79
82
  end
80
83
  end
81
84
  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.1.5
4
+ version: 4.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keolo Keagy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-30 00:00:00.000000000 Z
11
+ date: 2016-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -157,6 +157,7 @@ executables: []
157
157
  extensions: []
158
158
  extra_rdoc_files: []
159
159
  files:
160
+ - ".codeclimate.yml"
160
161
  - ".document"
161
162
  - ".gitignore"
162
163
  - ".rubocop.yml"