typhoeus 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTgwYWYyZmI1ZTkxMWMxZjM3MTQ2ZmE1OTJkMGJlMTJkNjQ1NWQ0Yg==
4
+ OTdmYmRhNGQwNjM5YzJiMjI4NzljODU0ODRjMzhjZjgwYTllOGM1MA==
5
5
  data.tar.gz: !binary |-
6
- NjU1MTA2N2IxOGJhNWVmNWYwMGFjMTNhNjc2YTcyOWQ5MzFlMDljNw==
6
+ NTc5MzlkNmIyM2VmYTdlMmMzNzM0OTFkN2QwNGIyY2I2YTNhZDg3NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzZmYjAyZTYxZDIwMjQyN2NhMmViNTE1ZjliNjI3OGU4MzEwNzYwMTMxZjEy
10
- MWY1NDRjOWQyODZjMDRmYWVkMjIyOGU3ZGJiMjM5YmM5ZDI1YjFkODc1NWZm
11
- YWY1YmZjYjliZWMzYzY3NDc1YzI5ZWRjYjA0Y2RmZDMxNmIzMDA=
9
+ YzlhNjk0NjRmYmFkZjI0NjUwYmZmNzEzYzM0MjIxN2FiMjJlYzI0YjFlMzVl
10
+ ZDZjZWQ5ZGUzODg5YTljZWJmMjNiOWYwZTUyNmU3N2QzOGQ3YjQ5M2VlMTky
11
+ NmExOTZiMDAyYmYyYjJlNjc1MDk1Njg1MGY1ODU5MmI5MmI2ZjY=
12
12
  data.tar.gz: !binary |-
