mixpanel_client 4.1.3 → 4.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/changelog.md +3 -0
- data/lib/mixpanel/client.rb +3 -2
- data/lib/mixpanel/uri.rb +2 -2
- data/lib/mixpanel/version.rb +1 -1
- data/spec/mixpanel_client/mixpanel_client_spec.rb +15 -0
- data/spec/mixpanel_client/uri_spec.rb +23 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20fdfa3521f3281e6319ae41fa6d15e99dc37db2
|
4
|
+
data.tar.gz: 377594c3362e46afcdd5c8c29cd5f68fbe665a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f46b04fae019e68ed8160c165652e99d5ce53cfcfc9da77f9f1099e0104260ce79cae277f8d09f74390751591f8ff83752d88e0d66400c2e9d2671785577698f
|
7
|
+
data.tar.gz: da3cf583fa0a6a5ffb1d83095b402332fa53735a863a1d22176e950215510fe72cf830f047a3e454c095ded8d42fb6252f81a0d20a90049c6f832ff2263bf8fa
|
data/changelog.md
CHANGED
data/lib/mixpanel/client.rb
CHANGED
@@ -14,7 +14,7 @@ module Mixpanel
|
|
14
14
|
IMPORT_URI = 'https://api.mixpanel.com'
|
15
15
|
|
16
16
|
attr_reader :uri
|
17
|
-
attr_accessor :api_key, :api_secret, :parallel
|
17
|
+
attr_accessor :api_key, :api_secret, :parallel, :timeout
|
18
18
|
|
19
19
|
# Configure the client
|
20
20
|
#
|
@@ -27,6 +27,7 @@ module Mixpanel
|
|
27
27
|
@api_key = config[:api_key]
|
28
28
|
@api_secret = config[:api_secret]
|
29
29
|
@parallel = config[:parallel] || false
|
30
|
+
@timeout = config[:timeout] || nil
|
30
31
|
|
31
32
|
fail ConfigurationError if @api_key.nil? || @api_secret.nil?
|
32
33
|
end
|
@@ -63,7 +64,7 @@ module Mixpanel
|
|
63
64
|
end
|
64
65
|
|
65
66
|
def make_normal_request(resource)
|
66
|
-
response = URI.get(@uri)
|
67
|
+
response = URI.get(@uri, @timeout)
|
67
68
|
|
68
69
|
if %w(export import).include?(resource) && @format != 'raw'
|
69
70
|
response = %Q([#{response.split("\n").join(',')}])
|
data/lib/mixpanel/uri.rb
CHANGED
@@ -18,8 +18,8 @@ module Mixpanel
|
|
18
18
|
params.map { |key, val| "#{key}=#{CGI.escape(val.to_s)}" }.sort.join('&')
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.get(uri)
|
22
|
-
::URI.parse(uri).read
|
21
|
+
def self.get(uri, timeout)
|
22
|
+
::URI.parse(uri).read(read_timeout: timeout)
|
23
23
|
rescue OpenURI::HTTPError => error
|
24
24
|
raise HTTPError, JSON.parse(error.io.read)['error']
|
25
25
|
end
|
data/lib/mixpanel/version.rb
CHANGED
@@ -25,6 +25,21 @@ describe Mixpanel::Client do
|
|
25
25
|
parallel: true
|
26
26
|
).parallel.should eq true
|
27
27
|
end
|
28
|
+
|
29
|
+
it 'should set a timeout option as nil by default' do
|
30
|
+
Mixpanel::Client.new(
|
31
|
+
api_key: 'test_key',
|
32
|
+
api_secret: 'test_secret'
|
33
|
+
).timeout.should be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should be able to set a timeout option when passed' do
|
37
|
+
Mixpanel::Client.new(
|
38
|
+
api_key: 'test_key',
|
39
|
+
api_secret: 'test_secret',
|
40
|
+
timeout: 3
|
41
|
+
).timeout.should eql 3
|
42
|
+
end
|
28
43
|
end
|
29
44
|
|
30
45
|
context 'when making an invalid request' do
|
@@ -53,7 +53,29 @@ describe Mixpanel::URI do
|
|
53
53
|
it 'should return a string response' do
|
54
54
|
stub_request(:get, 'http://example.com').to_return(body: 'something')
|
55
55
|
|
56
|
-
Mixpanel::URI.get('http://example.com').should eq 'something'
|
56
|
+
Mixpanel::URI.get('http://example.com', nil).should eq 'something'
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when timeout is not nil' do
|
60
|
+
|
61
|
+
context 'when the request times out' do
|
62
|
+
it 'should return a timeout error' do
|
63
|
+
stub_request(:get, 'http://example.com').to_timeout
|
64
|
+
|
65
|
+
expect do
|
66
|
+
Mixpanel::URI.get('http://example.com', 3)
|
67
|
+
end.to raise_error Timeout::Error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when the request does not timeout' do
|
72
|
+
it 'should return a string response' do
|
73
|
+
stub_request(:get, 'http://example.com').to_return(body: 'something')
|
74
|
+
|
75
|
+
Mixpanel::URI.get('http://example.com', 3).should eq 'something'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
57
79
|
end
|
58
80
|
end
|
59
81
|
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.
|
4
|
+
version: 4.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keolo Keagy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
201
201
|
version: '0'
|
202
202
|
requirements: []
|
203
203
|
rubyforge_project: mixpanel_client
|
204
|
-
rubygems_version: 2.
|
204
|
+
rubygems_version: 2.5.1
|
205
205
|
signing_key:
|
206
206
|
specification_version: 4
|
207
207
|
summary: Ruby Mixpanel API Client Library
|