typhoeus 0.5.0.alpha → 0.5.0.pre
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.
- data/CHANGELOG.md +0 -12
- data/Gemfile +1 -17
- data/lib/typhoeus.rb +1 -32
- data/lib/typhoeus/config.rb +3 -6
- data/lib/typhoeus/hydra.rb +2 -7
- data/lib/typhoeus/hydras/easy_factory.rb +1 -1
- data/lib/typhoeus/hydras/memoizable.rb +3 -3
- data/lib/typhoeus/request.rb +13 -23
- data/lib/typhoeus/requests/actions.rb +6 -90
- data/lib/typhoeus/requests/callbacks.rb +18 -52
- data/lib/typhoeus/requests/memoizable.rb +1 -1
- data/lib/typhoeus/requests/operations.rb +1 -2
- data/lib/typhoeus/response.rb +4 -5
- data/lib/typhoeus/responses/informations.rb +1 -1
- data/lib/typhoeus/responses/legacy.rb +2 -3
- data/lib/typhoeus/responses/status.rb +2 -3
- data/lib/typhoeus/version.rb +1 -1
- metadata +118 -14
- data/lib/typhoeus/errors.rb +0 -9
- data/lib/typhoeus/errors/no_stub.rb +0 -12
- data/lib/typhoeus/errors/typhoeus_error.rb +0 -8
- data/lib/typhoeus/expectation.rb +0 -126
- data/lib/typhoeus/hydras/block_connection.rb +0 -33
- data/lib/typhoeus/hydras/stubbable.rb +0 -27
- data/lib/typhoeus/requests/block_connection.rb +0 -31
- data/lib/typhoeus/requests/stubbable.rb +0 -29
data/CHANGELOG.md
CHANGED
|
@@ -20,7 +20,6 @@ Major Changes:
|
|
|
20
20
|
for a description.
|
|
21
21
|
* The following classes were deleted because they do not seemed to be uesed at all. If that
|
|
22
22
|
turns out to be wrong, they will be restored: `Typhoeus::Filter`, `Typhoeus::Remote`, `Typhoeus::RemoteMethod`, `Typhoeus::RemoteProxyObject`
|
|
23
|
-
* `Typhoeus::Easy` and `Typhoeus::Multi` are now `Ethon::Easy` and `Ethon::Multi`
|
|
24
23
|
|
|
25
24
|
* Request shortcuts: `Typhoeus.get("www.google.de")`
|
|
26
25
|
* Global configuration:
|
|
@@ -33,17 +32,6 @@ end
|
|
|
33
32
|
* No more Response#headers_hash, instead response#header returning the last
|
|
34
33
|
header and response#redirections returning the responses with headers
|
|
35
34
|
generated through redirections
|
|
36
|
-
* Instead of defining the same callbacks on every request, you can define global callbacks:
|
|
37
|
-
|
|
38
|
-
```ruby
|
|
39
|
-
Typhoeus.on_complete { p "yay" }
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
* The stubbing interface changed slightly. You now have the same syntax as for requests:
|
|
43
|
-
|
|
44
|
-
```ruby
|
|
45
|
-
Typhoeus.stub(url, options).and_return(response)
|
|
46
|
-
```
|
|
47
35
|
|
|
48
36
|
Enhancements:
|
|
49
37
|
|
data/Gemfile
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
source :rubygems
|
|
2
|
-
gemspec
|
|
3
|
-
|
|
4
|
-
gem "rake"
|
|
5
|
-
|
|
6
|
-
group :development, :test do
|
|
7
|
-
gem "rspec", "~> 2.11"
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
gem "json"
|
|
11
|
-
|
|
12
|
-
if RUBY_PLATFORM == "java"
|
|
13
|
-
gem "spoon"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
unless ENV["CI"]
|
|
17
|
-
gem "guard-rspec", "~> 0.7"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
3
|
+
gemspec
|
data/lib/typhoeus.rb
CHANGED
|
@@ -2,11 +2,9 @@ require 'digest/sha2'
|
|
|
2
2
|
require 'ethon'
|
|
3
3
|
|
|
4
4
|
require 'typhoeus/config'
|
|
5
|
-
require 'typhoeus/errors'
|
|
6
|
-
require 'typhoeus/expectation'
|
|
7
|
-
require 'typhoeus/hydra'
|
|
8
5
|
require 'typhoeus/request'
|
|
9
6
|
require 'typhoeus/response'
|
|
7
|
+
require 'typhoeus/hydra'
|
|
10
8
|
require 'typhoeus/version'
|
|
11
9
|
|
|
12
10
|
# Typhoeus is a http client library based on Ethon which
|
|
@@ -26,7 +24,6 @@ module Typhoeus
|
|
|
26
24
|
extend self
|
|
27
25
|
extend Hydras::EasyPool
|
|
28
26
|
extend Requests::Actions
|
|
29
|
-
extend Requests::Callbacks::Types
|
|
30
27
|
|
|
31
28
|
# The default typhoeus user agent.
|
|
32
29
|
USER_AGENT = "Typhoeus - https://github.com/typhoeus/typhoeus"
|
|
@@ -42,32 +39,4 @@ module Typhoeus
|
|
|
42
39
|
def configure
|
|
43
40
|
yield Config
|
|
44
41
|
end
|
|
45
|
-
|
|
46
|
-
# Stub out specific request.
|
|
47
|
-
#
|
|
48
|
-
# @example Stub.
|
|
49
|
-
# Typhoeus.stub("www.example.com").and_return(Typhoeus::Response.new)
|
|
50
|
-
#
|
|
51
|
-
# @param [ String ] url The url to stub out.
|
|
52
|
-
# @param [ Hash ] options The options to stub out.
|
|
53
|
-
#
|
|
54
|
-
# @return [ Expection ] The expection.
|
|
55
|
-
def stub(url, options = {})
|
|
56
|
-
expectation = Expectation.all.find{ |e| e.url == url && e.options == options }
|
|
57
|
-
return expectation if expectation
|
|
58
|
-
|
|
59
|
-
Expectation.new(url, options).tap do |new_expectation|
|
|
60
|
-
Expectation.all << new_expectation
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# Execute given block as if block connection is turned off.
|
|
65
|
-
#
|
|
66
|
-
# @param [ Block ] block The block to execute.
|
|
67
|
-
def with_connection
|
|
68
|
-
old = Config.block_connection
|
|
69
|
-
Config.block_connection = false
|
|
70
|
-
yield if block_given?
|
|
71
|
-
Config.block_connection = old
|
|
72
|
-
end
|
|
73
42
|
end
|
data/lib/typhoeus/config.rb
CHANGED
|
@@ -2,13 +2,10 @@ module Typhoeus
|
|
|
2
2
|
|
|
3
3
|
# The Typhoeus configuration used to set global
|
|
4
4
|
# options. Available options:
|
|
5
|
-
# *
|
|
6
|
-
#
|
|
7
|
-
# do a real request.
|
|
8
|
-
# * verbose: show curls debug out
|
|
9
|
-
# * memoize: memoize GET requests.
|
|
5
|
+
# * verbose
|
|
6
|
+
# * memoize.
|
|
10
7
|
module Config
|
|
11
8
|
extend self
|
|
12
|
-
attr_accessor :
|
|
9
|
+
attr_accessor :verbose, :memoize
|
|
13
10
|
end
|
|
14
11
|
end
|
data/lib/typhoeus/hydra.rb
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
require 'typhoeus/hydras/block_connection'
|
|
2
1
|
require 'typhoeus/hydras/easy_factory'
|
|
3
2
|
require 'typhoeus/hydras/easy_pool'
|
|
4
3
|
require 'typhoeus/hydras/memoizable'
|
|
5
4
|
require 'typhoeus/hydras/queueable'
|
|
6
5
|
require 'typhoeus/hydras/runnable'
|
|
7
|
-
require 'typhoeus/hydras/stubbable'
|
|
8
6
|
|
|
9
7
|
module Typhoeus
|
|
10
8
|
|
|
11
9
|
# Hydra manages making parallel HTTP requests. This
|
|
12
|
-
# is
|
|
13
|
-
#
|
|
14
|
-
# The benefits are that you don't have to worry running
|
|
10
|
+
# is archived by using libcurls multi interface. The
|
|
11
|
+
# benefits are that you don't have to worry running
|
|
15
12
|
# the requests by yourself.
|
|
16
13
|
class Hydra
|
|
17
14
|
include Hydras::EasyPool
|
|
18
15
|
include Hydras::Queueable
|
|
19
16
|
include Hydras::Runnable
|
|
20
17
|
include Hydras::Memoizable
|
|
21
|
-
include Hydras::BlockConnection
|
|
22
|
-
include Hydras::Stubbable
|
|
23
18
|
|
|
24
19
|
attr_reader :max_concurrency, :multi
|
|
25
20
|
|
|
@@ -4,7 +4,7 @@ module Typhoeus
|
|
|
4
4
|
# This module handles the GET request memoization
|
|
5
5
|
# on the hydra side. Memoization needs to be turned
|
|
6
6
|
# on:
|
|
7
|
-
# Typhoeus.
|
|
7
|
+
# Typhoeus.configre do |config|
|
|
8
8
|
# config.memoize = true
|
|
9
9
|
# end
|
|
10
10
|
module Memoizable
|
|
@@ -33,13 +33,13 @@ module Typhoeus
|
|
|
33
33
|
def queue(request)
|
|
34
34
|
if request.memoizable? && memory.has_key?(request)
|
|
35
35
|
request.instance_variable_set(:@response, memory[request])
|
|
36
|
-
request.
|
|
36
|
+
request.complete
|
|
37
37
|
else
|
|
38
38
|
super
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
# Overrides run to
|
|
42
|
+
# Overrides run to clear the memory is cleared after
|
|
43
43
|
# each run.
|
|
44
44
|
#
|
|
45
45
|
# @example Run hydra.
|
data/lib/typhoeus/request.rb
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
|
-
require 'typhoeus/requests/actions'
|
|
2
|
-
require 'typhoeus/requests/block_connection'
|
|
3
1
|
require 'typhoeus/requests/callbacks'
|
|
4
|
-
require 'typhoeus/requests/
|
|
5
|
-
require 'typhoeus/requests/memoizable'
|
|
2
|
+
require 'typhoeus/requests/actions'
|
|
6
3
|
require 'typhoeus/requests/operations'
|
|
4
|
+
require 'typhoeus/requests/marshal'
|
|
7
5
|
require 'typhoeus/requests/responseable'
|
|
8
|
-
require 'typhoeus/requests/
|
|
6
|
+
require 'typhoeus/requests/memoizable'
|
|
9
7
|
|
|
10
8
|
module Typhoeus
|
|
11
9
|
|
|
12
10
|
# This class represents a request.
|
|
13
11
|
class Request
|
|
14
|
-
extend Requests::Actions
|
|
15
|
-
include Requests::Callbacks::Types
|
|
16
12
|
include Requests::Callbacks
|
|
17
13
|
include Requests::Marshal
|
|
18
14
|
include Requests::Operations
|
|
15
|
+
extend Requests::Actions
|
|
19
16
|
include Requests::Responseable
|
|
20
17
|
include Requests::Memoizable
|
|
21
|
-
include Requests::BlockConnection
|
|
22
|
-
include Requests::Stubbable
|
|
23
18
|
|
|
24
|
-
attr_accessor :options, :url, :hydra
|
|
19
|
+
attr_accessor :options, :url, :hydra
|
|
25
20
|
|
|
26
21
|
# Create a new request.
|
|
27
22
|
#
|
|
@@ -34,10 +29,14 @@ module Typhoeus
|
|
|
34
29
|
# #return [ Request ] The new request.
|
|
35
30
|
def initialize(url, options = {})
|
|
36
31
|
@url = url
|
|
37
|
-
@original_options = options
|
|
38
32
|
@options = options.dup
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
if @options[:headers]
|
|
35
|
+
@options[:headers] = {'User-Agent' => Typhoeus::USER_AGENT}.merge(options[:headers])
|
|
36
|
+
else
|
|
37
|
+
@options[:headers] = {'User-Agent' => Typhoeus::USER_AGENT}
|
|
38
|
+
end
|
|
39
|
+
@options[:verbose] = Typhoeus::Config.verbose unless @options[:verbose]
|
|
41
40
|
end
|
|
42
41
|
|
|
43
42
|
# Returns wether other is equal to self.
|
|
@@ -65,8 +64,8 @@ module Typhoeus
|
|
|
65
64
|
|
|
66
65
|
# Checks if two hashes are equal or not, discarding first-level hash order
|
|
67
66
|
#
|
|
68
|
-
# @param [ Hash ]
|
|
69
|
-
# @param [ Hash ]
|
|
67
|
+
# @param [ Hash ] hash
|
|
68
|
+
# @param [ Hash ] other hash to check for equality
|
|
70
69
|
#
|
|
71
70
|
# @return [ Boolean ] Returns true if hashes have same values for same keys and same length,
|
|
72
71
|
# even if the keys are given in a different order.
|
|
@@ -78,14 +77,5 @@ module Typhoeus
|
|
|
78
77
|
end
|
|
79
78
|
end
|
|
80
79
|
|
|
81
|
-
# Sets default header and verbose when turned on.
|
|
82
|
-
def set_defaults
|
|
83
|
-
if @options[:headers]
|
|
84
|
-
@options[:headers] = {'User-Agent' => Typhoeus::USER_AGENT}.merge(options[:headers])
|
|
85
|
-
else
|
|
86
|
-
@options[:headers] = {'User-Agent' => Typhoeus::USER_AGENT}
|
|
87
|
-
end
|
|
88
|
-
@options[:verbose] = Typhoeus::Config.verbose if @options[:verbose].nil? && !Typhoeus::Config.verbose.nil?
|
|
89
|
-
end
|
|
90
80
|
end
|
|
91
81
|
end
|
|
@@ -5,96 +5,12 @@ module Typhoeus
|
|
|
5
5
|
# http methods. Like
|
|
6
6
|
# Typhoeus.get("www.example.com")
|
|
7
7
|
module Actions
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# @param [ String ] url The url to request.
|
|
15
|
-
# @param [ options ] options The options.
|
|
16
|
-
#
|
|
17
|
-
# @return [ Response ] The response.
|
|
18
|
-
def get(url, options = {})
|
|
19
|
-
Request.run(url, options.merge(:method => :get))
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# Make a post request.
|
|
23
|
-
#
|
|
24
|
-
# @example Make post request.
|
|
25
|
-
# Typhoeus.post("www.example.com")
|
|
26
|
-
#
|
|
27
|
-
# @param [ String ] url The url to request.
|
|
28
|
-
# @param [ options ] options The options.
|
|
29
|
-
#
|
|
30
|
-
# @return [ Response ] The response.
|
|
31
|
-
def post(url, options = {})
|
|
32
|
-
Request.run(url, options.merge(:method => :post))
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Make a put request.
|
|
36
|
-
#
|
|
37
|
-
# @example Make put request.
|
|
38
|
-
# Typhoeus.put("www.example.com")
|
|
39
|
-
#
|
|
40
|
-
# @param [ String ] url The url to request.
|
|
41
|
-
# @param [ options ] options The options.
|
|
42
|
-
#
|
|
43
|
-
# @return [ Response ] The response.
|
|
44
|
-
def put(url, options = {})
|
|
45
|
-
Request.run(url, options.merge(:method => :put))
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Make a delete request.
|
|
49
|
-
#
|
|
50
|
-
# @example Make delete request.
|
|
51
|
-
# Typhoeus.delete("www.example.com")
|
|
52
|
-
#
|
|
53
|
-
# @param [ String ] url The url to request.
|
|
54
|
-
# @param [ options ] options The options.
|
|
55
|
-
#
|
|
56
|
-
# @return [ Response ] The response.
|
|
57
|
-
def delete(url, options = {})
|
|
58
|
-
Request.run(url, options.merge(:method => :delete))
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
# Make a head request.
|
|
62
|
-
#
|
|
63
|
-
# @example Make head request.
|
|
64
|
-
# Typhoeus.head("www.example.com")
|
|
65
|
-
#
|
|
66
|
-
# @param [ String ] url The url to request.
|
|
67
|
-
# @param [ options ] options The options.
|
|
68
|
-
#
|
|
69
|
-
# @return [ Response ] The response.
|
|
70
|
-
def head(url, options = {})
|
|
71
|
-
Request.run(url, options.merge(:method => :head))
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# Make a patch request.
|
|
75
|
-
#
|
|
76
|
-
# @example Make patch request.
|
|
77
|
-
# Typhoeus.patch("www.example.com")
|
|
78
|
-
#
|
|
79
|
-
# @param [ String ] url The url to request.
|
|
80
|
-
# @param [ options ] options The options.
|
|
81
|
-
#
|
|
82
|
-
# @return [ Response ] The response.
|
|
83
|
-
def patch(url, options = {})
|
|
84
|
-
Request.run(url, options.merge(:method => :patch))
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Make a options request.
|
|
88
|
-
#
|
|
89
|
-
# @example Make options request.
|
|
90
|
-
# Typhoeus.options("www.example.com")
|
|
91
|
-
#
|
|
92
|
-
# @param [ String ] url The url to request.
|
|
93
|
-
# @param [ options ] options The options.
|
|
94
|
-
#
|
|
95
|
-
# @return [ Response ] The response.
|
|
96
|
-
def options(url, options = {})
|
|
97
|
-
Request.run(url, options.merge(:method => :options))
|
|
8
|
+
[:get, :post, :put, :delete, :head, :patch, :options].each do |name|
|
|
9
|
+
define_method(name) do |*args|
|
|
10
|
+
url = args[0]
|
|
11
|
+
options = args.fetch(1, {})
|
|
12
|
+
Request.run(url, options.merge(:method => name))
|
|
13
|
+
end
|
|
98
14
|
end
|
|
99
15
|
end
|
|
100
16
|
end
|
|
@@ -9,7 +9,7 @@ module Typhoeus
|
|
|
9
9
|
#
|
|
10
10
|
# request.on_complete { p 1 }
|
|
11
11
|
# request.on_complete { p 2 }
|
|
12
|
-
# request.
|
|
12
|
+
# request.complete
|
|
13
13
|
# #=> 1
|
|
14
14
|
# #=> 2
|
|
15
15
|
#
|
|
@@ -18,64 +18,30 @@ module Typhoeus
|
|
|
18
18
|
# request.on_complete { p 1 }
|
|
19
19
|
# request.on_complete { p 2 }
|
|
20
20
|
# request.on_complete.clear
|
|
21
|
-
# request.
|
|
21
|
+
# request.on_complete
|
|
22
22
|
# #=> []
|
|
23
23
|
module Callbacks
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@on_complete
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# Set on_success callback.
|
|
39
|
-
#
|
|
40
|
-
# @example Set on_success.
|
|
41
|
-
# request.on_success { p "yay" }
|
|
42
|
-
#
|
|
43
|
-
# @param [ Block ] block The block to execute.
|
|
44
|
-
def on_success(&block)
|
|
45
|
-
@on_success ||= []
|
|
46
|
-
@on_success << block if block_given?
|
|
47
|
-
@on_success
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Set on_failure callback.
|
|
51
|
-
#
|
|
52
|
-
# @example Set on_failure.
|
|
53
|
-
# request.on_failure { p "yay" }
|
|
54
|
-
#
|
|
55
|
-
# @param [ Block ] block The block to execute.
|
|
56
|
-
def on_failure(&block)
|
|
57
|
-
@on_failure ||= []
|
|
58
|
-
@on_failure << block if block_given?
|
|
59
|
-
@on_failure
|
|
60
|
-
end
|
|
25
|
+
# Set on_complete callback.
|
|
26
|
+
#
|
|
27
|
+
# @example Set on_complete.
|
|
28
|
+
# request.on_complete { p "yay" }
|
|
29
|
+
#
|
|
30
|
+
# @param [ Block ] block The block to execute.
|
|
31
|
+
def on_complete(&block)
|
|
32
|
+
@on_complete ||= []
|
|
33
|
+
@on_complete << block if block_given?
|
|
34
|
+
@on_complete
|
|
61
35
|
end
|
|
62
36
|
|
|
63
|
-
# Execute
|
|
64
|
-
# include in every case on_complete, on_success if
|
|
65
|
-
# successful and on_failure if not.
|
|
37
|
+
# Execute on_complete callbacks.
|
|
66
38
|
#
|
|
67
|
-
# @example Execute
|
|
68
|
-
# request.
|
|
69
|
-
def
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if response && response.success?
|
|
73
|
-
callbacks += Typhoeus.on_success + on_success
|
|
74
|
-
elsif response
|
|
75
|
-
callbacks += Typhoeus.on_failure + on_failure
|
|
39
|
+
# @example Execute on_completes.
|
|
40
|
+
# request.complete
|
|
41
|
+
def complete
|
|
42
|
+
if defined?(@on_complete)
|
|
43
|
+
@on_complete.map{ |callback| callback.call(self) }
|
|
76
44
|
end
|
|
77
|
-
|
|
78
|
-
callbacks.map{ |callback| callback.call(self.response) }
|
|
79
45
|
end
|
|
80
46
|
end
|
|
81
47
|
end
|
data/lib/typhoeus/response.rb
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
require 'typhoeus/responses/header'
|
|
2
|
-
require 'typhoeus/responses/informations'
|
|
3
1
|
require 'typhoeus/responses/legacy'
|
|
2
|
+
require 'typhoeus/responses/informations'
|
|
4
3
|
require 'typhoeus/responses/status'
|
|
4
|
+
require 'typhoeus/responses/header'
|
|
5
5
|
|
|
6
6
|
module Typhoeus
|
|
7
7
|
|
|
8
8
|
# This class respresents the response.
|
|
9
9
|
class Response
|
|
10
|
+
include Responses::Status
|
|
10
11
|
include Responses::Informations
|
|
11
12
|
include Responses::Legacy
|
|
12
|
-
include Responses::Status
|
|
13
13
|
|
|
14
|
-
attr_accessor :request, :options
|
|
14
|
+
attr_accessor :request, :options
|
|
15
15
|
|
|
16
16
|
# Create a new response.
|
|
17
17
|
#
|
|
@@ -23,7 +23,6 @@ module Typhoeus
|
|
|
23
23
|
# @return [ Response ] The new response.
|
|
24
24
|
def initialize(options = {})
|
|
25
25
|
@options = options
|
|
26
|
-
@header = options[:header]
|
|
27
26
|
end
|
|
28
27
|
end
|
|
29
28
|
end
|
|
@@ -13,13 +13,12 @@ module Typhoeus
|
|
|
13
13
|
:time => :total_time,
|
|
14
14
|
:app_connect_time => :appconnect_time,
|
|
15
15
|
:start_transfer_time => :starttransfer_time,
|
|
16
|
-
:name_lookup_time => :namelookup_time
|
|
17
|
-
:headers_hash => :header
|
|
16
|
+
:name_lookup_time => :namelookup_time
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
MAPPING.each do |old, new|
|
|
21
20
|
define_method(old) do
|
|
22
|
-
options[new]
|
|
21
|
+
options[new]
|
|
23
22
|
end
|
|
24
23
|
end
|
|
25
24
|
end
|
|
@@ -13,7 +13,6 @@ module Typhoeus
|
|
|
13
13
|
# @return [ String ] The message.
|
|
14
14
|
def status_message
|
|
15
15
|
return @status_message if defined?(@status_message) && @status_message
|
|
16
|
-
return options[:status_message] unless options[:status_message].nil?
|
|
17
16
|
|
|
18
17
|
# HTTP servers can choose not to include the explanation to HTTP codes. The RFC
|
|
19
18
|
# states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4):
|
|
@@ -46,7 +45,7 @@ module Typhoeus
|
|
|
46
45
|
#
|
|
47
46
|
# @return [ Boolean ] Return true if successful, false else.
|
|
48
47
|
def success?
|
|
49
|
-
|
|
48
|
+
(200..299).include?(response_code)
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
# Return wether the response is modified.
|
|
@@ -56,7 +55,7 @@ module Typhoeus
|
|
|
56
55
|
#
|
|
57
56
|
# @return [ Boolean ] Return true if modified, false else.
|
|
58
57
|
def modified?
|
|
59
|
-
|
|
58
|
+
response_code != 304
|
|
60
59
|
end
|
|
61
60
|
|
|
62
61
|
# Return wether the response is timed out.
|
data/lib/typhoeus/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: typhoeus
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.0.
|
|
4
|
+
version: 0.5.0.pre
|
|
5
5
|
prerelease: 6
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2012-
|
|
14
|
+
date: 2012-07-04 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: ethon
|
|
@@ -20,7 +20,7 @@ dependencies:
|
|
|
20
20
|
requirements:
|
|
21
21
|
- - ~>
|
|
22
22
|
- !ruby/object:Gem::Version
|
|
23
|
-
version: 0.
|
|
23
|
+
version: 0.3.0
|
|
24
24
|
type: :runtime
|
|
25
25
|
prerelease: false
|
|
26
26
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -28,7 +28,119 @@ dependencies:
|
|
|
28
28
|
requirements:
|
|
29
29
|
- - ~>
|
|
30
30
|
- !ruby/object:Gem::Version
|
|
31
|
-
version: 0.
|
|
31
|
+
version: 0.3.0
|
|
32
|
+
- !ruby/object:Gem::Dependency
|
|
33
|
+
name: sinatra
|
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
|
35
|
+
none: false
|
|
36
|
+
requirements:
|
|
37
|
+
- - ~>
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '1.3'
|
|
40
|
+
type: :development
|
|
41
|
+
prerelease: false
|
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
43
|
+
none: false
|
|
44
|
+
requirements:
|
|
45
|
+
- - ~>
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1.3'
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: json
|
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ~>
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '1.7'
|
|
56
|
+
type: :development
|
|
57
|
+
prerelease: false
|
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
59
|
+
none: false
|
|
60
|
+
requirements:
|
|
61
|
+
- - ~>
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '1.7'
|
|
64
|
+
- !ruby/object:Gem::Dependency
|
|
65
|
+
name: rake
|
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
|
67
|
+
none: false
|
|
68
|
+
requirements:
|
|
69
|
+
- - ~>
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '0.9'
|
|
72
|
+
type: :development
|
|
73
|
+
prerelease: false
|
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
75
|
+
none: false
|
|
76
|
+
requirements:
|
|
77
|
+
- - ~>
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0.9'
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: mocha
|
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
|
83
|
+
none: false
|
|
84
|
+
requirements:
|
|
85
|
+
- - ~>
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 0.11.4
|
|
88
|
+
type: :development
|
|
89
|
+
prerelease: false
|
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
91
|
+
none: false
|
|
92
|
+
requirements:
|
|
93
|
+
- - ~>
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: 0.11.4
|
|
96
|
+
- !ruby/object:Gem::Dependency
|
|
97
|
+
name: rspec
|
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
|
99
|
+
none: false
|
|
100
|
+
requirements:
|
|
101
|
+
- - ~>
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '2.10'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
none: false
|
|
108
|
+
requirements:
|
|
109
|
+
- - ~>
|
|
110
|
+
- !ruby/object:Gem::Version
|
|
111
|
+
version: '2.10'
|
|
112
|
+
- !ruby/object:Gem::Dependency
|
|
113
|
+
name: guard-rspec
|
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
|
115
|
+
none: false
|
|
116
|
+
requirements:
|
|
117
|
+
- - ~>
|
|
118
|
+
- !ruby/object:Gem::Version
|
|
119
|
+
version: 1.1.0
|
|
120
|
+
type: :development
|
|
121
|
+
prerelease: false
|
|
122
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
123
|
+
none: false
|
|
124
|
+
requirements:
|
|
125
|
+
- - ~>
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: 1.1.0
|
|
128
|
+
- !ruby/object:Gem::Dependency
|
|
129
|
+
name: simplecov
|
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
|
131
|
+
none: false
|
|
132
|
+
requirements:
|
|
133
|
+
- - ~>
|
|
134
|
+
- !ruby/object:Gem::Version
|
|
135
|
+
version: 0.5.3
|
|
136
|
+
type: :development
|
|
137
|
+
prerelease: false
|
|
138
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
139
|
+
none: false
|
|
140
|
+
requirements:
|
|
141
|
+
- - ~>
|
|
142
|
+
- !ruby/object:Gem::Version
|
|
143
|
+
version: 0.5.3
|
|
32
144
|
description: Like a modern code version of the mythical beast with 100 serpent heads,
|
|
33
145
|
Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
|
|
34
146
|
email:
|
|
@@ -38,27 +150,19 @@ extensions: []
|
|
|
38
150
|
extra_rdoc_files: []
|
|
39
151
|
files:
|
|
40
152
|
- lib/typhoeus/config.rb
|
|
41
|
-
- lib/typhoeus/errors/no_stub.rb
|
|
42
|
-
- lib/typhoeus/errors/typhoeus_error.rb
|
|
43
|
-
- lib/typhoeus/errors.rb
|
|
44
|
-
- lib/typhoeus/expectation.rb
|
|
45
153
|
- lib/typhoeus/hydra.rb
|
|
46
|
-
- lib/typhoeus/hydras/block_connection.rb
|
|
47
154
|
- lib/typhoeus/hydras/easy_factory.rb
|
|
48
155
|
- lib/typhoeus/hydras/easy_pool.rb
|
|
49
156
|
- lib/typhoeus/hydras/memoizable.rb
|
|
50
157
|
- lib/typhoeus/hydras/queueable.rb
|
|
51
158
|
- lib/typhoeus/hydras/runnable.rb
|
|
52
|
-
- lib/typhoeus/hydras/stubbable.rb
|
|
53
159
|
- lib/typhoeus/request.rb
|
|
54
160
|
- lib/typhoeus/requests/actions.rb
|
|
55
|
-
- lib/typhoeus/requests/block_connection.rb
|
|
56
161
|
- lib/typhoeus/requests/callbacks.rb
|
|
57
162
|
- lib/typhoeus/requests/marshal.rb
|
|
58
163
|
- lib/typhoeus/requests/memoizable.rb
|
|
59
164
|
- lib/typhoeus/requests/operations.rb
|
|
60
165
|
- lib/typhoeus/requests/responseable.rb
|
|
61
|
-
- lib/typhoeus/requests/stubbable.rb
|
|
62
166
|
- lib/typhoeus/response.rb
|
|
63
167
|
- lib/typhoeus/responses/header.rb
|
|
64
168
|
- lib/typhoeus/responses/informations.rb
|
|
@@ -85,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
85
189
|
version: '0'
|
|
86
190
|
segments:
|
|
87
191
|
- 0
|
|
88
|
-
hash:
|
|
192
|
+
hash: -87429564240378902
|
|
89
193
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
194
|
none: false
|
|
91
195
|
requirements:
|
|
@@ -94,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
198
|
version: 1.3.6
|
|
95
199
|
requirements: []
|
|
96
200
|
rubyforge_project: ! '[none]'
|
|
97
|
-
rubygems_version: 1.8.
|
|
201
|
+
rubygems_version: 1.8.24
|
|
98
202
|
signing_key:
|
|
99
203
|
specification_version: 3
|
|
100
204
|
summary: Parallel HTTP library on top of libcurl multi.
|
data/lib/typhoeus/errors.rb
DELETED
data/lib/typhoeus/expectation.rb
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
|
|
3
|
-
# This class represents an expectation. It is part
|
|
4
|
-
# of the stubbing mechanism. An expectation contains
|
|
5
|
-
# an url and options, like a request. They were compared
|
|
6
|
-
# to the request url and options in order to evaluate
|
|
7
|
-
# wether they match. If thats the case, the attached
|
|
8
|
-
# responses were returned one by one.
|
|
9
|
-
class Expectation
|
|
10
|
-
attr_reader :url, :options
|
|
11
|
-
|
|
12
|
-
class << self
|
|
13
|
-
|
|
14
|
-
# Returns all expectations.
|
|
15
|
-
#
|
|
16
|
-
# @example Return expectations.
|
|
17
|
-
# Typhoeus::Expectation.all
|
|
18
|
-
#
|
|
19
|
-
# @return [ Array ] The expectations.
|
|
20
|
-
def all
|
|
21
|
-
@expectations ||= []
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# Clears expectations.
|
|
25
|
-
#
|
|
26
|
-
# @example Clear expectations.
|
|
27
|
-
# Typhoeus:;Expectation.clear
|
|
28
|
-
def clear
|
|
29
|
-
all.clear
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# Returns expecation matching the provided
|
|
33
|
-
# request.
|
|
34
|
-
#
|
|
35
|
-
# @example Find expectation.
|
|
36
|
-
# Typhoeus::Expectation.find_by(request)
|
|
37
|
-
#
|
|
38
|
-
# @return [ Expectation ] The matching expectation.
|
|
39
|
-
def find_by(request)
|
|
40
|
-
all.find do |expectation|
|
|
41
|
-
expectation.matches?(request)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Creates an expactation.
|
|
47
|
-
#
|
|
48
|
-
# @example Create expactation.
|
|
49
|
-
# Typhoeus::Expectation.new(url)
|
|
50
|
-
#
|
|
51
|
-
# @return [ Expectation ] The created expactation.
|
|
52
|
-
def initialize(url, options = {})
|
|
53
|
-
@url = url
|
|
54
|
-
@options = options
|
|
55
|
-
@response_counter = 0
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# Specify what should be returned,
|
|
59
|
-
# when this expactation is hit.
|
|
60
|
-
#
|
|
61
|
-
# @example Add response.
|
|
62
|
-
# expectation.and_return(response)
|
|
63
|
-
def and_return(response)
|
|
64
|
-
responses << response
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Checks wether this expectation matches
|
|
68
|
-
# the provided request.
|
|
69
|
-
#
|
|
70
|
-
# @example Check if request matches.
|
|
71
|
-
# expectation.matches? request
|
|
72
|
-
#
|
|
73
|
-
# @param [ Request ] The request to check.
|
|
74
|
-
#
|
|
75
|
-
# @return [ Boolean ] True when matches, else false.
|
|
76
|
-
def matches?(request)
|
|
77
|
-
url_match?(request.url) &&
|
|
78
|
-
(options ? options.all?{ |k,v| request.original_options[k] == v } : true)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# Return canned responses.
|
|
82
|
-
#
|
|
83
|
-
# @example Return responses.
|
|
84
|
-
# expectation.responses
|
|
85
|
-
#
|
|
86
|
-
# @return [ Array ] The responses.
|
|
87
|
-
def responses
|
|
88
|
-
@responses ||= []
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# Return the response. When there are
|
|
92
|
-
# multiple responses, they were returned one
|
|
93
|
-
# by one.
|
|
94
|
-
#
|
|
95
|
-
# @example Return response.
|
|
96
|
-
# expectation.response
|
|
97
|
-
#
|
|
98
|
-
# @return [ Response ] The response.
|
|
99
|
-
def response
|
|
100
|
-
response = responses.fetch(@response_counter, responses.last)
|
|
101
|
-
@response_counter += 1
|
|
102
|
-
response
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
private
|
|
106
|
-
|
|
107
|
-
# Check wether the url matches the request url.
|
|
108
|
-
# The url can be a string, regex or nil. String and
|
|
109
|
-
# regexp were checked, nil is always true. Else false.
|
|
110
|
-
#
|
|
111
|
-
# Nil serves as a placeholder in case you want to match
|
|
112
|
-
# all urls.
|
|
113
|
-
def url_match?(request_url)
|
|
114
|
-
case url
|
|
115
|
-
when String
|
|
116
|
-
url == request_url
|
|
117
|
-
when Regexp
|
|
118
|
-
!!request_url.match(url)
|
|
119
|
-
when nil
|
|
120
|
-
true
|
|
121
|
-
else
|
|
122
|
-
false
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end
|
|
126
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
module Hydras
|
|
3
|
-
|
|
4
|
-
# This module handles the blocked connection request mode on
|
|
5
|
-
# the hydra side, where only stubbed requests
|
|
6
|
-
# are allowed.
|
|
7
|
-
# Connection blocking needs to be turned on:
|
|
8
|
-
# Typhoeus.configure do |config|
|
|
9
|
-
# config.block_connection = true
|
|
10
|
-
# end
|
|
11
|
-
#
|
|
12
|
-
# When trying to do real requests a NoStub error
|
|
13
|
-
# is raised.
|
|
14
|
-
module BlockConnection
|
|
15
|
-
|
|
16
|
-
# Overrides queue in order to check before if block connection
|
|
17
|
-
# is turned on. If thats the case a NoStub error is
|
|
18
|
-
# raised.
|
|
19
|
-
#
|
|
20
|
-
# @example Queue the request.
|
|
21
|
-
# hydra.queue(request)
|
|
22
|
-
#
|
|
23
|
-
# @param [ Request ] request The request to enqueue.
|
|
24
|
-
def queue(request)
|
|
25
|
-
if Typhoeus::Config.block_connection
|
|
26
|
-
raise Typhoeus::Errors::NoStub.new(request)
|
|
27
|
-
else
|
|
28
|
-
super
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
module Hydras
|
|
3
|
-
|
|
4
|
-
# This module handles stubbing on the hydra side.
|
|
5
|
-
# It plays well with the block_connection configuration,
|
|
6
|
-
# which raises when you make a request which is not stubbed.
|
|
7
|
-
module Stubbable
|
|
8
|
-
|
|
9
|
-
# Override queue in order to check for matching expecations.
|
|
10
|
-
# When an expecation is found, super is not called. Instead a
|
|
11
|
-
# canned response is assigned to the request.
|
|
12
|
-
#
|
|
13
|
-
# @example Queue the request.
|
|
14
|
-
# hydra.queue(request)
|
|
15
|
-
def queue(request)
|
|
16
|
-
if expectation = Expectation.find_by(request)
|
|
17
|
-
request.response = expectation.response
|
|
18
|
-
request.response.mock = true
|
|
19
|
-
request.execute_callbacks
|
|
20
|
-
request.response
|
|
21
|
-
else
|
|
22
|
-
super
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
module Requests
|
|
3
|
-
|
|
4
|
-
# This module handles the blocked connection request mode on
|
|
5
|
-
# the request side, where only stubbed requests
|
|
6
|
-
# are allowed.
|
|
7
|
-
# Connection blocking needs to be turned on:
|
|
8
|
-
# Typhoeus.configure do |config|
|
|
9
|
-
# config.block_connection = true
|
|
10
|
-
# end
|
|
11
|
-
#
|
|
12
|
-
# When trying to do real requests a NoStub error
|
|
13
|
-
# is raised.
|
|
14
|
-
module BlockConnection
|
|
15
|
-
|
|
16
|
-
# Overrides run in order to check before if block connection
|
|
17
|
-
# is turned on. If thats the case a NoStub error is
|
|
18
|
-
# raised.
|
|
19
|
-
#
|
|
20
|
-
# @example Run request.
|
|
21
|
-
# request.run
|
|
22
|
-
def run
|
|
23
|
-
if Typhoeus::Config.block_connection
|
|
24
|
-
raise Typhoeus::Errors::NoStub.new(self)
|
|
25
|
-
else
|
|
26
|
-
super
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
module Typhoeus
|
|
2
|
-
module Requests
|
|
3
|
-
|
|
4
|
-
# This module handles stubbing on the request side.
|
|
5
|
-
# It plays well with the block_connection configuration,
|
|
6
|
-
# which raises when you make a request which is not stubbed.
|
|
7
|
-
module Stubbable
|
|
8
|
-
|
|
9
|
-
# Override run in order to check for matching expecations.
|
|
10
|
-
# When an expecation is found, super is not called. Instead a
|
|
11
|
-
# canned response is assigned to the request.
|
|
12
|
-
#
|
|
13
|
-
# @example Run the request.
|
|
14
|
-
# request.run
|
|
15
|
-
#
|
|
16
|
-
# @return [ Response ] The response.
|
|
17
|
-
def run
|
|
18
|
-
if expectation = Expectation.find_by(self)
|
|
19
|
-
@response = expectation.response
|
|
20
|
-
@response.mock = true
|
|
21
|
-
execute_callbacks
|
|
22
|
-
@response
|
|
23
|
-
else
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|