13
- ZGY3YTM2NjQyOGFkZjJiMDI4MWZlODUyYTI2YzFiMmM4MTZmYThkODAyODE3
14
- OWQ0YmJkYTVhNzFiNzk4ZTdjNTNhMDFhYjAwZDg3ZGJjYzMxNzJhYTQxMjhh
15
- NWMyOTBkNzM1ZTc3ZTZhZGI5ZjcwNGM5ZDM0ZmQ3NWM5MjM3OGY=
13
+ ODA0MTQxYzE5YTczYmRlNDE2ZTZiZDIxODJmZDYwMjg4OWE1ODAyNmQzNTFj
14
+ OWU1OWU3NjZmZTllMGUzMTNmZmY1Yjg1MDMyYWYwZjk0YzYzNWJmYmJjMjE3
15
+ Yjc3NjVkYmUwZGNkZGM2OWJjMmQ1MmM4ZTExNTA5MzY3NjYxYWQ=
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## Master
4
+
5
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.7.2...master)
6
+
7
+ ## 0.7.2
8
+
9
+ [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.7.1...v0.7.2)
10
+
11
+ * Allow arrays to be passed to Expectation#and_return
12
+ ([JP Moral](https://github.com/jpmoral))
13
+
14
+ * Added getter for `redirect_time` value.
15
+ ([Adrien Jarthon](https://github.com/jarthod))
16
+
3
17
  ## 0.7.1
4
18
 
5
19
  [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.7.0...v0.7.1)
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gemspec
4
4
  gem "rake"
5
5
 
6
6
  group :development, :test do
7
- gem "rspec", "~> 2.11"
7
+ gem "rspec", "~> 3.0"
8
8
 
9
9
  gem "sinatra", "~> 1.3"
10
10
  gem "json"
data/README.md CHANGED
@@ -2,6 +2,16 @@
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
 
5
+ # Typhoeus needs your help!
6
+
7
+ I don't have enough time, but I think this is a nice project! If you or your company is using Typhoeus you should help keeping it alive! Pick any of:
8
+
9
+ * add docs
10
+ * respond to issues
11
+ * add features
12
+
13
+ Or send me an email! I would be more than happy to help getting you up to speed!
14
+
5
15
  ## Example
6
16
 
7
17
  A single request:
@@ -54,6 +64,24 @@ The options are all optional. The default for `:method` is `:get`.
54
64
 
55
65
  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
66
 
67
+ #### Sending requests through the proxy
68
+
69
+ Add a proxy url to the list of options:
70
+
71
+ ```ruby
72
+ options = {proxy: 'http://myproxy.org'}
73
+ req = Typhoeus::Request.new(url, options)
74
+ ```
75
+
76
+ If your proxy requires authentication, add it with `proxyuserpwd` option key:
77
+
78
+ ```ruby
79
+ options = {proxy: 'http://proxyurl.com', proxyuserpwd: 'user:password'}
80
+ req = Typhoeus::Request.new(url, options)
81
+ ```
82
+
83
+ Note that `proxyuserpwd` is a colon-separated username and password, in the vein of basic auth `userpwd` option.
84
+
57
85
 
58
86
  You can run the query either on its own or through the hydra:
59
87
 
@@ -91,6 +119,14 @@ Typhoeus.post("www.example.com/posts", body: { title: "test post", content: "thi
91
119
  Typhoeus.delete("www.example.com/posts/1")
92
120
  Typhoeus.options("www.example.com")
93
121
  ```
122
+ #### Sending params in the body with PUT
123
+ When using POST the content-type is set automatically to 'application/x-www-form-urlencoded'. That's not the case for any other method like PUT, PATCH, HEAD and so on, irrespective of whether you are using body or not. To get the same result as POST, i.e. a hash in the body coming through as params in the receiver, you need to set the content-type as shown below:
124
+ ```ruby
125
+ Typhoeus.put("www.example.com/posts/1",
126
+ headers: {'Content-Type'=> "application/x-www-form-urlencoded"},
127
+ body: {title:"test post updated title", content: "this is my updated content"}
128
+ )
129
+ ```
94
130
 
95
131
  ### Handling HTTP errors
96
132
 
@@ -337,6 +373,15 @@ Typhoeus.get("www.example.com") == response
337
373
  #=> true
338
374
  ```
339
375
 
376
+ You may also specify an array for the stub to return sequentially.
377
+
378
+ ```ruby
379
+ Typhoeus.stub('www.example.com').and_return([response1, response2])
380
+
381
+ Typhoeus.get('www.example.com') == response1 #=> true
382
+ Typhoeus.get('www.example.com') == response2 #=> true
383
+ ```
384
+
340
385
  When testing make sure to clear your expectations or the stubs will persist between tests. The following can be included in your spec_helper.rb file to do this automatically.
341
386
 
342
387
  ```ruby
@@ -128,7 +128,7 @@ module Faraday # :nodoc:
128
128
  proxy = env[:request][:proxy]
129
129
  return unless proxy
130
130
 
131
- req.options[:proxy] = "#{proxy[:uri].host}:#{proxy[:uri].port}"
131
+ req.options[:proxy] = "#{proxy[:uri].scheme}://#{proxy[:uri].host}:#{proxy[:uri].port}"
132
132
 
133
133
  if proxy[:user] && proxy[:password]
134
134
  req.options[:proxyuserpwd] = "#{proxy[:user]}:#{proxy[:password]}"
@@ -136,7 +136,8 @@ module Typhoeus
136
136
  #
137
137
  # @return [ void ]
138
138
  def and_return(response=nil, &block)
139
- responses << (response.nil? ? block : response)
139
+ new_response = (response.nil? ? block : response)
140
+ responses.push *new_response
140
141
  end
141
142
 
142
143
  # Checks whether this expectation matches
@@ -205,7 +206,7 @@ module Typhoeus
205
206
  when String
206
207
  base_url == request_url
207
208
  when Regexp
208
- !!request_url.match(base_url)
209
+ base_url === request_url
209
210
  when nil
210
211
  true
211
212
  else
@@ -18,7 +18,7 @@ module Typhoeus
18
18
  # request.on_complete { |response| p 2 }
19
19
  # request.on_complete.clear
20
20
  # request.execute_callbacks
21
- # #=> []
21
+ # #=> nil
22
22
  #
23
23
  # @note If you're using the Hydra to execute multiple
24
24
  # requests, then callbacks are delaying the
@@ -124,7 +124,7 @@ module Typhoeus
124
124
  callbacks += Typhoeus.on_failure + on_failure
125
125
  end
126
126
 
127
- callbacks.map do |callback|
127
+ callbacks.each do |callback|
128
128
  self.response.handled_response = callback.call(self.response)
129
129
  end
130
130
  end
@@ -160,6 +160,19 @@ module Typhoeus
160
160
  end
161
161
  alias :name_lookup_time :namelookup_time
162
162
 
163
+ # Return the time, in seconds, it took for all redirection steps
164
+ # include name lookup, connect, pretransfer and transfer before the
165
+ # final transaction was started. time_redirect shows the complete
166
+ # execution time for multiple redirections.
167
+ #
168
+ # @example Get redirect_time.
169
+ # response.redirect_time
170
+ #
171
+ # @return [ Float ] The redirect_time.
172
+ def redirect_time
173
+ options[:redirect_time]
174
+ end
175
+
163
176
  # Return the last used effective url.
164
177
  #
165
178
  # @example Get effective_url.
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.2'
5
5
  end
@@ -159,16 +159,16 @@ describe Faraday::Adapter::Typhoeus do
159
159
  before { adapter.method(:configure_proxy).call(request, env) }
160
160
 
161
161
  context "when proxy" do
162
- let(:env) { { :request => { :proxy => { :uri => double(:host => "localhost", :port => "3001") } } } }
162
+ let(:env) { { :request => { :proxy => { :uri => double(:scheme => 'http', :host => "localhost", :port => "3001") } } } }
163
163
 
164
164
  it "sets proxy" do
165
- expect(request.options[:proxy]).to eq("localhost:3001")
165
+ expect(request.options[:proxy]).to eq("http://localhost:3001")
166
166
  end
167
167
 
168
168
  context "when username and password" do
169
169
  let(:env) do
170
170
  { :request => { :proxy => {
171
- :uri => double(:host => :a, :port => :b),
171
+ :uri => double(:scheme => 'http', :host => :a, :port => :b),
172
172
  :user => "a",
173
173
  :password => "b"
174
174
  } } }
@@ -88,7 +88,6 @@ describe Typhoeus::Expectation do
88
88
 
89
89
  context "when array" do
90
90
  it "adds to responses" do
91
- skip
92
91
  expectation.and_return([1, 2])
93
92
  expect(expectation.responses).to eq([1, 2])
94
93
  end
@@ -201,6 +200,14 @@ describe Typhoeus::Expectation do
201
200
  it "returns false" do
202
201
  expect(url_match).to be_falsey
203
202
  end
203
+
204
+ context "with nil request_url" do
205
+ let(:request_url) { nil }
206
+
207
+ it "returns false" do
208
+ expect(url_match).to be_falsey
209
+ end
210
+ end
204
211
  end
205
212
  end
206
213
 
@@ -5,8 +5,6 @@ describe Typhoeus::Request::Marshal do
5
5
  let(:request) { Typhoeus::Request.new(base_url) }
6
6
 
7
7
  describe "#marshal_dump" do
8
- let(:base_url) { "http://www.google.com" }
9
-
10
8
  %w(on_complete on_success on_failure).each do |name|
11
9
  context "when #{name} handler" do
12
10
  before { request.instance_variable_set("@#{name}", Proc.new{}) }
@@ -152,6 +152,14 @@ describe Typhoeus::Response::Informations do
152
152
  end
153
153
  end
154
154
 
155
+ describe "#redirect_time" do
156
+ let(:options) { { :redirect_time => 1 } }
157
+
158
+ it "returns redirect_time from options" do
159
+ expect(response.redirect_time).to eq(1)
160
+ end
161
+ end
162
+
155
163
  describe "#effective_url" do
156
164
  let(:options) { { :effective_url => "http://www.example.com" } }
157
165
 
@@ -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.7.1"])
20
+ s.add_dependency('ethon', [">= 0.7.4"])
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.7.1
4
+ version: 0.7.2
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: 2015-01-29 00:00:00.000000000 Z
13
+ date: 2015-06-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ethon
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.7.1
21
+ version: 0.7.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ! '>='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.7.1
28
+ version: 0.7.4
29
29
  description: Like a modern code version of the mythical beast with 100 serpent heads,
30
30
  Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
31
31
  email: