typhoeus 0.5.0.pre → 0.5.0.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG.md +12 -0
  2. data/Gemfile +17 -1
  3. data/README.md +2 -2
  4. data/lib/typhoeus.rb +78 -16
  5. data/lib/typhoeus/config.rb +40 -4
  6. data/lib/typhoeus/errors.rb +9 -0
  7. data/lib/typhoeus/errors/no_stub.rb +12 -0
  8. data/lib/typhoeus/errors/typhoeus_error.rb +8 -0
  9. data/lib/typhoeus/expectation.rb +174 -0
  10. data/lib/typhoeus/hydra.rb +71 -14
  11. data/lib/typhoeus/hydra/before.rb +30 -0
  12. data/lib/typhoeus/hydra/block_connection.rb +35 -0
  13. data/lib/typhoeus/{hydras → hydra}/easy_factory.rb +17 -5
  14. data/lib/typhoeus/{hydras → hydra}/easy_pool.rb +4 -2
  15. data/lib/typhoeus/{hydras → hydra}/memoizable.rb +7 -5
  16. data/lib/typhoeus/{hydras → hydra}/queueable.rb +5 -3
  17. data/lib/typhoeus/{hydras → hydra}/runnable.rb +4 -1
  18. data/lib/typhoeus/hydra/stubbable.rb +26 -0
  19. data/lib/typhoeus/request.rb +117 -29
  20. data/lib/typhoeus/request/actions.rb +125 -0
  21. data/lib/typhoeus/request/before.rb +30 -0
  22. data/lib/typhoeus/request/block_connection.rb +52 -0
  23. data/lib/typhoeus/request/callbacks.rb +98 -0
  24. data/lib/typhoeus/{requests → request}/marshal.rb +1 -1
  25. data/lib/typhoeus/{requests → request}/memoizable.rb +4 -2
  26. data/lib/typhoeus/{requests → request}/operations.rb +25 -5
  27. data/lib/typhoeus/{requests → request}/responseable.rb +1 -1
  28. data/lib/typhoeus/request/stubbable.rb +28 -0
  29. data/lib/typhoeus/response.rb +30 -8
  30. data/lib/typhoeus/{responses → response}/header.rb +15 -11
  31. data/lib/typhoeus/response/informations.rb +205 -0
  32. data/lib/typhoeus/{responses → response}/status.rb +10 -7
  33. data/lib/typhoeus/version.rb +1 -1
  34. metadata +32 -135
  35. data/lib/typhoeus/requests/actions.rb +0 -17
  36. data/lib/typhoeus/requests/callbacks.rb +0 -48
  37. data/lib/typhoeus/responses/informations.rb +0 -43
  38. data/lib/typhoeus/responses/legacy.rb +0 -26
@@ -1,8 +1,10 @@
1
1
  module Typhoeus
2
- module Responses
2
+ class Response
3
3
 
4
4
  # This class represents the response header.
5
5
  # It can be accessed like a hash.
6
+ #
7
+ # @api private
6
8
  class Header < Hash
7
9
  # Create a new header.
8
10
  #
@@ -15,16 +17,6 @@ module Typhoeus
15
17
  parse
16
18
  end
17
19
 
18
- # Returns the raw header or empty string.
19
- #
20
- # @example Return raw header.
21
- # header.raw
22
- #
23
- # @return [ String ] The raw header.
24
- def raw
25
- @raw ||= ''
26
- end
27
-
28
20
  # Parses the raw header.
29
21
  #
30
22
  # @example Parse header.
@@ -45,6 +37,18 @@ module Typhoeus
45
37
  end
46
38
  end
47
39
  end
40
+
41
+ private
42
+
43
+ # Returns the raw header or empty string.
44
+ #
45
+ # @example Return raw header.
46
+ # header.raw
47
+ #
48
+ # @return [ String ] The raw header.
49
+ def raw
50
+ @raw ||= ''
51
+ end
48
52
  end
49
53
  end
50
54
  end
