typhoeus 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 417ef8dd5903c12a896c84db243131ec364aec235a44ac32d2590d95f919c10a
4
- data.tar.gz: 62fca0f2cf069282d5c6cdbed018e395b6b40f379cb2d8e45129a156e7aed69a
2
+ SHA1:
3
+ metadata.gz: 79bd3451f6ec67ea973d9dc62dc4645c21e2eba1
4
+ data.tar.gz: 762e3c44e97fc0f2241d5cbf9d2a9ff2caa8a53a
5
5
  SHA512:
6
- metadata.gz: 9a8e291edbdb7e635f6ffbf085783752e6a0688e342dbec333e2fd85f6d4ac841a4bfca128fe36d4f30d5e0f87a8d124447d77cfd2d15e77c6f29bec4a55f197
7
- data.tar.gz: cf6d163bfb31f1cf77c2faf068601b6c65685d5afaf0f582dadd9505882fb8c567583fd1dad7a47f27210018e992ac300a7803f3870250e1f7a1461111bcab80
6
+ metadata.gz: e0a7c0b640b05b4527a4a9a7b3ee7db526fc25e31e001b7287f2423fecebbf6d673adb5c17b7cda32c1206872a3a27d82825b9ee74974607f691e9ee573fb39a
7
+ data.tar.gz: 444398bc7499402359de7a5534c265bf91c39346903c1b82c4767b1b7f9eb9c72741a979986b905e388301055e6816baa6ef999f9f35bed06a07a4bec37d7b99
@@ -1,15 +1,14 @@
1
1
  language: ruby
2
2
  script: "bundle exec rake"
3
- sudo: false
4
3
  rvm:
5
- - 1.8.7
6
- - 1.9.2
7
4
  - 1.9.3
8
5
  - 2.0.0
9
- - 2.1.8
10
- - 2.2.4
11
- - 2.3.0
12
- - 2.4.1
6
+ - 2.1.10
7
+ - 2.2.10
8
+ - 2.3.8
9
+ - 2.4.7
10
+ - 2.5.6
11
+ - 2.6.4
13
12
  - ruby-head
14
13
  - jruby-head
15
14
  - jruby-18mode
@@ -20,3 +19,8 @@ matrix:
20
19
  - rvm: ruby-head
21
20
  - rvm: jruby-head
22
21
  - rvm: ree
22
+ include:
23
+ - rvm: 1.8.7
24
+ dist: precise
25
+ - rvm: 1.9.2
26
+ dist: trusty
@@ -2,7 +2,19 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.1.2...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.4.0...master)
6
+
7
+ ## 1.4.0
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.1.2...v1.4.0)
10
+
11
+ #### 1 feature
12
+ - Faraday adapter exceptions namespace compatibility with Faraday v1 ([@iMacTia](https://github.com/iMacTia) in [#616](https://github.com/typhoeus/typhoeus/pull/616))
13
+
14
+ #### 3 Others
15
+ - Yard warning fixes ([@olleolleolle](https://github.com/olleolleolle) in [#622](https://github.com/typhoeus/typhoeus/pull/622))
16
+ - Add more Ruby versions in CI matrix ([@olleolleolle](https://github.com/olleolleolle) in [#623](https://github.com/typhoeus/typhoeus/pull/623))
17
+ - Use of argument passed in function instead of `attr_reader` ([@v-kolesnikov](https://github.com/v-kolesnikov) in [#625](https://github.com/typhoeus/typhoeus/pull/625))
6
18
 
7
19
  ## 1.1.2
8
20
 
@@ -14,3 +14,7 @@ a test!
14
14
  5. Push to your fork and submit a pull request.
15
15
 
16
16
  And in case we didn't emphasize it enough: we love tests!
17
+
18
+ ## Issue triage [![Open Source Helpers](https://www.codetriage.com/typhoeus/typhoeus/badges/users.svg)](https://www.codetriage.com/typhoeus/typhoeus)
19
+
20
+ You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to typhoeus on CodeTriage](https://www.codetriage.com/typhoeus/typhoeus).
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Typhoeus [![Build Status](https://img.shields.io/travis/typhoeus/typhoeus/master.svg)](https://travis-ci.org/typhoeus/typhoeus) [![Code Climate](https://img.shields.io/codeclimate/github/typhoeus/typhoeus.svg)](https://codeclimate.com/github/typhoeus/typhoeus) [![Gem Version](https://img.shields.io/gem/v/typhoeus.svg)](https://rubygems.org/gems/typhoeus)
1
+ # Typhoeus [![Build Status](https://img.shields.io/travis/typhoeus/typhoeus/master.svg)](https://travis-ci.org/typhoeus/typhoeus) [![Code Climate](https://img.shields.io/codeclimate/maintainability/typhoeus/typhoeus.svg)](https://codeclimate.com/github/typhoeus/typhoeus) [![Gem Version](https://img.shields.io/gem/v/typhoeus.svg)](https://rubygems.org/gems/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
 
@@ -19,13 +19,16 @@ hydra.run
19
19
  ```
20
20
 
21
21
  ## Installation
22
-
22
+ Add the following line to your Gemfile:
23
23
  ```
24
- gem install typhoeus
24
+ gem "typhoeus"
25
25
  ```
26
+ Then run `bundle install`
27
+
28
+ Or install it yourself as:
26
29
 
27
30
  ```
28
- gem "typhoeus"
31
+ gem install typhoeus
29
32
  ```
30
33
 
31
34
  ## Project Tracking
@@ -127,11 +127,12 @@ module Typhoeus
127
127
  # #=> :ok
128
128
  # end
129
129
  #
130
- # @param [ Block ] block The block to execute.
131
- #
130
+ # @yield Yields control to the block after disabling block_connection.
131
+ # Afterwards, the block_connection is set to its original
132
+ # value.
132
133
  # @return [ Object ] Returns the return value of the block.
133
134
  #
134
- # @see Typhoeus::Config#block_connection
135
+ # @see Typhoeus::Config.block_connection
135
136
  def self.with_connection
136
137
  old = Config.block_connection
137
138
  Config.block_connection = false
@@ -97,13 +97,13 @@ module Faraday # :nodoc:
97
97
  if resp.timed_out?
98
98
  env[:typhoeus_timed_out] = true
99
99
  unless parallel?(env)
100
- raise Faraday::Error::TimeoutError, "request timed out"
100
+ raise Faraday::TimeoutError, "request timed out"
101
101
  end
102
102
  elsif (resp.response_code == 0) || ((resp.return_code != :ok) && !resp.mock?)
103
103
  env[:typhoeus_connection_failed] = true
104
104
  env[:typhoeus_return_message] = resp.return_message
105
105
  unless parallel?(env)
106
- raise Faraday::Error::ConnectionFailed, resp.return_message
106
+ raise Faraday::ConnectionFailed, resp.return_message
107
107
  end
108
108
  end
109
109
 
@@ -7,7 +7,9 @@ module Typhoeus
7
7
  #
8
8
  # @param [ Dalli::Client ] client
9
9
  # A connection to the cache server. Defaults to `Dalli::Client.new`
10
- # @param [ Integer ] default_ttl
10
+ # @param [ Hash ] options
11
+ # Options
12
+ # @option options [ Integer ] :default_ttl
11
13
  # The default TTL of cached responses in seconds, for requests which do not set a cache_ttl.
12
14
  def initialize(client = ::Dalli::Client.new, options = {})
13
15
  @client = client
@@ -7,7 +7,9 @@ module Typhoeus
7
7
  #
8
8
  # @param [ ActiveSupport::Cache::Store ] cache
9
9
  # A Rails cache backend. Defaults to Rails.cache.
10
- # @param [ Integer ] default_ttl
10
+ # @param [ Hash ] options
11
+ # Options
12
+ # @option options [ Integer ] :default_ttl
11
13
  # The default TTL of cached responses in seconds, for requests which do not set a cache_ttl.
12
14
  def initialize(cache = ::Rails.cache, options = {})
13
15
  @cache = cache
@@ -19,7 +21,7 @@ module Typhoeus
19
21
  end
20
22
 
21
23
  def set(request, response)
22
- @cache.write(request, response, :expires_in => request.cache_ttl || @default_ttl)
24
+ @cache.write(request.cache_key, response, :expires_in => request.cache_ttl || @default_ttl)
23
25
  end
24
26
  end
25
27
  end
@@ -8,7 +8,9 @@ module Typhoeus
8
8
  # @param [ Redis ] redis
9
9
  # A connection to Redis. Defaults to `Redis.new`, which uses the
10
10
  # `REDIS_URL` environment variable to connect
11
- # @param [ Integer ] default_ttl
11
+ # @param [ Hash ] options
12
+ # Options
13
+ # @option options [ Integer ] :default_ttl
12
14
  # The default TTL of cached responses in seconds, for requests which do not set a cache_ttl.
13
15
  def initialize(redis = ::Redis.new, options = {})
14
16
  @redis = redis
@@ -18,7 +18,7 @@ module Typhoeus
18
18
  # {Typhoeus::Errors::NoStub} error is raised,
19
19
  # when trying to do a real request. It's possible
20
20
  # to work around inside
21
- # {Typhoeus#with_connection}.
21
+ # {Typhoeus.with_connection}.
22
22
  #
23
23
  # @return [ Boolean ]
24
24
  #
@@ -97,7 +97,7 @@ module Typhoeus
97
97
  # set nosignal to true by default
98
98
  # this improves thread safety and timeout behavior
99
99
  sanitized = {:nosignal => true}
100
- request.options.each do |k,v|
100
+ options.each do |k,v|
101
101
  s = k.to_sym
102
102
  next if SANITIZE_IGNORE.include?(s)
103
103
  if new_option = RENAMED_OPTIONS[k.to_sym]
@@ -2,7 +2,7 @@ module Typhoeus
2
2
  class Hydra
3
3
  module Cacheable
4
4
  def add(request)
5
- if request.cacheable? && response = Typhoeus::Config.cache.get(request)
5
+ if request.cacheable? && response = request.cached_response
6
6
  response.cached = true
7
7
  request.finish(response)
8
8
  dequeue
@@ -11,7 +11,7 @@ module Typhoeus
11
11
  end
12
12
 
13
13
  def run
14
- if cacheable? && response = cache.get(self)
14
+ if response = cached_response
15
15
  response.cached = true
16
16
  finish(response)
17
17
  else
@@ -19,6 +19,10 @@ module Typhoeus
19
19
  end
20
20
  end
21
21
 
22
+ def cached_response
23
+ cacheable? && cache.get(self)
24
+ end
25
+
22
26
  def cache_ttl
23
27
  options[:cache_ttl]
24
28
  end
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '1.3.1'
4
+ VERSION = '1.4.0'
5
5
  end
@@ -163,7 +163,7 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
163
163
 
164
164
  context "when not parallel" do
165
165
  it "raises an error" do
166
- expect { conn.get("/") }.to raise_error(Faraday::Error::ConnectionFailed, "No error")
166
+ expect { conn.get("/") }.to raise_error(Faraday::ConnectionFailed, "No error")
167
167
  end
168
168
  end
169
169
  end
@@ -4,6 +4,7 @@ describe Typhoeus::Hydra::Cacheable do
4
4
  let(:base_url) { "localhost:3001" }
5
5
  let(:hydra) { Typhoeus::Hydra.new() }
6
6
  let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
7
+ let(:response) { Typhoeus::Response.new }
7
8
  let(:cache) { MemoryCache.new }
8
9
 
9
10
  describe "add" do
@@ -24,7 +25,6 @@ describe Typhoeus::Hydra::Cacheable do
24
25
  end
25
26
 
26
27
  context "when request in memory" do
27
- let(:response) { Typhoeus::Response.new }
28
28
  before { cache.memory[request] = response }
29
29
 
30
30
  it "returns response with cached status" do
@@ -53,6 +53,36 @@ describe Typhoeus::Hydra::Cacheable do
53
53
  end
54
54
  end
55
55
  end
56
+
57
+ context "when cache is specified on a request" do
58
+ before { Typhoeus::Config.cache = false }
59
+
60
+ context "when cache is false" do
61
+ let(:non_cached_request) { Typhoeus::Request.new(base_url, {:method => :get, :cache => false}) }
62
+
63
+ it "initiates an HTTP call" do
64
+ expect(Typhoeus::EasyFactory).to receive(:new).with(non_cached_request, hydra).and_call_original
65
+
66
+ hydra.add(non_cached_request)
67
+ end
68
+ end
69
+
70
+ context "when cache is defined" do
71
+ let(:cached_request) { Typhoeus::Request.new(base_url, {:method => :get, :cache => cache}) }
72
+
73
+ before { cache.memory[cached_request] = response }
74
+
75
+ it "uses the cache instead of making a new request" do
76
+ expect(Typhoeus::EasyFactory).not_to receive(:new)
77
+
78
+ hydra.add(cached_request)
79
+
80
+ expect(cached_request.response).to be_cached
81
+ expect(cached_request.response).to eq(response)
82
+ end
83
+ end
84
+ end
85
+
56
86
  end
57
87
  end
58
88
  end
@@ -88,12 +88,14 @@ describe Typhoeus::Pool do
88
88
 
89
89
  context "when threaded access" do
90
90
  it "creates correct number of easies" do
91
- array = []
91
+ queue = Queue.new
92
92
  (0..9).map do |n|
93
93
  Thread.new do
94
- array << Typhoeus::Pool.get
94
+ queue.enq(Typhoeus::Pool.get)
95
95
  end
96
96
  end.map(&:join)
97
+
98
+ array = Array.new(queue.size) { queue.pop }
97
99
  expect(array.uniq.size).to eq(10)
98
100
  end
99
101
  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: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Balatero
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-11-06 00:00:00.000000000 Z
13
+ date: 2020-05-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ethon
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: 1.3.6
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 2.7.6
153
+ rubygems_version: 2.5.2.3
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Parallel HTTP library on top of libcurl multi.