typhoeus 0.6.1 → 0.6.2

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 CHANGED
@@ -2,7 +2,22 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.1...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.2...master)
6
+
7
+ ## 0.6.2
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.1...v0.6.2)
10
+
11
+ Enhancements:
12
+
13
+ * Reintroduce a global cache.
14
+ * `Request#handled_response` falls back to the original response.
15
+ ([turnerking](https://github.com/turnerking), [\#272](https://github.com/typhoeus/typhoeus/pull/272))
16
+ * When `Errors::NoStub` is raised the `url` is displayed.
17
+ ([dschneider](https://github.com/dschneider), [\#276](https://github.com/typhoeus/typhoeus/pull/276))
18
+ * Make `Request#hash` consistent.
19
+ * Add `.rvmrc` and `ctags` to `.gitignore`.
20
+ ([ryankindermann](https://github.com/ryankinderman), [\#274](https://github.com/typhoeus/typhoeus/pull/274))
6
21
 
7
22
  ## 0.6.1
8
23
 
@@ -24,6 +39,8 @@ Enhancements:
24
39
  Bugfixes:
25
40
 
26
41
  * Corrected ssl options for the faraday adapter.
42
+ * The before hook now correctly returns the response.
43
+ ([Mattias Putman](https://github.com/challengee), [\#268](https://github.com/typhoeus/typhoeus/pull/268))
27
44
  * Benchmark is working again.
28
45
 
29
46
  ## 0.5.4
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typhoeus [![Build Status](https://secure.travis-ci.org/typhoeus/typhoeus.png)](http://travis-ci.org/typhoeus/typhoeus) [<img src="https://codeclimate.com/github/typhoeus/typhoeus.png" height="13" width="89" />](https://codeclimate.com/github/typhoeus/typhoeus)
1
+ # Typhoeus [![Build Status](https://secure.travis-ci.org/typhoeus/typhoeus.png)](http://travis-ci.org/typhoeus/typhoeus) [![Code Climate](https://codeclimate.com/github/typhoeus/typhoeus.png)](https://codeclimate.com/github/typhoeus/typhoeus)
2
2
 
3
3
  Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
4
4
 
@@ -43,5 +43,13 @@ module Typhoeus
43
43
  #
44
44
  # @see http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTVERBOSE
45
45
  attr_accessor :verbose
46
+
47
+ # Defines wether requests are cached.
48
+ #
49
+ # @return [ Object ]
50
+ #
51
+ # @see Typhoeus::Hydra::Cacheable
52
+ # @see Typhoeus::Request::Cacheable
53
+ attr_accessor :cache
46
54
  end
47
55
  end
@@ -51,7 +51,7 @@ module Typhoeus
51
51
  easy.http_request(
52
52
  request.base_url,
53
53
  request.options.fetch(:method, :get),
54
- request.options.reject{|k,_| k==:method}
54
+ request.options.reject{ |k,_| [:method, :cache_ttl].include?(k) }
55
55
  )
56
56
  rescue Ethon::Errors::InvalidOption => e
57
57
  help = provide_help(e.message.match(/:\s(\w+)/)[1])
@@ -5,7 +5,7 @@ module Typhoeus
5
5
  # and making a real request.
6
6
  class NoStub < TyphoeusError
7
7
  def initialize(request)
8
- super("The connection is blocked and no stub defined.")
8
+ super("The connection is blocked and no stub defined: #{request.url}")
9
9
  end
10
10
  end
11
11
  end
@@ -1,5 +1,6 @@
1
1
  require 'typhoeus/hydra/addable'
2
2
  require 'typhoeus/hydra/before'
3
+ require 'typhoeus/hydra/cacheable'
3
4
  require 'typhoeus/hydra/block_connection'
4
5
  require 'typhoeus/hydra/memoizable'
5
6
  require 'typhoeus/hydra/queueable'
@@ -41,6 +42,7 @@ module Typhoeus
41
42
  include Hydra::Addable
42
43
  include Hydra::Runnable
43
44
  include Hydra::Memoizable
45
+ include Hydra::Cacheable
44
46
  include Hydra::BlockConnection
45
47
  include Hydra::Stubbable
46
48
  include Hydra::Before
@@ -0,0 +1,13 @@
1
+ module Typhoeus
2
+ class Hydra
3
+ module Cacheable
4
+ def add(request)
5
+ if request.cacheable? && response = Typhoeus::Config.cache.get(request)
6
+ request.finish(response)
7
+ else
8
+ super
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/typhoeus/pool.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module Typhoeus
2
4
 
3
5
  # The easy pool stores already initialized
@@ -8,15 +10,7 @@ module Typhoeus
8
10
  module Pool
9
11
  extend self
10
12
 
11
- # Return the easy pool.
12
- #
13
- # @example Return easy pool.
14
- # hydra.easy_pool
15
- #
16
- # @return [ Array<Ethon::Easy> ] The easy pool.
17
- def easies
18
- @easies ||= []
19
- end
13
+ @mutex = Mutex.new
20
14
 
21
15
  # Releases easy into pool. The easy handle is
22
16
  # resetted before it gets back in.
@@ -25,7 +19,7 @@ module Typhoeus
25
19
  # hydra.release_easy(easy)
26
20
  def release(easy)
27
21
  easy.reset
28
- easies << easy
22
+ @mutex.synchronize { easies << easy }
29
23
  end
30
24
 
31
25
  # Return an easy from pool.
@@ -35,17 +29,30 @@ module Typhoeus
35
29
  #
36
30
  # @return [ Ethon::Easy ] The easy.
37
31
  def get
38
- easies.pop || Ethon::Easy.new
32
+ @mutex.synchronize { easies.pop } || Ethon::Easy.new
39
33
  end
40
34
 
41
35
  def clear
42
- easies.clear
36
+ @mutex.synchronize { easies.clear }
43
37
  end
44
38
 
45
39
  def with_easy(&block)
46
40
  easy = get
47
41
  yield easy
48
- release easy
42
+ ensure
43
+ release(easy) if easy
44
+ end
45
+
46
+ private
47
+
48
+ # Return the easy pool.
49
+ #
50
+ # @example Return easy pool.
51
+ # hydra.easy_pool
52
+ #
53
+ # @return [ Array<Ethon::Easy> ] The easy pool.
54
+ def easies
55
+ @easies ||= []
49
56
  end
50
57
  end
51
58
  end
@@ -1,6 +1,7 @@
1
1
  require 'typhoeus/request/actions'
2
2
  require 'typhoeus/request/before'
3
3
  require 'typhoeus/request/block_connection'
4
+ require 'typhoeus/request/cacheable'
4
5
  require 'typhoeus/request/callbacks'
5
6
  require 'typhoeus/request/marshal'
6
7
  require 'typhoeus/request/memoizable'
@@ -26,6 +27,7 @@ module Typhoeus
26
27
  include Request::Operations
27
28
  include Request::Responseable
28
29
  include Request::Memoizable
30
+ include Request::Cacheable
29
31
  include Request::BlockConnection
30
32
  include Request::Stubbable
31
33
  include Request::Before
@@ -146,7 +148,7 @@ module Typhoeus
146
148
  #
147
149
  # @api private
148
150
  def hash
149
- [ self.class, self.base_url, self.options ].hash
151
+ Digest::MD5.hexdigest("#{self.class.name}#{base_url}#{options}").to_i(16)
150
152
  end
151
153
 
152
154
  private
@@ -0,0 +1,26 @@
1
+ module Typhoeus
2
+ class Request
3
+ module Cacheable
4
+ def response=(response)
5
+ Typhoeus::Config.cache.set(self, response) if cacheable?
6
+ super
7
+ end
8
+
9
+ def cacheable?
10
+ Typhoeus::Config.cache
11
+ end
12
+
13
+ def run
14
+ if cacheable? && response = Typhoeus::Config.cache.get(self)
15
+ finish(response)
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def cache_ttl
22
+ options[:cache_ttl]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -26,10 +26,8 @@ module Typhoeus
26
26
  # @return [ Hash ]
27
27
  attr_accessor :options
28
28
 
29
- # The handled response.
30
- #
31
- # @return [ String ]
32
- attr_accessor :handled_response
29
+ # Set the handled response.
30
+ attr_writer :handled_response
33
31
 
34
32
  # @api private
35
33
  attr_writer :mock
@@ -54,5 +52,14 @@ module Typhoeus
54
52
  def mock
55
53
  defined?(@mock) ? @mock : options[:mock]
56
54
  end
55
+
56
+ # Returns the handled_response if it has
57
+ # been defined otherwise returns the response
58
+ #
59
+ # @return [ Object ] The result of callbacks
60
+ # done on the response or the original response.
61
+ def handled_response
62
+ @handled_response || self
63
+ end
57
64
  end
58
65
  end
@@ -15,6 +15,18 @@ module Typhoeus
15
15
  options[:return_code]
16
16
  end
17
17
 
18
+ # Returns a string describing the return.
19
+ #
20
+ # @example Get return_message.
21
+ # response.return_message
22
+ #
23
+ # @return [ String ] The return_message.
24
+ #
25
+ # @since 0.6.2
26
+ def return_message
27
+ Ethon::Curl.easy_strerror(return_code)
28
+ end
29
+
18
30
  # Return the http response body.
19
31
  #
20
32
  # @example Get response_body.
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.6.1'
4
+ VERSION = '0.6.2'
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.6.1
4
+ version: 0.6.2
5
5
  prerelease:
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: 2013-02-11 00:00:00.000000000 Z
14
+ date: 2013-03-03 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.5.9
23
+ version: 0.5.10
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  requirements:
29
29
  - - ~>
30
30
  - !ruby/object:Gem::Version
31
- version: 0.5.9
31
+ version: 0.5.10
32
32
  description: Like a modern code version of the mythical beast with 100 serpent heads,
33
33
  Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
34
34
  email:
@@ -50,6 +50,7 @@ files:
50
50
  - lib/typhoeus/hydra/addable.rb
51
51
  - lib/typhoeus/hydra/before.rb
52
52
  - lib/typhoeus/hydra/block_connection.rb
53
+ - lib/typhoeus/hydra/cacheable.rb
53
54
  - lib/typhoeus/hydra/memoizable.rb
54
55
  - lib/typhoeus/hydra/queueable.rb
55
56
  - lib/typhoeus/hydra/runnable.rb
@@ -60,6 +61,7 @@ files:
60
61
  - lib/typhoeus/request/actions.rb
61
62
  - lib/typhoeus/request/before.rb
62
63
  - lib/typhoeus/request/block_connection.rb
64
+ - lib/typhoeus/request/cacheable.rb
63
65
  - lib/typhoeus/request/callbacks.rb
64
66
  - lib/typhoeus/request/marshal.rb
65
67
  - lib/typhoeus/request/memoizable.rb
@@ -92,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
94
  version: '0'
93
95
  segments:
94
96
  - 0
95
- hash: 1775342987634416595
97
+ hash: -431775000708918631
96
98
  required_rubygems_version: !ruby/object:Gem::Requirement
97
99
  none: false
98
100
  requirements: