typhoeus 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,20 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.5.1...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.5.2...master)
6
+
7
+ ## 0.5.2
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.5.1...v0.5.2)
10
+
11
+ Enhancements:
12
+
13
+ * Do not check the return_code in Response#success? when response is mocked.
14
+ * Check for memoization, stubbing, before hooks are delayed to Hydra#run. It
15
+ was on Hydra#queue before and led to strange behavior because if the request
16
+ was stubbed, it was wrapped up in queue already. There was no way to add
17
+ callbacks after queue thatswhy. This is now different, since everything happens
18
+ in run, just as you expect.
6
19
 
7
20
  ## 0.5.1
8
21
 
@@ -1,3 +1,4 @@
1
+ require 'typhoeus/hydra/addable'
1
2
  require 'typhoeus/hydra/before'
2
3
  require 'typhoeus/hydra/block_connection'
3
4
  require 'typhoeus/hydra/easy_factory'
@@ -40,12 +41,13 @@ module Typhoeus
40
41
  # execution.
41
42
  class Hydra
42
43
  include Hydra::EasyPool
43
- include Hydra::Queueable
44
+ include Hydra::Addable
44
45
  include Hydra::Runnable
45
46
  include Hydra::Memoizable
46
47
  include Hydra::BlockConnection
47
48
  include Hydra::Stubbable
48
49
  include Hydra::Before
50
+ include Hydra::Queueable
49
51
 
50
52
  # @example Set max_concurrency.
51
53
  # Typhoeus::Hydra.new(max_concurrency: 20)
@@ -0,0 +1,23 @@
1
+ module Typhoeus
2
+ class Hydra
3
+
4
+ # This module handles the request adding on
5
+ # hydra.
6
+ #
7
+ # @api private
8
+ module Addable
9
+
10
+ # Adds request to multi.
11
+ #
12
+ # @example Add request.
13
+ # hydra.add(request)
14
+ #
15
+ # @param [ Typhoeus::Request ] request to add.
16
+ #
17
+ # @return [ void ]
18
+ def add(request)
19
+ multi.add(Hydra::EasyFactory.new(request, self).get)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -9,14 +9,14 @@ module Typhoeus
9
9
  # @api private
10
10
  module Before
11
11
 
12
- # Overrride queue in order to execute callbacks in
12
+ # Overrride add in order to execute callbacks in
13
13
  # Typhoeus.before. Will break and return when a
14
14
  # callback returns nil or false. Calls super
15
15
  # otherwise.
16
16
  #
17
- # @example Queue the request.
18
- # hydra.queue(request)
19
- def queue(request)
17
+ # @example Add the request.
18
+ # hydra.add(request)
19
+ def add(request)
20
20
  Typhoeus.before.each do |callback|
21
21
  value = callback.call(request)
22
22
  if value.nil? || value == false || value.is_a?(Response)
@@ -15,15 +15,15 @@ module Typhoeus
15
15
  # @api private
16
16
  module BlockConnection
17
17
 
18
- # Overrides queue in order to check before if block connection
18
+ # Overrides add in order to check before if block connection
19
19
  # is turned on. If thats the case a NoStub error is
20
20
  # raised.
21
21
  #
22
- # @example Queue the request.
23
- # hydra.queue(request)
22
+ # @example Add the request.
23
+ # hydra.add(request)
24
24
  #
25
25
  # @param [ Request ] request The request to enqueue.
26
- def queue(request)
26
+ def add(request)
27
27
  if request.blocked?
28
28
  raise Typhoeus::Errors::NoStub.new(request)
29
29
  else
@@ -70,7 +70,7 @@ module Typhoeus
70
70
  easy.on_complete do |easy|
71
71
  request.finish(Response.new(easy.to_hash))
72
72
  hydra.release_easy(easy)
73
- hydra.queue(hydra.queued_requests.shift) unless hydra.queued_requests.empty?
73
+ hydra.add(hydra.queued_requests.shift) unless hydra.queued_requests.empty?
74
74
  end
