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 +5 -5
- data/.travis.yml +11 -7
- data/CHANGELOG.md +13 -1
- data/CONTRIBUTING.md +4 -0
- data/README.md +7 -4
- data/lib/typhoeus.rb +4 -3
- data/lib/typhoeus/adapters/faraday.rb +2 -2
- data/lib/typhoeus/cache/dalli.rb +3 -1
- data/lib/typhoeus/cache/rails.rb +4 -2
- data/lib/typhoeus/cache/redis.rb +3 -1
- data/lib/typhoeus/config.rb +1 -1
- data/lib/typhoeus/easy_factory.rb +1 -1
- data/lib/typhoeus/hydra/cacheable.rb +1 -1
- data/lib/typhoeus/request/cacheable.rb +5 -1
- data/lib/typhoeus/version.rb +1 -1
- data/spec/typhoeus/adapters/faraday_spec.rb +1 -1
- data/spec/typhoeus/hydra/cacheable_spec.rb +31 -1
- data/spec/typhoeus/pool_spec.rb +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79bd3451f6ec67ea973d9dc62dc4645c21e2eba1
|
4
|
+
data.tar.gz: 762e3c44e97fc0f2241d5cbf9d2a9ff2caa8a53a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0a7c0b640b05b4527a4a9a7b3ee7db526fc25e31e001b7287f2423fecebbf6d673adb5c17b7cda32c1206872a3a27d82825b9ee74974607f691e9ee573fb39a
|
7
|
+
data.tar.gz: 444398bc7499402359de7a5534c265bf91c39346903c1b82c4767b1b7f9eb9c72741a979986b905e388301055e6816baa6ef999f9f35bed06a07a4bec37d7b99
|
data/.travis.yml
CHANGED
@@ -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.
|
10
|
-
- 2.2.
|
11
|
-
- 2.3.
|
12
|
-
- 2.4.
|
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
|
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,19 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
-
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.
|
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
|
|
data/CONTRIBUTING.md
CHANGED
@@ -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/
|
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
|
24
|
+
gem "typhoeus"
|
25
25
|
```
|
26
|
+
Then run `bundle install`
|
27
|
+
|
28
|
+
Or install it yourself as:
|
26
29
|
|
27
30
|
```
|
28
|
-
gem
|
31
|
+
gem install typhoeus
|
29
32
|
```
|
30
33
|
|
31
34
|
## Project Tracking
|
data/lib/typhoeus.rb
CHANGED
@@ -127,11 +127,12 @@ module Typhoeus
|
|
127
127
|
# #=> :ok
|
128
128
|
# end
|
129
129
|
#
|
130
|
-
# @
|
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
|
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::
|
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::
|
106
|
+
raise Faraday::ConnectionFailed, resp.return_message
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
data/lib/typhoeus/cache/dalli.rb
CHANGED
@@ -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 [
|
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
|
data/lib/typhoeus/cache/rails.rb
CHANGED
@@ -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 [
|
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
|
data/lib/typhoeus/cache/redis.rb
CHANGED
@@ -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 [
|
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
|
data/lib/typhoeus/config.rb
CHANGED
@@ -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
|
-
|
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]
|
@@ -11,7 +11,7 @@ module Typhoeus
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def run
|
14
|
-
if
|
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
|
data/lib/typhoeus/version.rb
CHANGED
@@ -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::
|
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
|
data/spec/typhoeus/pool_spec.rb
CHANGED
@@ -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
|
-
|
91
|
+
queue = Queue.new
|
92
92
|
(0..9).map do |n|
|
93
93
|
Thread.new do
|
94
|
-
|
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.
|
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:
|
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.
|
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.
|