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 CHANGED
@@ -1,6 +1,8 @@
1
1
  module Typhoeus
2
2
  class Easy
3
3
  attr_reader :response_body, :response_header, :method, :headers, :url
4
+ attr_accessor :start_time
5
+
4
6
  CURLINFO_STRING = 1048576
5
7
  OPTION_VALUES = {
6
8
  :CURLOPT_URL => 10002,
@@ -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
@@ -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)
@@ -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.19"
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].perform
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
@@ -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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pauldix-typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix