faraday 0.8.1 → 0.8.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/Gemfile +3 -3
- data/README.md +73 -52
- data/Rakefile +4 -11
- data/faraday.gemspec +2 -2
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/excon.rb +33 -6
- data/lib/faraday/adapter/net_http.rb +2 -1
- data/lib/faraday/adapter/rack.rb +1 -1
- data/script/test +99 -0
- data/test/adapters/excon_test.rb +1 -14
- data/test/adapters/integration.rb +5 -2
- data/test/adapters/net_http_persistent_test.rb +4 -1
- data/test/adapters/net_http_test.rb +0 -29
- data/test/adapters/rack_test.rb +1 -1
- data/test/helper.rb +25 -9
- data/test/live_server.rb +7 -4
- metadata +4 -20
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
group :development do
|
4
|
-
gem 'sinatra', '~> 1.
|
4
|
+
gem 'sinatra', '~> 1.3'
|
5
5
|
end
|
6
6
|
|
7
7
|
group :test do
|
8
8
|
gem 'em-http-request', '~> 1.0', :require => 'em-http'
|
9
9
|
gem 'em-synchrony', '~> 1.0', :require => ['em-synchrony', 'em-synchrony/em-http'], :platforms => :ruby_19
|
10
|
-
gem 'excon', '
|
10
|
+
gem 'excon', '>= 0.14.1'
|
11
11
|
gem 'net-http-persistent', '~> 2.5', :require => false
|
12
12
|
gem 'leftright', '~> 0.9', :require => false
|
13
13
|
gem 'rack-test', '~> 0.6', :require => 'rack/test'
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
|
16
16
|
platforms :ruby do
|
17
17
|
gem 'patron', '~> 0.4', '> 0.4.1'
|
18
|
-
gem 'typhoeus', '~> 0.3
|
18
|
+
gem 'typhoeus', '~> 0.3.3'
|
19
19
|
end
|
20
20
|
|
21
21
|
platforms :jruby do
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# Faraday
|
2
|
-
[travis]: http://travis-ci.org/technoweenie/faraday
|
3
|
-
[gemnasium]: https://gemnasium.com/technoweenie/faraday
|
1
|
+
# Faraday
|
4
2
|
|
5
3
|
Faraday is an HTTP client lib that provides a common interface over many
|
6
4
|
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when
|
@@ -8,11 +6,11 @@ processing the request/response cycle.
|
|
8
6
|
|
9
7
|
Faraday supports these adapters:
|
10
8
|
|
11
|
-
* Net
|
12
|
-
* Excon
|
13
|
-
* Typhoeus
|
14
|
-
* Patron
|
15
|
-
* EventMachine
|
9
|
+
* Net::HTTP
|
10
|
+
* [Excon][]
|
11
|
+
* [Typhoeus][]
|
12
|
+
* [Patron][]
|
13
|
+
* [EventMachine][]
|
16
14
|
|
17
15
|
It also includes a Rack adapter for hitting loaded Rack applications through
|
18
16
|
Rack::Test, and a Test adapter for stubbing requests by hand.
|
@@ -20,15 +18,10 @@ Rack::Test, and a Test adapter for stubbing requests by hand.
|
|
20
18
|
## Usage
|
21
19
|
|
22
20
|
```ruby
|
23
|
-
conn = Faraday.new(:url => 'http://sushi.com') do |
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
# or, use shortcuts:
|
29
|
-
builder.request :url_encoded
|
30
|
-
builder.response :logger
|
31
|
-
builder.adapter :net_http
|
21
|
+
conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
|
22
|
+
faraday.request :url_encoded # form-encode POST params
|
23
|
+
faraday.response :logger # log requests to STDOUT
|
24
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
32
25
|
end
|
33
26
|
|
34
27
|
## GET ##
|
@@ -36,7 +29,7 @@ end
|
|
36
29
|
response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
|
37
30
|
response.body
|
38
31
|
|
39
|
-
conn.get '/nigiri', { :name => 'Maguro' }
|
32
|
+
conn.get '/nigiri', { :name => 'Maguro' } # GET /nigiri?name=Maguro
|
40
33
|
|
41
34
|
conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
|
42
35
|
req.url '/search', :page => 2
|
@@ -54,7 +47,7 @@ conn.post do |req|
|
|
54
47
|
req.body = '{ "name": "Unagi" }'
|
55
48
|
end
|
56
49
|
|
57
|
-
##
|
50
|
+
## Per-request options ##
|
58
51
|
|
59
52
|
conn.get do |req|
|
60
53
|
req.url '/search'
|
@@ -63,25 +56,26 @@ conn.get do |req|
|
|
63
56
|
end
|
64
57
|
```
|
65
58
|
|
66
|
-
If you'
|
59
|
+
If you don't need to set up anything, you can roll with just the bare minimum:
|
67
60
|
|
68
61
|
```ruby
|
69
|
-
# default stack
|
62
|
+
# using the default stack:
|
70
63
|
response = Faraday.get 'http://sushi.com/nigiri/sake.json'
|
71
64
|
```
|
72
65
|
|
73
66
|
## Advanced middleware usage
|
67
|
+
|
74
68
|
The order in which middleware is stacked is important. Like with Rack, the
|
75
69
|
first middleware on the list wraps all others, while the last middleware is the
|
76
|
-
innermost one, so that
|
70
|
+
innermost one, so that must be the adapter.
|
77
71
|
|
78
72
|
```ruby
|
79
|
-
|
73
|
+
Faraday.new(...) do |conn|
|
80
74
|
# POST/PUT params encoders:
|
81
|
-
|
82
|
-
|
75
|
+
conn.request :multipart
|
76
|
+
conn.request :url_encoded
|
83
77
|
|
84
|
-
|
78
|
+
conn.adapter :net_http
|
85
79
|
end
|
86
80
|
```
|
87
81
|
|
@@ -99,18 +93,17 @@ process it.
|
|
99
93
|
Examples:
|
100
94
|
|
101
95
|
```ruby
|
102
|
-
payload = { :name => 'Maguro' }
|
103
|
-
|
104
96
|
# uploading a file:
|
105
|
-
payload
|
97
|
+
payload[:profile_pic] = Faraday::UploadIO.new('/path/to/avatar.jpg', 'image/jpeg')
|
106
98
|
|
107
99
|
# "Multipart" middleware detects files and encodes with "multipart/form-data":
|
108
100
|
conn.put '/profile', payload
|
109
101
|
```
|
110
102
|
|
111
103
|
## Writing middleware
|
112
|
-
|
113
|
-
|
104
|
+
|
105
|
+
Middleware are classes that implement a `call` instance method. They hook into
|
106
|
+
the request/response cycle.
|
114
107
|
|
115
108
|
```ruby
|
116
109
|
def call(env)
|
@@ -142,7 +135,7 @@ later, response. Some keys are:
|
|
142
135
|
:response_headers
|
143
136
|
```
|
144
137
|
|
145
|
-
##
|
138
|
+
## Using Faraday for testing
|
146
139
|
|
147
140
|
```ruby
|
148
141
|
# It's possible to define stubbed request outside a test adapter block.
|
@@ -178,36 +171,51 @@ stubs.verify_stubbed_calls
|
|
178
171
|
```
|
179
172
|
|
180
173
|
## TODO
|
174
|
+
|
181
175
|
* support streaming requests/responses
|
182
176
|
* better stubbing API
|
183
177
|
|
184
|
-
##
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
178
|
+
## Contributing
|
179
|
+
|
180
|
+
You can run the test suite against a live server by running `script/test`. It
|
181
|
+
automatically starts a test server in background. Only tests in
|
182
|
+
`test/adapters/*_test.rb` require a server, though.
|
183
|
+
|
184
|
+
``` sh
|
185
|
+
# run the whole suite
|
186
|
+
$ script/test
|
187
|
+
|
188
|
+
# run only specific files
|
189
|
+
$ script/test excon typhoeus
|
190
|
+
```
|
191
|
+
|
192
|
+
We will accept middleware that:
|
193
|
+
|
194
|
+
1. is useful to a broader audience, but can be implemented relatively
|
195
|
+
simple; and
|
196
|
+
2. which isn't already present in [faraday_middleware][] project.
|
197
|
+
|
198
|
+
We will accept adapters that:
|
199
|
+
|
200
|
+
1. support SSL & streaming;
|
201
|
+
1. are proven and may have better performance than existing ones; or
|
202
|
+
2. if they have features not present in included adapters.
|
193
203
|
|
194
204
|
We are pushing towards a 1.0 release, when we will have to follow [Semantic
|
195
|
-
Versioning]
|
196
|
-
|
205
|
+
Versioning][semver]. If your patch includes changes to break compatiblitity,
|
206
|
+
note that so we can add it to the [Changelog][].
|
207
|
+
|
208
|
+
## Supported Ruby versions
|
197
209
|
|
198
|
-
## Supported Ruby Versions
|
199
210
|
This library aims to support and is [tested against][travis] the following Ruby
|
200
211
|
implementations:
|
201
212
|
|
202
|
-
*
|
203
|
-
*
|
204
|
-
*
|
205
|
-
* JRuby[]
|
213
|
+
* MRI 1.8.7
|
214
|
+
* MRI 1.9.2
|
215
|
+
* MRI 1.9.3
|
216
|
+
* [JRuby][]
|
206
217
|
* [Rubinius][]
|
207
218
|
|
208
|
-
[jruby]: http://jruby.org/
|
209
|
-
[rubinius]: http://rubini.us/
|
210
|
-
|
211
219
|
If something doesn't work on one of these interpreters, it should be considered
|
212
220
|
a bug.
|
213
221
|
|
@@ -223,7 +231,20 @@ timely fashion. If critical issues for a particular implementation exist at the
|
|
223
231
|
time of a major release, support for that Ruby version may be dropped.
|
224
232
|
|
225
233
|
## Copyright
|
234
|
+
|
226
235
|
Copyright (c) 2009-2012 [Rick Olson](mailto:technoweenie@gmail.com), zack hobson.
|
227
236
|
See [LICENSE][] for details.
|
228
237
|
|
229
|
-
|
238
|
+
|
239
|
+
[license]: https://github.com/technoweenie/faraday/blob/master/LICENSE.md
|
240
|
+
[travis]: http://travis-ci.org/technoweenie/faraday
|
241
|
+
[jruby]: http://jruby.org/
|
242
|
+
[rubinius]: http://rubini.us/
|
243
|
+
[semver]: http://semver.org/
|
244
|
+
[changelog]: https://github.com/technoweenie/faraday/wiki/Changelog
|
245
|
+
[excon]: https://github.com/geemus/excon#readme
|
246
|
+
[typhoeus]: https://github.com/typhoeus/typhoeus#readme
|
247
|
+
[patron]: http://toland.github.com/patron/
|
248
|
+
|
249
|
+
[eventmachine]: https://github.com/igrigorik/em-http-request#readme
|
250
|
+
[faraday_middleware]: https://github.com/pengwynn/faraday_middleware/wiki
|
data/Rakefile
CHANGED
@@ -28,16 +28,9 @@ end
|
|
28
28
|
|
29
29
|
## standard tasks
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
|
37
|
-
desc "Run tests including live tests against a local server on port 4567"
|
38
|
-
task :"test:local" do
|
39
|
-
ENV['LIVE'] = '1'
|
40
|
-
Rake::Task[:test].invoke
|
31
|
+
desc "Run all tests"
|
32
|
+
task :test do
|
33
|
+
exec 'script/test'
|
41
34
|
end
|
42
35
|
|
43
36
|
desc "Open an irb session preloaded with this library"
|
@@ -51,7 +44,7 @@ desc "Commit, create tag v#{version} and build and push #{gem_file} to Rubygems"
|
|
51
44
|
task :release => :build do
|
52
45
|
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
53
46
|
sh "git tag v#{version}"
|
54
|
-
sh "git push origin
|
47
|
+
sh "git push origin"
|
55
48
|
sh "git push origin v#{version}"
|
56
49
|
sh "gem push pkg/#{gem_file}"
|
57
50
|
end
|
data/faraday.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'faraday'
|
6
|
-
s.version = '0.8.
|
6
|
+
s.version = '0.8.2'
|
7
7
|
|
8
8
|
s.summary = "HTTP/REST API client library."
|
9
9
|
# TODO: s.description
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.add_development_dependency 'rake'
|
17
17
|
s.add_development_dependency 'simplecov'
|
18
18
|
s.add_development_dependency 'test-unit'
|
19
|
-
s.add_development_dependency 'webmock'
|
20
19
|
|
21
20
|
# = MANIFEST =
|
22
21
|
s.files = %w[
|
@@ -54,6 +53,7 @@ Gem::Specification.new do |s|
|
|
54
53
|
lib/faraday/response/raise_error.rb
|
55
54
|
lib/faraday/upload_io.rb
|
56
55
|
lib/faraday/utils.rb
|
56
|
+
script/test
|
57
57
|
test/adapters/default_test.rb
|
58
58
|
test/adapters/em_http_test.rb
|
59
59
|
test/adapters/em_synchrony_test.rb
|
data/lib/faraday.rb
CHANGED
@@ -6,22 +6,49 @@ module Faraday
|
|
6
6
|
def call(env)
|
7
7
|
super
|
8
8
|
|
9
|
-
|
9
|
+
opts = {}
|
10
10
|
if env[:url].scheme == 'https' && ssl = env[:ssl]
|
11
|
-
|
12
|
-
|
11
|
+
opts[:ssl_verify_peer] = !!ssl.fetch(:verify, true)
|
12
|
+
opts[:ssl_ca_path] = ssl[:ca_path] if ssl[:ca_path]
|
13
|
+
opts[:ssl_ca_file] = ssl[:ca_file] if ssl[:ca_file]
|
13
14
|
end
|
14
15
|
|
16
|
+
if ( req = env[:request] )
|
17
|
+
if req[:timeout]
|
18
|
+
opts[:read_timeout] = req[:timeout]
|
19
|
+
opts[:connect_timeout] = req[:timeout]
|
20
|
+
opts[:write_timeout] = req[:timeout]
|
21
|
+
end
|
22
|
+
|
23
|
+
if req[:open_timeout]
|
24
|
+
opts[:connect_timeout] = req[:open_timeout]
|
25
|
+
opts[:write_timeout] = req[:open_timeout]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
conn = ::Excon.new(env[:url].to_s, opts)
|
30
|
+
|
15
31
|
resp = conn.request \
|
16
32
|
:method => env[:method].to_s.upcase,
|
17
33
|
:headers => env[:request_headers],
|
18
|
-
:body => env
|
34
|
+
:body => read_body(env)
|
19
35
|
|
20
36
|
save_response(env, resp.status.to_i, resp.body, resp.headers)
|
21
37
|
|
22
38
|
@app.call env
|
23
|
-
rescue ::Excon::Errors::SocketError
|
24
|
-
|
39
|
+
rescue ::Excon::Errors::SocketError => err
|
40
|
+
if err.message =~ /\btimeout\b/
|
41
|
+
raise Error::TimeoutError, err
|
42
|
+
else
|
43
|
+
raise Error::ConnectionFailed, err
|
44
|
+
end
|
45
|
+
rescue ::Excon::Errors::Timeout => err
|
46
|
+
raise Error::TimeoutError, err
|
47
|
+
end
|
48
|
+
|
49
|
+
# TODO: support streaming requests
|
50
|
+
def read_body(env)
|
51
|
+
env[:body].respond_to?(:read) ? env[:body].read : env[:body]
|
25
52
|
end
|
26
53
|
end
|
27
54
|
end
|
data/lib/faraday/adapter/rack.rb
CHANGED
data/script/test
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby -rubygems -w
|
2
|
+
# Runs the test suite against a local server spawned automatically in a
|
3
|
+
# thread. After tests are done, the server is shut down.
|
4
|
+
#
|
5
|
+
# If filename arguments are given, only those files are run. If arguments given
|
6
|
+
# are not filenames, they are taken as words that filter the list of files to run.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# $ script/test
|
11
|
+
# $ script/test test/env_test.rb
|
12
|
+
# $ script/test excon typhoeus
|
13
|
+
|
14
|
+
require 'bundler'
|
15
|
+
begin
|
16
|
+
Bundler.setup
|
17
|
+
rescue Bundler::GemNotFound
|
18
|
+
$stderr.print "Error: "
|
19
|
+
$stderr.puts $!.message
|
20
|
+
warn "Run `bundle install` to install missing gems."
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
host = '127.0.0.1'
|
25
|
+
logfile = 'log/test.log'
|
26
|
+
test_glob = 'test/**/*_test.rb'
|
27
|
+
|
28
|
+
require 'fileutils'
|
29
|
+
FileUtils.mkdir_p 'log'
|
30
|
+
|
31
|
+
# find available port
|
32
|
+
require 'socket'
|
33
|
+
port = begin
|
34
|
+
server = TCPServer.new(host, 0)
|
35
|
+
server.addr[1]
|
36
|
+
ensure
|
37
|
+
server.close if server
|
38
|
+
end
|
39
|
+
|
40
|
+
server = nil
|
41
|
+
|
42
|
+
# start test server in a separate thread
|
43
|
+
thread = Thread.new do
|
44
|
+
old_verbose, $VERBOSE = $VERBOSE, nil
|
45
|
+
begin
|
46
|
+
require File.expand_path('../../test/live_server', __FILE__)
|
47
|
+
ensure
|
48
|
+
$VERBOSE = old_verbose
|
49
|
+
end
|
50
|
+
require 'webrick'
|
51
|
+
log_io = File.open logfile, 'w'
|
52
|
+
webrick_opts = {
|
53
|
+
:Port => port, :Logger => WEBrick::Log::new(log_io),
|
54
|
+
:AccessLog => [[log_io, "[%{X-Faraday-Adapter}i] %m %U -> %s %b"]]
|
55
|
+
}
|
56
|
+
Rack::Handler::WEBrick.run(Faraday::LiveServer, webrick_opts) {|serv| server = serv }
|
57
|
+
end
|
58
|
+
|
59
|
+
# find files to test
|
60
|
+
test_files = Dir[test_glob]
|
61
|
+
if ARGV.any?
|
62
|
+
all_files, test_files = test_files, []
|
63
|
+
args, extra_args = ARGV, []
|
64
|
+
if idx = args.index('--')
|
65
|
+
extra_args = args[(idx+1)..-1]
|
66
|
+
args = args[0, idx]
|
67
|
+
end
|
68
|
+
for arg in args
|
69
|
+
re = /(\b|_)#{arg}(\b|_)/
|
70
|
+
test_files.concat all_files.select { |f| f =~ re }
|
71
|
+
end
|
72
|
+
test_files.concat extra_args
|
73
|
+
end
|
74
|
+
|
75
|
+
require 'net/http'
|
76
|
+
conn = Net::HTTP.new host, port
|
77
|
+
conn.open_timeout = conn.read_timeout = 0.05
|
78
|
+
|
79
|
+
# test if test server is accepting requests
|
80
|
+
responsive = lambda { |path|
|
81
|
+
begin
|
82
|
+
res = conn.start { conn.get(path) }
|
83
|
+
res.is_a?(Net::HTTPSuccess)
|
84
|
+
rescue Errno::ECONNREFUSED, Errno::EBADF, Timeout::Error
|
85
|
+
false
|
86
|
+
end
|
87
|
+
}
|
88
|
+
|
89
|
+
require 'timeout'
|
90
|
+
Timeout.timeout 40 do
|
91
|
+
# block until test server is ready
|
92
|
+
thread.join 0.05 until responsive.call('/echo')
|
93
|
+
end
|
94
|
+
|
95
|
+
ENV['LIVE'] = "http://#{host}:#{port}"
|
96
|
+
system 'ruby', '-Ilib:test', '-S', 'testrb', *test_files
|
97
|
+
|
98
|
+
server.respond_to?(:stop!) ? server.stop! : server.stop
|
99
|
+
thread.join
|
data/test/adapters/excon_test.rb
CHANGED
@@ -5,19 +5,6 @@ module Adapters
|
|
5
5
|
|
6
6
|
def adapter() :excon end
|
7
7
|
|
8
|
-
|
9
|
-
if defined?(RUBY_ENGINE) and "rbx" == RUBY_ENGINE
|
10
|
-
warn "Warning: Skipping Excon tests on Rubinius"
|
11
|
-
else
|
12
|
-
Integration.apply(self, :NonParallel) do
|
13
|
-
# https://github.com/eventmachine/eventmachine/pull/289
|
14
|
-
undef :test_timeout
|
15
|
-
|
16
|
-
# FIXME: this test fails on Travis with
|
17
|
-
# "Faraday::Error::ClientError: the server responded with status 400"
|
18
|
-
undef :test_POST_sends_files if ENV['CI']
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
8
|
+
Integration.apply(self, :NonParallel)
|
22
9
|
end
|
23
10
|
end
|
@@ -8,7 +8,7 @@ module Adapters
|
|
8
8
|
# `#adapter_options` optional. extra arguments for building an adapter
|
9
9
|
module Integration
|
10
10
|
def self.apply(base, *extras)
|
11
|
-
if
|
11
|
+
if base.live_server?
|
12
12
|
([:Common] + extras).each {|name| base.send(:include, self.const_get(name)) }
|
13
13
|
yield if block_given?
|
14
14
|
elsif !defined? @warned
|
@@ -179,7 +179,10 @@ module Adapters
|
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
server = self.class.live_server
|
183
|
+
url = 'http://%s:%d' % [server.host, server.port]
|
184
|
+
|
185
|
+
Faraday::Connection.new(url, options, &builder_block).tap do |conn|
|
183
186
|
conn.headers['X-Faraday-Adapter'] = adapter.to_s
|
184
187
|
adapter_handler = conn.builder.handlers.last
|
185
188
|
conn.builder.insert_before adapter_handler, Faraday::Response::RaiseError
|
@@ -10,35 +10,6 @@ module Adapters
|
|
10
10
|
|
11
11
|
Integration.apply(self, *behaviors)
|
12
12
|
|
13
|
-
def test_connection_errors_get_wrapped
|
14
|
-
connection = Faraday.new('http://disney.com') do |b|
|
15
|
-
b.adapter :net_http
|
16
|
-
end
|
17
|
-
|
18
|
-
exceptions = [
|
19
|
-
EOFError,
|
20
|
-
Errno::ECONNABORTED,
|
21
|
-
Errno::ECONNREFUSED,
|
22
|
-
Errno::ECONNRESET,
|
23
|
-
Errno::EINVAL,
|
24
|
-
Net::HTTPBadResponse,
|
25
|
-
Net::HTTPHeaderSyntaxError,
|
26
|
-
Net::ProtocolError,
|
27
|
-
SocketError
|
28
|
-
]
|
29
|
-
|
30
|
-
exceptions << OpenSSL::SSL::SSLError if defined?(OpenSSL)
|
31
|
-
|
32
|
-
exceptions.each do |exception_class|
|
33
|
-
stub_request(:get, 'disney.com/hello').to_raise(exception_class)
|
34
|
-
|
35
|
-
assert_raise(Faraday::Error::ConnectionFailed,
|
36
|
-
"Failed to wrap #{exception_class} exceptions") do
|
37
|
-
connection.get('/hello')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
13
|
def test_configure_ssl
|
43
14
|
http = Net::HTTP.new 'disney.com', 443
|
44
15
|
# this should not raise an error
|
data/test/adapters/rack_test.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -9,7 +9,6 @@ unless ENV['CI']
|
|
9
9
|
end
|
10
10
|
|
11
11
|
require 'test/unit'
|
12
|
-
require 'stringio'
|
13
12
|
|
14
13
|
if ENV['LEFTRIGHT']
|
15
14
|
begin
|
@@ -29,14 +28,34 @@ else
|
|
29
28
|
Debugger.start
|
30
29
|
end
|
31
30
|
|
31
|
+
require 'stringio'
|
32
|
+
require 'uri'
|
33
|
+
|
32
34
|
module Faraday
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
when
|
37
|
-
|
35
|
+
module LiveServerConfig
|
36
|
+
def live_server=(value)
|
37
|
+
@@live_server = case value
|
38
|
+
when /^http/
|
39
|
+
URI(value)
|
40
|
+
when /./
|
41
|
+
URI('http://127.0.0.1:4567')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def live_server?
|
46
|
+
defined? @@live_server
|
38
47
|
end
|
39
48
|
|
49
|
+
# Returns an object that responds to `host` and `port`.
|
50
|
+
def live_server
|
51
|
+
live_server? and @@live_server
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class TestCase < Test::Unit::TestCase
|
56
|
+
extend LiveServerConfig
|
57
|
+
self.live_server = ENV['LIVE']
|
58
|
+
|
40
59
|
def test_default
|
41
60
|
assert true
|
42
61
|
end unless defined? ::MiniTest
|
@@ -52,6 +71,3 @@ module Faraday
|
|
52
71
|
end
|
53
72
|
end
|
54
73
|
end
|
55
|
-
|
56
|
-
require 'webmock/test_unit'
|
57
|
-
WebMock.disable_net_connect!(:allow => Faraday::TestCase::LIVE_SERVER)
|
data/test/live_server.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Faraday
|
4
|
+
class LiveServer < Sinatra::Base
|
5
|
+
set :environment, :test
|
6
|
+
disable :logging
|
7
|
+
disable :protection
|
6
8
|
|
7
9
|
[:get, :post, :put, :patch, :delete, :options].each do |method|
|
8
10
|
send(method, '/echo') do
|
@@ -44,7 +46,8 @@ class FaradayTestServer < Sinatra::Base
|
|
44
46
|
"#{e.class}\n#{e.to_s}\n#{e.backtrace.join("\n")}"
|
45
47
|
end
|
46
48
|
end
|
49
|
+
end
|
47
50
|
|
48
51
|
if $0 == __FILE__
|
49
|
-
|
52
|
+
Faraday::LiveServer.run!
|
50
53
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multipart-post
|
@@ -75,22 +75,6 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: webmock
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
78
|
description:
|
95
79
|
email: technoweenie@gmail.com
|
96
80
|
executables: []
|
@@ -131,6 +115,7 @@ files:
|
|
131
115
|
- lib/faraday/response/raise_error.rb
|
132
116
|
- lib/faraday/upload_io.rb
|
133
117
|
- lib/faraday/utils.rb
|
118
|
+
- script/test
|
134
119
|
- test/adapters/default_test.rb
|
135
120
|
- test/adapters/em_http_test.rb
|
136
121
|
- test/adapters/em_synchrony_test.rb
|
@@ -172,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
157
|
version: 1.3.5
|
173
158
|
requirements: []
|
174
159
|
rubyforge_project:
|
175
|
-
rubygems_version: 1.8.
|
160
|
+
rubygems_version: 1.8.23
|
176
161
|
signing_key:
|
177
162
|
specification_version: 2
|
178
163
|
summary: HTTP/REST API client library.
|
@@ -198,4 +183,3 @@ test_files:
|
|
198
183
|
- test/middleware_stack_test.rb
|
199
184
|
- test/request_middleware_test.rb
|
200
185
|
- test/response_middleware_test.rb
|
201
|
-
has_rdoc:
|