typhoeus 0.6.7 → 0.6.8

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.
@@ -1,8 +1,34 @@
1
1
  # Changelog
2
2
 
3
- ## Master
3
+ ## 0.6.8
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.6...master)
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.7...v0.6.8)
6
+
7
+ Bugfixes:
8
+
9
+ * Fix Faraday 0.9 compatibility.
10
+ ([Gleb Mazovetskiy](https://github.com/glebm), [\#357](https://github.com/typhoeus/typhoeus/pull/357)
11
+ * Fix Request#hash for different key orders.
12
+ ([Matthew Schulkind](https://github.com/mschulkind), [\#344](https://github.com/typhoeus/typhoeus/pull/344))
13
+
14
+ Enhancements:
15
+
16
+ * Use SVG for status badges in README.
17
+ 7[Sean Linsley](https://github.com/seanlinsley), [\#353](https://github.com/typhoeus/typhoeus/pull/353))
18
+ * Missing quotes in README example code.
19
+ ([Jason R. Clark](https://github.com/jasonrclark), [\#351](https://github.com/typhoeus/typhoeus/pull/351))
20
+ * Specs for Faraday adapter.
21
+ ([michaelavila](https://github.com/michaelavila), [\#348](https://github.com/typhoeus/typhoeus/pull/348))
22
+ * Clarify wording in README.
23
+ ([Sean Linsley](https://github.com/seanlinsley), [\#347](https://github.com/typhoeus/typhoeus/pull/347))
24
+ * Make caching easier for non-memory caches.
25
+ ([Matthew Schulkind](https://github.com/mschulkind), [\#345](https://github.com/typhoeus/typhoeus/pull/345))
26
+ * Spec refactoring.
27
+ ([Matthew Schulkind](https://github.com/mschulkind), [\#343](https://github.com/typhoeus/typhoeus/pull/343))
28
+
29
+ ## 0.6.7
30
+
31
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.6...v0.6.7)
6
32
 
7
33
  Enhancements:
8
34
 
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ group :development, :test do
8
8
 
9
9
  gem "sinatra", "~> 1.3"
10
10
  gem "json"
11
- gem "faraday", "~> 0.8.4"
11
+ gem "faraday", ">= 0.9"
12
12
 
13
13
  if RUBY_PLATFORM == "java"
14
14
  gem "spoon"
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  Copyright (c) 2009-2010 Paul Dix
2
2
  Copyright (c) 2011 David Balatero
3
- Copyright (c) 2012 Hans Hasselberg
3
+ Copyright (c) 2012-2014 Hans Hasselberg
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
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) [![Code Climate](https://codeclimate.com/github/typhoeus/typhoeus.png)](https://codeclimate.com/github/typhoeus/typhoeus) [![Gem Version](https://badge.fury.io/rb/typhoeus.png)](http://badge.fury.io/rb/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/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)
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
 
@@ -50,7 +50,7 @@ request = Typhoeus::Request.new(
50
50
  ```
51
51
 
52
52
  We can see from this that the first argument is the url. The second is a set of options.
53
- The options are all optional. The default for `:method` is `:get`.
53
+ The options are all optional. The default for `:method` is `:get`.
54
54
 
55
55
  When you want to send URL parameters, you can use `:params` hash to do so. Please note that in case of you should send a request via `x-www-form-urlencoded` parameters, you need to use `:body` hash instead. `params` are for URL parameters and `:body` is for the request body.
56
56
 
@@ -172,7 +172,7 @@ hydra = Typhoeus::Hydra.hydra
172
172
 
173
173
  first_request = Typhoeus::Request.new("www.example.com/posts/1.json")
174
174
  first_request.on_complete do |response|
175
- third_request = Typhoeus::Request.new(www.example.com/posts/3.json)
175
+ third_request = Typhoeus::Request.new("www.example.com/posts/3.json")
176
176
  hydra.queue third_request
177
177
  end
178
178
  second_request = Typhoeus::Request.new("www.example.com/posts/2.json")
@@ -208,7 +208,7 @@ end
208
208
  hydra.run
209
209
  ```
210
210
 
211
- This will result in a two requests.
211
+ This will result in two requests.
212
212
 
213
213
  ```ruby
214
214
  Typhoeus::Config.memoize = false
@@ -226,27 +226,63 @@ Typhoeus includes built in support for caching. In the following example, if the
226
226
 
227
227
  ```ruby
228
228
  class Cache
229
- attr_accessor :memory
230
-
231
229
  def initialize
232
230
  @memory = {}
233
231
  end
234
232
 
235
233
  def get(request)
236
- memory[request]
234
+ @memory[request]
237
235
  end
238
236
 
239
237
  def set(request, response)
240
- memory[request] = response
238
+ @memory[request] = response
241
239
  end
242
240
  end
243
241
 
244
242
  Typhoeus::Config.cache = Cache.new
245
243
 
246
- Typhoeus.get("www.example.com") == Typhoeus.get("www.example.com")
244
+ Typhoeus.get("www.example.com").cached?
245
+ #=> false
246
+ Typhoeus.get("www.example.com").cached?
247
247
  #=> true
248
248
  ```
249
249
 
250
+ For use with [Dalli](https://github.com/mperham/dalli):
251
+
252
+ ```ruby
253
+ class Cache
254
+ def initialize
255
+ @client = Dalli::Client.new
256
+ end
257
+
258
+ def get(request)
259
+ @client.get(request.cache_key)
260
+ end
261
+
262
+ def set(request, response)
263
+ @client.set(request.cache_key, response)
264
+ end
265
+ end
266
+
267
+ Typhoeus::Config.cache = Cache.new
268
+ ```
269
+
270
+ For use with Rails:
271
+
272
+ ```ruby
273
+ class Cache
274
+ def get(request)
275
+ Rails.cache.read(request)
276
+ end
277
+
278
+ def set(request, response)
279
+ Rails.cache.write(request, response)
280
+ end
281
+ end
282
+
283
+ Typhoeus::Config.cache = Cache.new
284
+ ```
285
+
250
286
  ### Direct Stubbing
251
287
 
252
288
  Hydra allows you to stub out specific urls and patterns to avoid hitting
@@ -288,10 +324,10 @@ No exceptions are raised on HTTP timeouts. You can check whether a request timed
288
324
  Typhoeus.get("www.example.com").timed_out?
289
325
  ```
290
326
 
291
- There are two different timeouts available: [`timeout`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTTIMEOUT)
327
+ There are two different timeouts available: [`timeout`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTTIMEOUT)
292
328
  and [`connecttimeout`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT). `timeout` is the
293
- maximum time in seconds that you allow the libcurl transfer operation to take and `connecttimeout` is the maximum
294
- time in seconds that you allow the connection to the server to take. These two are always available, while `timeout_ms` ond
329
+ maximum time in seconds that you allow the libcurl transfer operation to take and `connecttimeout` is the maximum
330
+ time in seconds that you allow the connection to the server to take. These two are always available, while `timeout_ms` ond
295
331
  `connecttimeout_ms` accept milliseconds but only an option when curl is build with `c-ares`, it will use `timout` or `connecttimeout` otherwise.
296
332
 
297
333
  ### Following Redirections
@@ -314,8 +350,8 @@ Typhoeus::Request.get("www.example.com", userpwd: "user:password")
314
350
  Typhoeus::Request.get("www.example.com", cookiefile: "/path/to/file", cookiejar: "/path/to/file")
315
351
  ```
316
352
 
317
- Here, `cookiefile` is a file to read cookies to send from, and `cookiejar` is a file to write received cookies to.
318
- So, if you just want cookies enabled, you need to pass in a same filename in both options.
353
+ Here, `cookiefile` is a file to read cookies from, and `cookiejar` is a file to write received cookies to.
354
+ If you just want cookies enabled, you need to pass the same filename for both options.
319
355
 
320
356
  ### Other CURL options
321
357
 
@@ -352,13 +388,13 @@ Typhoeus.get("https://www.example.com", ssl_verifyhost: 2)
352
388
 
353
389
  ### Verbose debug output
354
390
 
355
- Sometime it’s useful to see verbose output from curl. You may now enable it on a per request basis:
391
+ It’s sometimes useful to see verbose output from curl. You can enable it on a per-request basis:
356
392
 
357
393
  ```ruby
358
394
  Typhoeus.get("http://example.com", verbose: true)
359
395
  ```
360
396
 
361
- or global:
397
+ or globally:
362
398
 
363
399
  ```ruby
364
400
  Typhoeus::Config.verbose = true
@@ -384,7 +420,7 @@ Copyright © 2009-2010 [Paul Dix](http://www.pauldix.net/)
384
420
 
385
421
  Copyright © 2011-2012 [David Balatero](https://github.com/dbalatero/)
386
422
 
387
- Copyright © 2012-2013 [Hans Hasselberg](http://github.com/i0rek/)
423
+ Copyright © 2012-2014 [Hans Hasselberg](http://github.com/i0rek/)
388
424
 
389
425
  Permission is hereby granted, free of charge, to any person obtaining a
390
426
  copy of this software and associated documentation files (the "Software"),
@@ -120,7 +120,8 @@ module Faraday # :nodoc:
120
120
  req.options[:sslkey] = ssl[:client_key] if ssl[:client_key]
121
121
  req.options[:cainfo] = ssl[:ca_file] if ssl[:ca_file]
122
122
  req.options[:capath] = ssl[:ca_path] if ssl[:ca_path]
123
- req.options[:keypasswd] = ssl[:client_cert_passwd] if ssl[:client_cert_passwd]
123
+ client_cert_passwd_key = [:client_cert_passwd, :client_certificate_password].detect { |name| ssl.key?(name) }
124
+ req.options[:keypasswd] = ssl[client_cert_passwd_key] if client_cert_passwd_key
124
125
  end
125
126
 
126
127
  def configure_proxy(req, env)
@@ -154,7 +154,15 @@ module Typhoeus
154
154
  #
155
155
  # @api private
156
156
  def hash
157
- Zlib.crc32 "#{self.class.name}#{base_url}#{options}"
157
+ Zlib.crc32 cache_key
158
+ end
159
+
160
+ # Returns a cache key for use with caching methods that required a string
161
+ # for a key. Will get used by ActiveSupport::Cache stores automatically.
162
+ #
163
+ # @return [ String ] The cache key.
164
+ def cache_key
165
+ "#{self.class.name}#{base_url}#{hashable_string_for(options)}"
158
166
  end
159
167
 
160
168
  # Mimics libcurls POST body generation. This is not accurate, but good
@@ -187,6 +195,17 @@ module Typhoeus
187
195
  end
188
196
  end
189
197
 
198
+ def hashable_string_for(obj)
199
+ case obj
200
+ when Hash
201
+ hashable_string_for(obj.sort_by {|sub_obj| sub_obj.first.to_s})
202
+ when Array
203
+ obj.map {|sub_obj| hashable_string_for(sub_obj)}.to_s
204
+ else
205
+ obj.to_s
206
+ end
207
+ end
208
+
190
209
  # Sets default header and verbose when turned on.
191
210
  def set_defaults
192
211
  if @options[:headers]
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.6.7'
4
+ VERSION = '0.6.8'
5
5
  end
@@ -6,13 +6,7 @@ Bundler.setup
6
6
  require "typhoeus"
7
7
  require "rspec"
8
8
 
9
- if defined? require_relative
10
- require_relative 'support/localhost_server.rb'
11
- require_relative 'support/server.rb'
12
- else
13
- require 'support/localhost_server.rb'
14
- require 'support/server.rb'
15
- end
9
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
16
10
 
17
11
  RSpec.configure do |config|
18
12
  config.order = :rand
@@ -0,0 +1,15 @@
1
+ class MemoryCache
2
+ attr_reader :memory
3
+
4
+ def initialize
5
+ @memory = {}
6
+ end
7
+
8
+ def get(request)
9
+ memory[request]
10
+ end
11
+
12
+ def set(request, response)
13
+ memory[request] = response
14
+ end
15
+ end
@@ -224,6 +224,30 @@ describe Faraday::Adapter::Typhoeus do
224
224
  end
225
225
  end
226
226
 
227
+ context "when client_cert_passwd" do
228
+ let(:env) { { :ssl => { :client_cert_passwd => "a" } } }
229
+
230
+ it "sets keypasswd to the value of client_cert_passwd" do
231
+ expect(request.options[:keypasswd]).to eq("a")
232
+ end
233
+ end
234
+
235
+ context "when client_certificate_password" do
236
+ let(:env) { { :ssl => { :client_certificate_password => "a" } } }
237
+
238
+ it "sets keypasswd to the value of client_cert_passwd" do
239
+ expect(request.options[:keypasswd]).to eq("a")
240
+ end
241
+ end
242
+
243
+ context "when no client_cert_passwd" do
244
+ let(:env) { { :ssl => { } } }
245
+
246
+ it "does not set keypasswd on options" do
247
+ expect(request.options).not_to have_key :keypasswd
248
+ end
249
+ end
250
+
227
251
  context "when verify is false" do
228
252
  let(:env) { { :ssl => { :verify => false } } }
229
253
 
@@ -4,23 +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(:cache) {
8
- Class.new do
9
- attr_reader :memory
10
-
11
- def initialize
12
- @memory = {}
13
- end
14
-
15
- def get(request)
16
- memory[request]
17
- end
18
-
19
- def set(request, response)
20
- memory[request] = response
21
- end
22
- end.new
23
- }
7
+ let(:cache) { MemoryCache.new }
24
8
 
25
9
  describe "add" do
26
10
  context "when cache activated" do
@@ -1,23 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Typhoeus::Request::Cacheable do
4
- let(:cache) {
5
- Class.new do
6
- attr_reader :memory
7
-
8
- def initialize
9
- @memory = {}
10
- end
11
-
12
- def get(request)
13
- memory[request]
14
- end
15
-
16
- def set(request, response)
17
- memory[request] = response
18
- end
19
- end.new
20
- }
4
+ let(:cache) { MemoryCache.new }
21
5
  let(:options) { {} }
22
6
  let(:request) { Typhoeus::Request.new("http://localhost:3001", options) }
23
7
  let(:response) { Typhoeus::Response.new }
@@ -27,7 +11,7 @@ describe Typhoeus::Request::Cacheable do
27
11
 
28
12
  describe "#response=" do
29
13
  context "when cache activated" do
30
- context "when nequest new" do
14
+ context "when request new" do
31
15
  it "caches response" do
32
16
  request.response = response
33
17
  expect(cache.memory[request]).to be
@@ -57,9 +41,6 @@ describe Typhoeus::Request::Cacheable do
57
41
 
58
42
  describe "#run" do
59
43
  context "when cache activated" do
60
- before { Typhoeus::Config.cache = cache }
61
- after { Typhoeus::Config.cache = false }
62
-
63
44
  context "when request new" do
64
45
  it "fetches response" do
65
46
  expect(request.response).to_not be(response)
@@ -67,7 +48,6 @@ describe Typhoeus::Request::Cacheable do
67
48
  end
68
49
 
69
50
  context "when request in memory" do
70
- let(:response) { Typhoeus::Response.new }
71
51
  before { cache.memory[request] = response }
72
52
 
73
53
  it "finishes request" do
@@ -143,15 +143,37 @@ describe Typhoeus::Request do
143
143
 
144
144
  describe "#hash" do
145
145
  context "when request.eql?(other)" do
146
- let(:other) { Typhoeus::Request.new(base_url, options) }
146
+ context "when different order" do
147
+ let(:other_options) {
148
+ {:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
149
+ }
150
+ let(:other) { Typhoeus::Request.new(base_url, other_options)}
151
+
152
+ it "has same hashes" do
153
+ expect(request.hash).to eq(other.hash)
154
+ end
155
+ end
147
156
 
148
- it "has same hashes" do
149
- expect(request.hash).to eq(other.hash)
157
+ context "when same order" do
158
+ let(:other) { Typhoeus::Request.new(base_url, options) }
159
+
160
+ it "has same hashes" do
161
+ expect(request.hash).to eq(other.hash)
162
+ end
163
+ end
164
+
165
+ context "when hashes with different orders are contained in arrays" do
166
+ let(:request) { Typhoeus::Request.new(base_url, :params => [{:b => 2, :a => 1}]) }
167
+ let(:other) { Typhoeus::Request.new(base_url, :params => [{:a => 1, :b => 2}]) }
168
+ it "has different hashes" do
169
+ expect(request.hash).to eq(other.hash)
170
+ end
150
171
  end
151
172
  end
152
173
 
153
174
  context "when not request.eql?(other)" do
154
- let(:other) { Typhoeus::Request.new("base_url", {}) }
175
+ let(:request) { Typhoeus::Request.new(base_url, :params => {:foo => 'bar'}) }
176
+ let(:other) { Typhoeus::Request.new(base_url, :params => {:foo => 'baz'}) }
155
177
 
156
178
  it "has different hashes" do
157
179
  expect(request.hash).to_not eq(other.hash)
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.required_rubygems_version = ">= 1.3.6"
18
18
  s.license = 'MIT'
19
19
 
20
- s.add_dependency('ethon', ["~> 0.6.2"])
20
+ s.add_dependency('ethon', [">= 0.7.0"])
21
21
 
22
22
  s.files = `git ls-files`.split("\n")
23
23
  s.test_files = `git ls-files -- spec/*`.split("\n")
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.7
4
+ version: 0.6.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,24 +11,24 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-12-19 00:00:00.000000000 Z
14
+ date: 2014-03-19 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.6.2
23
+ version: 0.7.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.6.2
31
+ version: 0.7.0
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:
@@ -94,6 +94,7 @@ files:
94
94
  - spec/rack/typhoeus/middleware/params_decoder_spec.rb
95
95
  - spec/spec_helper.rb
96
96
  - spec/support/localhost_server.rb
97
+ - spec/support/memory_cache.rb
97
98
  - spec/support/server.rb
98
99
  - spec/typhoeus/adapters/faraday_spec.rb
99
100
  - spec/typhoeus/config_spec.rb
@@ -142,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  segments:
144
145
  - 0
145
- hash: -1737493821567630899
146
+ hash: 1782230934011170024
146
147
  required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  none: false
148
149
  requirements:
@@ -160,6 +161,7 @@ test_files:
160
161
  - spec/rack/typhoeus/middleware/params_decoder_spec.rb
161
162
  - spec/spec_helper.rb
162
163
  - spec/support/localhost_server.rb
164
+ - spec/support/memory_cache.rb
163
165
  - spec/support/server.rb
164
166
  - spec/typhoeus/adapters/faraday_spec.rb
165
167
  - spec/typhoeus/config_spec.rb