pauldix-typhoeus 0.0.19 → 0.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/typhoeus/easy.rb +2 -0
- data/lib/typhoeus/multi.rb +14 -1
- data/lib/typhoeus/remote.rb +2 -1
- data/lib/typhoeus/remote_proxy_object.rb +2 -1
- data/lib/typhoeus/response.rb +2 -1
- data/lib/typhoeus.rb +7 -2
- data/spec/typhoeus/easy_spec.rb +10 -0
- data/spec/typhoeus/multi_spec.rb +13 -1
- metadata +1 -1
data/lib/typhoeus/easy.rb
CHANGED
data/lib/typhoeus/multi.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module Typhoeus
|
2
2
|
class Multi
|
3
|
+
attr_reader :easy_handles
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
reset_easy_handles
|
7
|
+
end
|
8
|
+
|
3
9
|
def remove(easy)
|
4
10
|
multi_remove_handle(easy)
|
5
11
|
end
|
6
12
|
|
7
13
|
def add(easy)
|
14
|
+
@easy_handles << easy
|
8
15
|
multi_add_handle(easy)
|
9
16
|
end
|
10
17
|
|
@@ -12,10 +19,16 @@ module Typhoeus
|
|
12
19
|
while active_handle_count > 0 do
|
13
20
|
multi_perform
|
14
21
|
end
|
22
|
+
reset_easy_handles
|
15
23
|
end
|
16
24
|
|
17
25
|
def cleanup()
|
18
26
|
multi_cleanup
|
19
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def reset_easy_handles
|
31
|
+
@easy_handles = []
|
32
|
+
end
|
20
33
|
end
|
21
|
-
end
|
34
|
+
end
|
data/lib/typhoeus/remote.rb
CHANGED
@@ -65,7 +65,8 @@ module Typhoeus
|
|
65
65
|
return nil unless @remote_mocks
|
66
66
|
if @remote_mocks.has_key? method
|
67
67
|
extra_response_args = { :requested_http_method => method,
|
68
|
-
:requested_url => url
|
68
|
+
:requested_url => url,
|
69
|
+
:start_time => Time.now }
|
69
70
|
mock_key = mock_key_for(url, options[:params])
|
70
71
|
if @remote_mocks[method].has_key? mock_key
|
71
72
|
get_mock_and_run_handlers(method,
|
@@ -26,7 +26,8 @@ module Typhoeus
|
|
26
26
|
:body => @easy.response_body,
|
27
27
|
:time => @easy.total_time_taken,
|
28
28
|
:requested_url => @easy.url,
|
29
|
-
:requested_http_method => @easy.method
|
29
|
+
:requested_http_method => @easy.method,
|
30
|
+
:start_time => @easy.start_time)
|
30
31
|
if @easy.response_code >= 200 && @easy.response_code < 300
|
31
32
|
Typhoeus.release_easy_object(@easy)
|
32
33
|
@proxied_object = @success.nil? ? response : @success.call(response)
|
data/lib/typhoeus/response.rb
CHANGED
@@ -2,7 +2,7 @@ module Typhoeus
|
|
2
2
|
class Response
|
3
3
|
attr_reader :code, :headers, :body, :time,
|
4
4
|
:requested_url, :requested_remote_method,
|
5
|
-
:requested_http_method
|
5
|
+
:requested_http_method, :start_time
|
6
6
|
|
7
7
|
def initialize(params = {})
|
8
8
|
@code = params[:code]
|
@@ -11,6 +11,7 @@ module Typhoeus
|
|
11
11
|
@time = params[:time]
|
12
12
|
@requested_url = params[:requested_url]
|
13
13
|
@requested_http_method = params[:requested_http_method]
|
14
|
+
@start_time = params[:start_time]
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/typhoeus.rb
CHANGED
@@ -12,7 +12,7 @@ require 'typhoeus/remote_proxy_object'
|
|
12
12
|
require 'typhoeus/response'
|
13
13
|
|
14
14
|
module Typhoeus
|
15
|
-
VERSION = "0.0.
|
15
|
+
VERSION = "0.0.20"
|
16
16
|
|
17
17
|
def self.easy_object_pool
|
18
18
|
@easy_objects ||= []
|
@@ -43,6 +43,11 @@ module Typhoeus
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def self.perform_easy_requests
|
46
|
-
Thread.current[:curl_multi]
|
46
|
+
multi = Thread.current[:curl_multi]
|
47
|
+
start_time = Time.now
|
48
|
+
multi.easy_handles.each do |easy|
|
49
|
+
easy.start_time = start_time
|
50
|
+
end
|
51
|
+
multi.perform
|
47
52
|
end
|
48
53
|
end
|
data/spec/typhoeus/easy_spec.rb
CHANGED
@@ -47,6 +47,16 @@ describe Typhoeus::Easy do
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
describe "start_time" do
|
51
|
+
it "should be get/settable" do
|
52
|
+
time = Time.now
|
53
|
+
easy = Typhoeus::Easy.new
|
54
|
+
easy.start_time.should be_nil
|
55
|
+
easy.start_time = time
|
56
|
+
easy.start_time.should == time
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
50
60
|
describe "params=" do
|
51
61
|
it "should handle arrays of params" do
|
52
62
|
easy = Typhoeus::Easy.new
|
data/spec/typhoeus/multi_spec.rb
CHANGED
@@ -8,6 +8,18 @@ describe Typhoeus::Easy do
|
|
8
8
|
after(:all) do
|
9
9
|
stop_method_server(@pid)
|
10
10
|
end
|
11
|
+
|
12
|
+
it "should save easy handles that get added" do
|
13
|
+
multi = Typhoeus::Multi.new
|
14
|
+
easy = Typhoeus::Easy.new
|
15
|
+
easy.url = "http://localhost:3002"
|
16
|
+
easy.method = :get
|
17
|
+
|
18
|
+
multi.add(easy)
|
19
|
+
multi.easy_handles.should == [easy]
|
20
|
+
multi.perform
|
21
|
+
multi.easy_handles.should == []
|
22
|
+
end
|
11
23
|
|
12
24
|
it "should be reusable" do
|
13
25
|
easy = Typhoeus::Easy.new
|
@@ -67,4 +79,4 @@ describe Typhoeus::Easy do
|
|
67
79
|
#
|
68
80
|
# multi.perform
|
69
81
|
# end
|
70
|
-
end
|
82
|
+
end
|