typhoeus 0.5.0.pre → 0.5.0.rc

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.
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,17 +0,0 @@
1
- module Typhoeus
2
- module Requests # :nodoc:
3
-
4
- # Module containing logic about shortcuts to
5
- # http methods. Like
6
- # Typhoeus.get("www.example.com")
7
- module Actions
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
14
- end
15
- end
16
- end
17
- end
@@ -1,48 +0,0 @@
1
- module Typhoeus
2
- module Requests
3
-
4
- # This module contains the logic for the response callbacks.
5
- # The on_complete callback is the only one at the moment.
6
- #
7
- # You can set multiple callbacks, which are then executed
8
- # in the same order.
9
- #
10
- # request.on_complete { p 1 }
11
- # request.on_complete { p 2 }
12
- # request.complete
13
- # #=> 1
14
- # #=> 2
15
- #
16
- # You can clear the callbacks:
17
- #
18
- # request.on_complete { p 1 }
19
- # request.on_complete { p 2 }
20
- # request.on_complete.clear
21
- # request.on_complete
22
- # #=> []
23
- module Callbacks
24
-
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
35
- end
36
-
37
- # Execute on_complete callbacks.
38
- #
39
- # @example Execute on_completes.
40
- # request.complete
41
- def complete
42
- if defined?(@on_complete)
43
- @on_complete.map{ |callback| callback.call(self) }
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,43 +0,0 @@
1
- module Typhoeus
2
- module Responses
3
-
4
- # This module contains logic about informations
5
- # on a response.
6
- module Informations
7
-
8
- # All available informations.
9
- AVAILABLE_INFORMATIONS = Ethon::Easies::Informations::AVAILABLE_INFORMATIONS.keys+
10
- [:return_code, :response_body, :response_header]
11
-
12
- AVAILABLE_INFORMATIONS.each do |name|
13
- define_method(name) do
14
- options[name.to_sym]
15
- end
16
- end
17
-
18
- # Returns the response header.
19
- #
20
- # @example Return header.
21
- # response.header
22
- #
23
- # @return [ Header ] The response header.
24
- def header
25
- return nil unless response_header
26
- @header ||= Responses::Header.new(response_header.split("\r\n\r\n").last)
27
- end
28
-
29
- # Return all redirections in between as multiple
30
- # responses with header.
31
- #
32
- # @example Return redirections.
33
- # response.redirections
34
- #
35
- # @return [ Array ] The redirections
36
- def redirections
37
- return [] unless response_header
38
- response_header.split("\r\n\r\n")[0..-2].map{ |h| Response.new(:response_header => h) }
39
- end
40
- end
41
- end
42
- end
43
-
@@ -1,26 +0,0 @@
1
- module Typhoeus
2
- module Responses # :nodoc:
3
-
4
- # This module contains logic for providing the
5
- # old accessors.
6
- module Legacy
7
-
8
- # The legacy mapping.
9
- MAPPING = {
10
- :body => :response_body,
11
- :code => :response_code,
12
- :curl_return_code => :return_code,
13
- :time => :total_time,
14
- :app_connect_time => :appconnect_time,
15
- :start_transfer_time => :starttransfer_time,
16
- :name_lookup_time => :namelookup_time
17
- }
18
-
19
- MAPPING.each do |old, new|
20
- define_method(old) do
21
- options[new]
22
- end
23
- end
24
- end
25
- end
26
- end