@@ -0,0 +1,205 @@
1
+ module Typhoeus
2
+ class Response
3
+
4
+ # This module contains logic about informations
5
+ # on a response.
6
+ module Informations
7
+
8
+ # Return libcurls return value.
9
+ #
10
+ # @example Get return_code.
11
+ # response.return_code
12
+ #
13
+ # @return [ Symbol ] The return_code.
14
+ def return_code
15
+ options[:return_code]
16
+ end
17
+
18
+ # Return the http response body.
19
+ #
20
+ # @example Get response_body.
21
+ # response.response_body
22
+ #
23
+ # @return [ String ] The response_body.
24
+ def response_body
25
+ options[:response_body] || options[:body]
26
+ end
27
+ alias :body :response_body
28
+
29
+ # Return the http response headers.
30
+ #
31
+ # @example Get response_headers.
32
+ # response.response_headers
33
+ #
34
+ # @return [ String ] The response_headers.
35
+ def response_headers
36
+ options[:response_headers]
37
+ end
38
+
39
+ # Return the last received HTTP, FTP or SMTP response code.
40
+ # The value will be zero if no server response code has
41
+ # been received. Note that a proxy's CONNECT response should
42
+ # be read with http_connect_code and not this.
43
+ #
44
+ # @example Get response_code.
45
+ # response.response_code
46
+ #
47
+ # @return [ Integer ] The response_code.
48
+ def response_code
49
+ options[:response_code] || options[:code]
50
+ end
51
+ alias :code :response_code
52
+
53
+ # Return the available http auth methods.
54
+ # Bitmask indicating the authentication method(s)
55
+ # available.
56
+ #
57
+ # @example Get httpauth_avail.
58
+ # response.httpauth_avail
59
+ #
60
+ # @return [ Integer ] The bitmask.
61
+ def httpauth_avail
62
+ options[:httpauth_avail]
63
+ end
64
+
65
+
66
+ # Return the total time in seconds for the previous
67
+ # transfer, including name resolving, TCP connect etc.
68
+ #
69
+ # @example Get total_time.
70
+ # response.total_time
71
+ #
72
+ # @return [ Float ] The total_time.
73
+ def total_time
74
+ options[:total_time] || options[:time]
75
+ end
76
+ alias :time :total_time
77
+
78
+ # Return the time, in seconds, it took from the start
79
+ # until the first byte is received by libcurl. This
80
+ # includes pretransfer time and also the time the
81
+ # server needs to calculate the result.
82
+ #
83
+ # @example Get starttransfer_time.
84
+ # response.starttransfer_time
85
+ #
86
+ # @return [ Float ] The starttransfer_time.
87
+ def starttransfer_time
88
+ options[:starttransfer_time] || options[:start_transfer_time]
89
+ end
90
+ alias :start_transfer_time :starttransfer_time
91
+
92
+ # Return the time, in seconds, it took from the start
93
+ # until the SSL/SSH connect/handshake to the remote
94
+ # host was completed. This time is most often very near
95
+ # to the pre transfer time, except for cases such as HTTP
96
+ # pippelining where the pretransfer time can be delayed
97
+ # due to waits in line for the pipeline and more.
98
+ #
99
+ # @example Get appconnect_time.
100
+ # response.appconnect_time
101
+ #
102
+ # @return [ Float ] The appconnect_time.
103
+ def appconnect_time
104
+ options[:appconnect_time] || options[:app_connect_time]
105
+ end
106
+ alias :app_connect_time :appconnect_time
107
+
108
+ # Return the time, in seconds, it took from the start
109
+ # until the file transfer is just about to begin. This
110
+ # includes all pre-transfer commands and negotiations
111
+ # that are specific to the particular protocol(s) involved.
112
+ # It does not involve the sending of the protocol-
113
+ # specific request that triggers a transfer.
114
+ #
115
+ # @example Get pretransfer_time.
116
+ # response.pretransfer_time
117
+ #
118
+ # @return [ Float ] The pretransfer_time.
119
+ def pretransfer_time
120
+ options[:pretransfer_time]
121
+ end
122
+
123
+ # Return the time, in seconds, it took from the start
124
+ # until the connect to the remote host (or proxy) was completed.
125
+ #
126
+ # @example Get connect_time.
127
+ # response.connect_time
128
+ #
129
+ # @return [ Float ] The connect_time.
130
+ def connect_time
131
+ options[:connect_time]
132
+ end
133
+
134
+ # Return the time, in seconds, it took from the
135
+ # start until the name resolving was completed.
136
+ #
137
+ # @example Get namelookup_time.
138
+ # response.namelookup_time
139
+ #
140
+ # @return [ Float ] The namelookup_time.
141
+ def namelookup_time
142
+ options[:namelookup_time] || options[:name_lookup_time]
143
+ end
144
+ alias :name_lookup_time :namelookup_time
145
+
146
+ # Return the last used effective url.
147
+ #
148
+ # @example Get effective_url.
149
+ # response.effective_url
150
+ #
151
+ # @return [ String ] The effective_url.
152
+ def effective_url
153
+ options[:effective_url]
154
+ end
155
+
156
+ # Return the string holding the IP address of the most recent
157
+ # connection done with this curl handle. This string
158
+ # may be IPv6 if that's enabled.
159
+ #
160
+ # @example Get primary_ip.
161
+ # response.primary_ip
162
+ #
163
+ # @return [ String ] The primary_ip.
164
+ def primary_ip
165
+ options[:primary_ip]
166
+ end
167
+
168
+ # Return the total number of redirections that were
169
+ # actually followed
170
+ #
171
+ # @example Get redirect_count.
172
+ # response.redirect_count
173
+ #
174
+ # @return [ Integer ] The redirect_count.
175
+ def redirect_count
176
+ options[:redirect_count]
177
+ end
178
+
179
+ # Returns the response header.
180
+ #
181
+ # @example Return headers.
182
+ # response.headers
183
+ #
184
+ # @return [ Typhoeus::Header ] The response header.
185
+ def headers
186
+ return nil if response_headers.nil? && @headers.nil?
187
+ @headers ||= Response::Header.new(response_headers.split("\r\n\r\n").last)
188
+ end
189
+ alias :headers_hash :headers
190
+
191
+ # Return all redirections in between as multiple
192
+ # responses with header.
193
+ #
194
+ # @example Return redirections.
195
+ # response.redirections
196
+ #
197
+ # @return [ Array<Typhoeus::Response> ] The redirections
198
+ def redirections
199
+ return [] unless response_headers
200
+ response_headers.split("\r\n\r\n")[0..-2].map{ |h| Response.new(:response_headers => h) }
201
+ end
202
+ end
203
+ end
204
+ end
205
+
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
- module Responses
2
+ class Response
3
3
 
