mixpanel_client 4.1.3 → 4.1.4

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: 16219b0342a1de3526173fec4cef7b177c7d3d90
4
- data.tar.gz: d294629422b0281940850d1ae049d599f3d40bca
3
+ metadata.gz: 20fdfa3521f3281e6319ae41fa6d15e99dc37db2
4
+ data.tar.gz: 377594c3362e46afcdd5c8c29cd5f68fbe665a4d
5
5
  SHA512:
6
- metadata.gz: 54d1c6e37edcac2164bf8916c413e441dbf961fcb7f57ccb2e5a8deaf5f1937d2461f866e5ed38e6ada430a608ed3f3ceaed227a00bad3b86bad9ef77aeea216
7
- data.tar.gz: a8c5fc45ecebb8ed674a99fd34c2aded7ae1af0764c4ed765139e3d039fde35b14d04346d014bbbb8aeefc432928ad83800655e94e063bdaba49c80940b8730f
6
+ metadata.gz: f46b04fae019e68ed8160c165652e99d5ce53cfcfc9da77f9f1099e0104260ce79cae277f8d09f74390751591f8ff83752d88e0d66400c2e9d2671785577698f
7
+ data.tar.gz: da3cf583fa0a6a5ffb1d83095b402332fa53735a863a1d22176e950215510fe72cf830f047a3e454c095ded8d42fb6252f81a0d20a90049c6f832ff2263bf8fa
data/changelog.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### v4.1.4
2
+ * Add timeout option: Merged PR #48
3
+
1
4
  ### v4.1.3
2
5
  * Make request options optional. Closes #46.
3
6
 
@@ -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
@@ -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.3'
13
+ VERSION = '4.1.4'
14
14
  end
15
15
  end
@@ -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.3
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: 2015-09-30 00:00:00.000000000 Z
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.4.8
204
+ rubygems_version: 2.5.1
205
205
  signing_key:
206
206
  specification_version: 4
207
207
  summary: Ruby Mixpanel API Client Library