75
75
  end
76
76
  end
@@ -21,18 +21,18 @@ module Typhoeus
21
21
  @memory ||= {}
22
22
  end
23
23
 
24
- # Overrides queue in order to check before if request
24
+ # Overrides add in order to check before if request
25
25
  # is memoizable and already in memory. If thats the case,
26
26
  # super is not called, instead the response is set and
27
27
  # the on_complete callback called.
28
28
  #
29
- # @example Queue the request.
30
- # hydra.queue(request)
29
+ # @example Add the request.
30
+ # hydra.add(request)
31
31
  #
32
- # @param [ Request ] request The request to enqueue.
32
+ # @param [ Request ] request The request to add.
33
33
  #
34
- # @return [ Request ] The queued request.
35
- def queue(request)
34
+ # @return [ Request ] The added request.
35
+ def add(request)
36
36
  if request.memoizable? && memory.has_key?(request)
37
37
  response = memory[request]
38
38
  request.finish(response, true)
@@ -37,11 +37,7 @@ module Typhoeus
37
37
  # hydra.queue(request)
38
38
  def queue(request)
39
39
  request.hydra = self
40
- if multi.easy_handles.size < max_concurrency
41
- multi.add(Hydra::EasyFactory.new(request, self).get)
42
- else
43
- queued_requests << request
44
- end
40
+ queued_requests << request
45
41
  end
46
42
  end
47
43
  end
@@ -2,8 +2,6 @@ module Typhoeus
2
2
  class Hydra
3
3
 
4
4
  # This module contains logic to run a hydra.
5
- #
6
- # @api private
7
5
  module Runnable
8
6
 
9
7
  # Start the hydra run.
@@ -13,6 +11,9 @@ module Typhoeus
13
11
  #
14
12
  # @return [ Symbol ] Return value from multi.perform.
15
13
  def run
14
+ queued_requests.pop(max_concurrency).map do |request|
15
+ add(request)
16
+ end
16
17
  multi.perform
17
18
  end
18
19
  end
@@ -8,13 +8,13 @@ module Typhoeus
8
8
  # @api private
9
9
  module Stubbable
10
10
 
11
- # Override queue in order to check for matching expecations.
11
+ # Override add in order to check for matching expecations.
12
12
  # When an expecation is found, super is not called. Instead a
13
13
  # canned response is assigned to the request.
14
14
  #
15
- # @example Queue the request.
16
- # hydra.queue(request)
17
- def queue(request)
15
+ # @example Add the request.
16
+ # hydra.add(request)
17
+ def add(request)
18
18
  if expectation = Expectation.find_by(request)
19
19
  request.finish(expectation.response)
20
20
  else
@@ -46,7 +46,7 @@ module Typhoeus
46
46
  #
47
47
  # @return [ Boolean ] Return true if successful, false else.
48
48
  def success?
49
- return_code == :ok && response_code >= 200 && response_code < 300
49
+ (mock || return_code == :ok) && response_code && response_code >= 200 && response_code < 300
50
50
  end
51
51
 
52
52
  # Return wether the response is modified.
@@ -56,7 +56,7 @@ module Typhoeus
56
56
  #
57
57
  # @return [ Boolean ] Return true if modified, false else.
58
58
  def modified?
59
- return_code == :ok && response_code != 304
59
+ (mock || return_code == :ok) && response_code && response_code != 304
60
60
  end
61
61
 
62
62
  # Return wether the response is timed out.
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.2'
5
5
  end
metadata CHANGED
@@ -1,103 +1,74 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.5.1
4
+ version: 0.5.2
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Balatero
9
9
  - Paul Dix
10
10
  - Hans Hasselberg
11
- autorequire:
11
+ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-09 00:00:00.000000000 Z
14
+ date: 2012-11-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ethon
18
- version_requirements: !ruby/object:Gem::Requirement
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
19
20
  requirements:
20
- - - '='
21
+ - - ~>
21
22
  - !ruby/object:Gem::Version