4
4
  # This module contains logic about the http
5
5
  # status.
@@ -13,6 +13,7 @@ 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?
16
17
 
17
18
  # HTTP servers can choose not to include the explanation to HTTP codes. The RFC
18
19
  # states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4):
@@ -45,7 +46,7 @@ module Typhoeus
45
46
  #
46
47
  # @return [ Boolean ] Return true if successful, false else.
47
48
  def success?
48
- (200..299).include?(response_code)
49
+ return_code == :ok && response_code >= 200 && response_code < 300
49
50
  end
50
51
 
51
52
  # Return wether the response is modified.
@@ -55,22 +56,24 @@ module Typhoeus
55
56
  #
56
57
  # @return [ Boolean ] Return true if modified, false else.
57
58
  def modified?
58
- response_code != 304
59
+ return_code == :ok && response_code != 304
59
60
  end
60
61
 
61
62
  # Return wether the response is timed out.
62
63
  #
63
- # @example Return if the response timed out..
64
- # response.time_out?
64
+ # @example Return if the response timed out.
65
+ # response.timed_out?
65
66
  #
66
67
  # @return [ Boolean ] Return true if timed out, false else.
67
68
  def timed_out?
68
- return_code == 28
69
+ [:operation_timedout, :couldnt_connect].include?(return_code)
69
70
  end
70
71
 
72
+ private
73
+
71
74
  # :nodoc:
72
75
  def first_header_line
73
- @first_header_line ||= response_header.to_s.split("\n").first
76
+ @first_header_line ||= response_headers.to_s.split("\n").first
74
77
  end
75
78
  end
76
79
  end
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.5.0.pre'
4
+ VERSION = '0.5.0.rc'
5
5
  end
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.pre
4
+ version: 0.5.0.rc
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,136 +11,24 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-07-04 00:00:00.000000000 Z
14
+ date: 2012-10-06 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: ethon
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - ~>
21
+ - - '='
22
22
  - !ruby/object:Gem::Version
23
- version: 0.3.0
23
+ version: 0.5.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  none: false
28
28
  requirements:
29
- - - ~>
29
+ - - '='
30
30
  - !ruby/object:Gem::Version
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
31
+ version: 0.5.0
144
32
  description: Like a modern code version of the mythical beast with 100 serpent heads,
145
33
  Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
146
34
  email:
@@ -150,24 +38,33 @@ extensions: []
150
38
  extra_rdoc_files: []
151
39
  files:
152
40
  - 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
+ - lib/typhoeus/hydra/before.rb
46
+ - lib/typhoeus/hydra/block_connection.rb
47
+ - lib/typhoeus/hydra/easy_factory.rb
48
+ - lib/typhoeus/hydra/easy_pool.rb
49
+ - lib/typhoeus/hydra/memoizable.rb
50
+ - lib/typhoeus/hydra/queueable.rb
51
+ - lib/typhoeus/hydra/runnable.rb
52
+ - lib/typhoeus/hydra/stubbable.rb
153
53
  - lib/typhoeus/hydra.rb
154
- - lib/typhoeus/hydras/easy_factory.rb
155
- - lib/typhoeus/hydras/easy_pool.rb
156
- - lib/typhoeus/hydras/memoizable.rb
157
- - lib/typhoeus/hydras/queueable.rb
158
- - lib/typhoeus/hydras/runnable.rb
54
+ - lib/typhoeus/request/actions.rb
55
+ - lib/typhoeus/request/before.rb
56
+ - lib/typhoeus/request/block_connection.rb
57
+ - lib/typhoeus/request/callbacks.rb
58
+ - lib/typhoeus/request/marshal.rb
59
+ - lib/typhoeus/request/memoizable.rb
60
+ - lib/typhoeus/request/operations.rb
61
+ - lib/typhoeus/request/responseable.rb
62
+ - lib/typhoeus/request/stubbable.rb
159
63
  - lib/typhoeus/request.rb
160
- - lib/typhoeus/requests/actions.rb
161
- - lib/typhoeus/requests/callbacks.rb
162
- - lib/typhoeus/requests/marshal.rb
163
- - lib/typhoeus/requests/memoizable.rb
164
- - lib/typhoeus/requests/operations.rb
165
- - lib/typhoeus/requests/responseable.rb
64
+ - lib/typhoeus/response/header.rb
65
+ - lib/typhoeus/response/informations.rb
66
+ - lib/typhoeus/response/status.rb
166
67
  - lib/typhoeus/response.rb
167
- - lib/typhoeus/responses/header.rb
168
- - lib/typhoeus/responses/informations.rb
169
- - lib/typhoeus/responses/legacy.rb
170
- - lib/typhoeus/responses/status.rb
171
68
  - lib/typhoeus/version.rb
172
69
  - lib/typhoeus.rb
173
70
  - CHANGELOG.md
@@ -189,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
86
  version: '0'
190
87
  segments:
191
88
  - 0
192
- hash: -87429564240378902
89
+ hash: -3871520876617813232
193
90
  required_rubygems_version: !ruby/object:Gem::Requirement
194
91
  none: false
195
92
  requirements:
@@ -198,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
95
  version: 1.3.6
199
96
  requirements: []
200
97
  rubyforge_project: ! '[none]'
201
- rubygems_version: 1.8.24
98
+ rubygems_version: 1.8.23
202
99
  signing_key:
203
100
  specification_version: 3
204
101
  summary: Parallel HTTP library on top of libcurl multi.