22
23
  version: 0.5.3
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
23
27
  none: false
24
- requirement: !ruby/object:Gem::Requirement
25
28
  requirements:
26
- - - '='
29
+ - - ~>
27
30
  - !ruby/object:Gem::Version
28
31
  version: 0.5.3
29
- none: false
30
- prerelease: false
31
- type: :runtime
32
- description: Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
32
+ description: Like a modern code version of the mythical beast with 100 serpent heads,
33
+ Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
33
34
  email:
34
35
  - hans.hasselberg@gmail.com
35
36
  executables: []
36
37
  extensions: []
37
38
  extra_rdoc_files: []
38
39
  files:
39
- - !binary |-
40
- bGliL3R5cGhvZXVzLnJi
41
- - !binary |-
42
- bGliL3R5cGhvZXVzL2NvbmZpZy5yYg==
43
- - !binary |-
44
- bGliL3R5cGhvZXVzL2Vycm9ycy5yYg==
45
- - !binary |-
46
- bGliL3R5cGhvZXVzL2V4cGVjdGF0aW9uLnJi
47
- - !binary |-
48
- bGliL3R5cGhvZXVzL2h5ZHJhLnJi
49
- - !binary |-
50
- bGliL3R5cGhvZXVzL3JlcXVlc3QucmI=
51
- - !binary |-
52
- bGliL3R5cGhvZXVzL3Jlc3BvbnNlLnJi
53
- - !binary |-
54
- bGliL3R5cGhvZXVzL3ZlcnNpb24ucmI=
55
- - !binary |-
56
- bGliL3R5cGhvZXVzL2FkYXB0ZXJzL2ZhcmFkYXkucmI=
57
- - !binary |-
58
- bGliL3R5cGhvZXVzL2Vycm9ycy9ub19zdHViLnJi
59
- - !binary |-
60
- bGliL3R5cGhvZXVzL2Vycm9ycy90eXBob2V1c19lcnJvci5yYg==
61
- - !binary |-
62
- bGliL3R5cGhvZXVzL2h5ZHJhL2JlZm9yZS5yYg==
63
- - !binary |-
64
- bGliL3R5cGhvZXVzL2h5ZHJhL2Jsb2NrX2Nvbm5lY3Rpb24ucmI=
65
- - !binary |-
66
- bGliL3R5cGhvZXVzL2h5ZHJhL2Vhc3lfZmFjdG9yeS5yYg==
67
- - !binary |-
68
- bGliL3R5cGhvZXVzL2h5ZHJhL2Vhc3lfcG9vbC5yYg==
69
- - !binary |-
70
- bGliL3R5cGhvZXVzL2h5ZHJhL21lbW9pemFibGUucmI=
71
- - !binary |-
72
- bGliL3R5cGhvZXVzL2h5ZHJhL3F1ZXVlYWJsZS5yYg==
73
- - !binary |-
74
- bGliL3R5cGhvZXVzL2h5ZHJhL3J1bm5hYmxlLnJi
75
- - !binary |-
76
- bGliL3R5cGhvZXVzL2h5ZHJhL3N0dWJiYWJsZS5yYg==
77
- - !binary |-
78
- bGliL3R5cGhvZXVzL3JlcXVlc3QvYWN0aW9ucy5yYg==
79
- - !binary |-
80
- bGliL3R5cGhvZXVzL3JlcXVlc3QvYmVmb3JlLnJi
81
- - !binary |-
82
- bGliL3R5cGhvZXVzL3JlcXVlc3QvYmxvY2tfY29ubmVjdGlvbi5yYg==
83
- - !binary |-
84
- bGliL3R5cGhvZXVzL3JlcXVlc3QvY2FsbGJhY2tzLnJi
85
- - !binary |-
86
- bGliL3R5cGhvZXVzL3JlcXVlc3QvbWFyc2hhbC5yYg==
87
- - !binary |-
88
- bGliL3R5cGhvZXVzL3JlcXVlc3QvbWVtb2l6YWJsZS5yYg==
89
- - !binary |-
90
- bGliL3R5cGhvZXVzL3JlcXVlc3Qvb3BlcmF0aW9ucy5yYg==
91
- - !binary |-
92
- bGliL3R5cGhvZXVzL3JlcXVlc3QvcmVzcG9uc2VhYmxlLnJi
93
- - !binary |-
94
- bGliL3R5cGhvZXVzL3JlcXVlc3Qvc3R1YmJhYmxlLnJi
95
- - !binary |-
96
- bGliL3R5cGhvZXVzL3Jlc3BvbnNlL2hlYWRlci5yYg==
97
- - !binary |-
98
- bGliL3R5cGhvZXVzL3Jlc3BvbnNlL2luZm9ybWF0aW9ucy5yYg==
99
- - !binary |-
100
- bGliL3R5cGhvZXVzL3Jlc3BvbnNlL3N0YXR1cy5yYg==
40
+ - lib/typhoeus/adapters/faraday.rb
41
+ - lib/typhoeus/config.rb
42
+ - lib/typhoeus/errors/no_stub.rb
43
+ - lib/typhoeus/errors/typhoeus_error.rb
44
+ - lib/typhoeus/errors.rb
45
+ - lib/typhoeus/expectation.rb
46
+ - lib/typhoeus/hydra/addable.rb
47
+ - lib/typhoeus/hydra/before.rb
48
+ - lib/typhoeus/hydra/block_connection.rb
49
+ - lib/typhoeus/hydra/easy_factory.rb
50
+ - lib/typhoeus/hydra/easy_pool.rb
51
+ - lib/typhoeus/hydra/memoizable.rb
52
+ - lib/typhoeus/hydra/queueable.rb
53
+ - lib/typhoeus/hydra/runnable.rb
54
+ - lib/typhoeus/hydra/stubbable.rb
55
+ - lib/typhoeus/hydra.rb
56
+ - lib/typhoeus/request/actions.rb
57
+ - lib/typhoeus/request/before.rb
58
+ - lib/typhoeus/request/block_connection.rb
59
+ - lib/typhoeus/request/callbacks.rb
60
+ - lib/typhoeus/request/marshal.rb
61
+ - lib/typhoeus/request/memoizable.rb
62
+ - lib/typhoeus/request/operations.rb
63
+ - lib/typhoeus/request/responseable.rb
64
+ - lib/typhoeus/request/stubbable.rb
65
+ - lib/typhoeus/request.rb
66
+ - lib/typhoeus/response/header.rb
67
+ - lib/typhoeus/response/informations.rb
68
+ - lib/typhoeus/response/status.rb
69
+ - lib/typhoeus/response.rb
70
+ - lib/typhoeus/version.rb
71
+ - lib/typhoeus.rb
101
72
  - CHANGELOG.md
102
73
  - Gemfile
103
74
  - LICENSE
@@ -105,31 +76,29 @@ files:
105
76
  - Rakefile
106
77
  homepage: https://github.com/typhoeus/typhoeus
107
78
  licenses: []
108
- post_install_message:
79
+ post_install_message:
109
80
  rdoc_options: []
110
81
  require_paths:
111
82
  - lib
112
83
  required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
113
85
  requirements:
114
86
  - - ! '>='
115
87
  - !ruby/object:Gem::Version
88
+ version: '0'
116
89
  segments:
117
90
  - 0
118
- hash: 2
119
- version: !binary |-
120
- MA==
121
- none: false
91
+ hash: 2893915302486658705
122
92
  required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
123
94
  requirements:
124
95
  - - ! '>='
125
96
  - !ruby/object:Gem::Version
126
97
  version: 1.3.6
127
- none: false
128
98
  requirements: []
129
99
  rubyforge_project: ! '[none]'
130
- rubygems_version: 1.8.24
131
- signing_key:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
132
102
  specification_version: 3
133
103
  summary: Parallel HTTP library on top of libcurl multi.
134
104
  test_files: []
135
- ...