faraday 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +23 -13
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +29 -27
- data/Rakefile +8 -0
- data/config.ru +6 -0
- data/faraday.gemspec +10 -7
- data/lib/faraday.rb +1 -1
- data/lib/faraday/adapter/patron.rb +9 -6
- data/lib/faraday/adapter/test.rb +30 -4
- data/lib/faraday/builder.rb +3 -1
- data/lib/faraday/response.rb +2 -2
- data/lib/faraday/utils.rb +3 -3
- data/test/adapters/live_test.rb +5 -1
- data/test/adapters/test_middleware_test.rb +28 -1
- data/test/helper.rb +4 -8
- data/test/middleware_stack_test.rb +7 -0
- data/test/request_middleware_test.rb +2 -2
- data/test/response_middleware_test.rb +27 -0
- metadata +79 -13
data/Gemfile
CHANGED
@@ -1,19 +1,29 @@
|
|
1
|
-
source
|
1
|
+
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
gem 'addressable', '~> 2.2.6'
|
4
|
+
gem 'multipart-post', '~> 1.1.0'
|
5
|
+
gem 'rack', ['>= 1.1.0', '<= 1.2.0']
|
6
|
+
|
7
|
+
group :development do
|
8
8
|
gem 'sinatra', '~> 1.2'
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem 'em-http-request', '~> 0.3', :require => 'em-http'
|
12
13
|
gem 'em-synchrony', '~> 0.2', :require => ['em-synchrony', 'em-synchrony/em-http'], :platforms => :ruby_19
|
13
|
-
gem '
|
14
|
+
gem 'excon', '~> 0.6'
|
15
|
+
gem 'leftright', '~> 0.9', :require => false
|
16
|
+
gem 'patron', '~> 0.4'
|
17
|
+
gem 'rake', '~> 0.8'
|
18
|
+
gem 'test-unit', '~> 2.3'
|
19
|
+
gem 'typhoeus', '~> 0.2'
|
20
|
+
gem 'webmock', '~> 1.6'
|
14
21
|
# ActiveSupport::JSON will be used in ruby 1.8 and Yajl in 1.9; this is to test against both adapters
|
15
|
-
gem 'activesupport', '~>
|
16
|
-
gem 'yajl-ruby', :require => 'yajl', :platforms => :ruby_19
|
22
|
+
gem 'activesupport', '~> 3.0', :require => nil, :platforms => [:ruby_18, :jruby]
|
23
|
+
gem 'yajl-ruby', '~> 0.8', :require => 'yajl', :platforms => :ruby_19
|
17
24
|
end
|
18
25
|
|
19
|
-
|
26
|
+
platforms :jruby do
|
27
|
+
gem 'jruby-openssl', '~> 0.7'
|
28
|
+
gem 'ffi-ncurses', '~> 0.3'
|
29
|
+
end
|
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
faraday
|
2
|
+
=======
|
3
3
|
Modular HTTP client library using middleware heavily inspired by Rack.
|
4
4
|
|
5
5
|
This mess is gonna get raw, like sushi. So, haters to the left.
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
Usage
|
8
|
+
-----
|
9
9
|
conn = Faraday.new(:url => 'http://sushi.com') do |builder|
|
10
10
|
builder.use Faraday::Request::UrlEncoded # convert request params as "www-form-urlencoded"
|
11
11
|
builder.use Faraday::Request::JSON # encode request params as json
|
@@ -18,23 +18,23 @@ This mess is gonna get raw, like sushi. So, haters to the left.
|
|
18
18
|
builder.response :logger
|
19
19
|
builder.adapter :net_http
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
## GET ##
|
23
23
|
|
24
24
|
response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
|
25
25
|
response.body
|
26
26
|
|
27
27
|
conn.get '/nigiri', 'X-Awesome' => true # custom request header
|
28
|
-
|
28
|
+
|
29
29
|
conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
|
30
30
|
req.url '/search', :page => 2
|
31
31
|
req.params['limit'] = 100
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
## POST ##
|
35
|
-
|
35
|
+
|
36
36
|
conn.post '/nigiri', { :name => 'Maguro' } # POST "name=maguro" to http://sushi.com/nigiri
|
37
|
-
|
37
|
+
|
38
38
|
# post payload as JSON instead of "www-form-urlencoded" encoding:
|
39
39
|
conn.post '/nigiri', payload, 'Content-Type' => 'application/json'
|
40
40
|
|
@@ -50,8 +50,8 @@ If you're ready to roll with just the bare minimum:
|
|
50
50
|
# default stack (net/http), no extra middleware:
|
51
51
|
response = Faraday.get 'http://sushi.com/nigiri/sake.json'
|
52
52
|
|
53
|
-
|
54
|
-
|
53
|
+
Advanced middleware usage
|
54
|
+
-------------------------
|
55
55
|
The order in which middleware is stacked is important. Like with Rack, the first middleware on the list wraps all others, while the last middleware is the innermost one, so that's usually the adapter.
|
56
56
|
|
57
57
|
conn = Faraday.new(:url => 'http://sushi.com') do |builder|
|
@@ -59,7 +59,7 @@ The order in which middleware is stacked is important. Like with Rack, the first
|
|
59
59
|
builder.request :multipart
|
60
60
|
builder.request :url_encoded
|
61
61
|
builder.request :json
|
62
|
-
|
62
|
+
|
63
63
|
builder.adapter :net_http
|
64
64
|
end
|
65
65
|
|
@@ -74,23 +74,23 @@ Because "UrlEncoded" is higher on the stack than JSON encoder, it will get to pr
|
|
74
74
|
Examples:
|
75
75
|
|
76
76
|
payload = { :name => 'Maguro' }
|
77
|
-
|
77
|
+
|
78
78
|
# post payload as JSON instead of urlencoded:
|
79
79
|
conn.post '/nigiri', payload, 'Content-Type' => 'application/json'
|
80
|
-
|
80
|
+
|
81
81
|
# uploading a file:
|
82
82
|
payload = { :profile_pic => Faraday::UploadIO.new('avatar.jpg', 'image/jpeg') }
|
83
|
-
|
83
|
+
|
84
84
|
# "Multipart" middleware detects files and encodes with "multipart/form-data":
|
85
85
|
conn.put '/profile', payload
|
86
86
|
|
87
|
-
|
88
|
-
|
87
|
+
Writing middleware
|
88
|
+
------------------
|
89
89
|
Middleware are classes that respond to `call()`. They wrap the request/response cycle.
|
90
90
|
|
91
91
|
def call(env)
|
92
92
|
# do something with the request
|
93
|
-
|
93
|
+
|
94
94
|
@app.call(env).on_complete do
|
95
95
|
# do something with the response
|
96
96
|
end
|
@@ -111,8 +111,8 @@ The `env` is a hash with symbol keys that contains info about the request and, l
|
|
111
111
|
:body - the response body
|
112
112
|
:response_headers
|
113
113
|
|
114
|
-
|
115
|
-
|
114
|
+
Testing
|
115
|
+
-------
|
116
116
|
# It's possible to define stubbed request outside a test adapter block.
|
117
117
|
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
118
118
|
stub.get('/tamago') { [200, {}, 'egg'] }
|
@@ -138,21 +138,21 @@ The `env` is a hash with symbol keys that contains info about the request and, l
|
|
138
138
|
resp.body # => 'urchin'
|
139
139
|
resp = test.get '/else' #=> raises "no such stub" error
|
140
140
|
|
141
|
-
# If you like, you can treat your stubs as mocks by verifying that all of
|
141
|
+
# If you like, you can treat your stubs as mocks by verifying that all of
|
142
142
|
# the stubbed calls were made. NOTE that this feature is still fairly
|
143
143
|
# experimental: It will not verify the order or count of any stub, only that
|
144
144
|
# it was called once during the course of the test.
|
145
145
|
stubs.verify_stubbed_calls
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
TODO
|
148
|
+
----
|
149
149
|
* support streaming requests/responses
|
150
150
|
* better stubbing API
|
151
151
|
* Support timeouts
|
152
152
|
* Add curb, em-http, fast_http
|
153
153
|
|
154
|
-
|
155
|
-
|
154
|
+
Note on Patches/Pull Requests
|
155
|
+
-----------------------------
|
156
156
|
* Fork the project.
|
157
157
|
* Make your feature addition or bug fix.
|
158
158
|
* Add tests for it. This is important so I don't break it in a
|
@@ -161,6 +161,8 @@ The `env` is a hash with symbol keys that contains info about the request and, l
|
|
161
161
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
162
162
|
* Send me a pull request. Bonus points for topic branches.
|
163
163
|
|
164
|
-
|
164
|
+
Copyright
|
165
|
+
---------
|
166
|
+
Copyright (c) 2009-2011 rick, hobson. See [LICENSE][license] for details.
|
165
167
|
|
166
|
-
|
168
|
+
[license]: https://github.com/technoweenie/faraday/blob/master/LICENSE.md
|
data/Rakefile
CHANGED
@@ -52,6 +52,14 @@ Rake::TestTask.new(:test) do |test|
|
|
52
52
|
test.verbose = true
|
53
53
|
end
|
54
54
|
|
55
|
+
TEST_SERVER = 'http://faradaylive.heroku.com'
|
56
|
+
|
57
|
+
desc "Run tests including live tests against #{TEST_SERVER}"
|
58
|
+
task :"test:live" do
|
59
|
+
ENV['LIVE'] = TEST_SERVER
|
60
|
+
Rake::Task[:test].invoke
|
61
|
+
end
|
62
|
+
|
55
63
|
desc "Open an irb session preloaded with this library"
|
56
64
|
task :console do
|
57
65
|
sh "irb -rubygems -r ./lib/#{name}.rb"
|
data/config.ru
ADDED
data/faraday.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
|
|
12
12
|
## If your rubyforge_project name is different, then edit it and comment out
|
13
13
|
## the sub! line in the Rakefile
|
14
14
|
s.name = 'faraday'
|
15
|
-
s.version = '0.7.
|
16
|
-
s.date = '2011-
|
15
|
+
s.version = '0.7.1'
|
16
|
+
s.date = '2011-06-09'
|
17
17
|
s.rubyforge_project = 'faraday'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
@@ -32,10 +32,12 @@ Gem::Specification.new do |s|
|
|
32
32
|
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
33
33
|
s.require_paths = %w[lib]
|
34
34
|
|
35
|
-
s.add_development_dependency
|
36
|
-
s.
|
37
|
-
s.
|
38
|
-
s.add_runtime_dependency
|
35
|
+
s.add_development_dependency 'rake', '~> 0.9'
|
36
|
+
s.add_development_dependency 'test-unit', '~> 2.3'
|
37
|
+
s.add_development_dependency 'webmock', '~> 1.6'
|
38
|
+
s.add_runtime_dependency 'addressable', '~> 2.2.6'
|
39
|
+
s.add_runtime_dependency 'multipart-post', '~> 1.1.0'
|
40
|
+
s.add_runtime_dependency 'rack', ['>= 1.1.0', '< 2']
|
39
41
|
|
40
42
|
## Leave this section as-is. It will be automatically generated from the
|
41
43
|
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
@@ -43,9 +45,10 @@ Gem::Specification.new do |s|
|
|
43
45
|
# = MANIFEST =
|
44
46
|
s.files = %w[
|
45
47
|
Gemfile
|
46
|
-
LICENSE
|
48
|
+
LICENSE.md
|
47
49
|
README.md
|
48
50
|
Rakefile
|
51
|
+
config.ru
|
49
52
|
faraday.gemspec
|
50
53
|
lib/faraday.rb
|
51
54
|
lib/faraday/adapter.rb
|
data/lib/faraday.rb
CHANGED
@@ -22,12 +22,15 @@ module Faraday
|
|
22
22
|
|
23
23
|
@app.call env
|
24
24
|
end
|
25
|
-
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
if loaded? && defined?(::Patron::Request::VALID_ACTIONS)
|
27
|
+
# HAX: helps but doesn't work completely
|
28
|
+
# https://github.com/toland/patron/issues/34
|
29
|
+
::Patron::Request::VALID_ACTIONS.tap do |actions|
|
30
|
+
actions << :patch unless actions.include? :patch
|
31
|
+
actions << :options unless actions.include? :options
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
32
35
|
end
|
33
36
|
end
|
data/lib/faraday/adapter/test.rb
CHANGED
@@ -17,6 +17,9 @@ module Faraday
|
|
17
17
|
def self.loaded?() false end
|
18
18
|
|
19
19
|
class Stubs
|
20
|
+
class NotFound < StandardError
|
21
|
+
end
|
22
|
+
|
20
23
|
def initialize
|
21
24
|
# {:get => [Stub, Stub]}
|
22
25
|
@stack, @consumed = {}, {}
|
@@ -84,9 +87,29 @@ module Faraday
|
|
84
87
|
end
|
85
88
|
end
|
86
89
|
|
87
|
-
class Stub < Struct.new(:path, :body, :block)
|
88
|
-
def
|
89
|
-
|
90
|
+
class Stub < Struct.new(:path, :params, :body, :block)
|
91
|
+
def initialize(full, body, block)
|
92
|
+
path, query = full.split('?')
|
93
|
+
params = query ?
|
94
|
+
Rack::Utils.parse_nested_query(query) :
|
95
|
+
{}
|
96
|
+
super path, params, body, block
|
97
|
+
end
|
98
|
+
|
99
|
+
def matches?(request_uri, request_body)
|
100
|
+
request_path, request_query = request_uri.split('?')
|
101
|
+
request_params = request_query ?
|
102
|
+
Rack::Utils.parse_nested_query(request_query) :
|
103
|
+
{}
|
104
|
+
request_path == path &&
|
105
|
+
params_match?(request_params) &&
|
106
|
+
(body.to_s.size.zero? || request_body == body)
|
107
|
+
end
|
108
|
+
|
109
|
+
def params_match?(request_params)
|
110
|
+
params.keys.all? do |key|
|
111
|
+
request_params[key] == params[key]
|
112
|
+
end
|
90
113
|
end
|
91
114
|
|
92
115
|
def to_s
|
@@ -109,10 +132,13 @@ module Faraday
|
|
109
132
|
normalized_path = Faraday::Utils.normalize_path(env[:url])
|
110
133
|
|
111
134
|
if stub = stubs.match(env[:method], normalized_path, env[:body])
|
135
|
+
env[:params] = (query = env[:url].query) ?
|
136
|
+
Rack::Utils.parse_nested_query(query) :
|
137
|
+
{}
|
112
138
|
status, headers, body = stub.block.call(env)
|
113
139
|
save_response(env, status, body, headers)
|
114
140
|
else
|
115
|
-
raise "no stubbed request for #{env[:method]} #{normalized_path} #{env[:body]}"
|
141
|
+
raise Stubs::NotFound, "no stubbed request for #{env[:method]} #{normalized_path} #{env[:body]}"
|
116
142
|
end
|
117
143
|
@app.call(env)
|
118
144
|
end
|
data/lib/faraday/builder.rb
CHANGED
data/lib/faraday/response.rb
CHANGED
@@ -14,7 +14,7 @@ module Faraday
|
|
14
14
|
# Calls the `parse` method if defined
|
15
15
|
def on_complete(env)
|
16
16
|
if respond_to? :parse
|
17
|
-
env[:body] = parse(env[:body])
|
17
|
+
env[:body] = parse(env[:body]) unless [204,304].index env[:status]
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -72,7 +72,7 @@ module Faraday
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def success?
|
75
|
-
status
|
75
|
+
(200..299).include?(status)
|
76
76
|
end
|
77
77
|
|
78
78
|
# because @on_complete_callbacks cannot be marshalled
|
data/lib/faraday/utils.rb
CHANGED
@@ -18,7 +18,7 @@ module Faraday
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
KeyMap[:etag] = "ETag"
|
21
|
-
|
21
|
+
|
22
22
|
def [](k)
|
23
23
|
super(KeyMap[k])
|
24
24
|
end
|
@@ -28,9 +28,9 @@ module Faraday
|
|
28
28
|
v = v.to_ary.join(', ') if v.respond_to? :to_ary
|
29
29
|
super(KeyMap[k], v)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
alias_method :update, :merge!
|
33
|
-
|
33
|
+
|
34
34
|
def parse(header_string)
|
35
35
|
return unless header_string && !header_string.empty?
|
36
36
|
header_string.split(/\r\n/).
|
data/test/adapters/live_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
|
2
2
|
|
3
3
|
if !Faraday::TestCase::LIVE_SERVER
|
4
|
-
warn "warning: test server
|
4
|
+
warn "warning: test server not specified; skipping live server tests"
|
5
5
|
else
|
6
6
|
module Adapters
|
7
7
|
class LiveTest < Faraday::TestCase
|
@@ -84,7 +84,11 @@ else
|
|
84
84
|
end
|
85
85
|
assert_equal %({"first"=>"zack"}), resp.body
|
86
86
|
end
|
87
|
+
end
|
87
88
|
|
89
|
+
# https://github.com/toland/patron/issues/9
|
90
|
+
# https://github.com/dbalatero/typhoeus/issues/84
|
91
|
+
if ENV['FORCE'] || !%w[Faraday::Adapter::Patron Faraday::Adapter::Typhoeus].include?(adapter.to_s)
|
88
92
|
define_method "test_#{adapter}_PUT_retrieves_the_response_headers" do
|
89
93
|
assert_match /text\/html/, create_connection(adapter).put('echo_name').headers['content-type']
|
90
94
|
end
|
@@ -27,6 +27,20 @@ module Adapters
|
|
27
27
|
assert_equal 'hello', @conn.get("/hello").body
|
28
28
|
end
|
29
29
|
|
30
|
+
def test_middleware_with_get_params
|
31
|
+
@stubs.get('/param?a=1') { [200, {}, 'a'] }
|
32
|
+
assert_equal 'a', @conn.get('/param?a=1').body
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_middleware_ignores_unspecified_get_params
|
36
|
+
@stubs.get('/optional?a=1') { [200, {}, 'a'] }
|
37
|
+
assert_equal 'a', @conn.get('/optional?a=1&b=1').body
|
38
|
+
assert_equal 'a', @conn.get('/optional?a=1').body
|
39
|
+
assert_raise Faraday::Adapter::Test::Stubs::NotFound do
|
40
|
+
@conn.get('/optional')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
30
44
|
def test_middleware_allow_different_outcomes_for_the_same_request
|
31
45
|
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
|
32
46
|
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'world'] }
|
@@ -34,8 +48,21 @@ module Adapters
|
|
34
48
|
assert_equal 'world', @conn.get("/hello").body
|
35
49
|
end
|
36
50
|
|
51
|
+
def test_yields_env_to_stubs
|
52
|
+
@stubs.get '/hello' do |env|
|
53
|
+
assert_equal '/hello', env[:url].path
|
54
|
+
assert_equal 'foo.com', env[:url].host
|
55
|
+
assert_equal '1', env[:params]['a']
|
56
|
+
assert_equal 'text/plain', env[:request_headers]['Accept']
|
57
|
+
[200, {}, 'a']
|
58
|
+
end
|
59
|
+
|
60
|
+
@conn.headers['Accept'] = 'text/plain'
|
61
|
+
assert_equal 'a', @conn.get('http://foo.com/hello?a=1').body
|
62
|
+
end
|
63
|
+
|
37
64
|
def test_raises_an_error_if_no_stub_is_found_for_request
|
38
|
-
assert_raise
|
65
|
+
assert_raise Faraday::Adapter::Test::Stubs::NotFound do
|
39
66
|
@conn.get('/invalid'){ [200, {}, []] }
|
40
67
|
end
|
41
68
|
end
|
data/test/helper.rb
CHANGED
@@ -1,12 +1,5 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'test/unit'
|
2
|
-
unless ENV['BUNDLE_GEMFILE']
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
5
|
-
Bundler.setup
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'webmock/test_unit'
|
9
|
-
WebMock.disable_net_connect!(:allow_localhost => true)
|
10
3
|
|
11
4
|
if ENV['LEFTRIGHT']
|
12
5
|
begin
|
@@ -43,3 +36,6 @@ module Faraday
|
|
43
36
|
end unless defined? ::MiniTest
|
44
37
|
end
|
45
38
|
end
|
39
|
+
|
40
|
+
require 'webmock/test_unit'
|
41
|
+
WebMock.disable_net_connect!(:allow => Faraday::TestCase::LIVE_SERVER)
|
@@ -87,6 +87,13 @@ class MiddlewareStackTest < Faraday::TestCase
|
|
87
87
|
assert !duped_connection.builder.locked?
|
88
88
|
end
|
89
89
|
|
90
|
+
def test_handler_comparison
|
91
|
+
build_stack Apple
|
92
|
+
assert_equal @builder.handlers.first, Apple
|
93
|
+
assert_equal @builder.handlers[0,1], [Apple]
|
94
|
+
assert_equal @builder.handlers.first, Faraday::Builder::Handler.new(Apple)
|
95
|
+
end
|
96
|
+
|
90
97
|
private
|
91
98
|
|
92
99
|
# make a stack with test adapter that reflects the order of middleware
|
@@ -74,8 +74,8 @@ class RequestMiddlewareTest < Faraday::TestCase
|
|
74
74
|
assert_kind_of Faraday::CompositeReadIO, response.body
|
75
75
|
assert_equal "multipart/form-data;boundary=%s" % Faraday::Request::Multipart::DEFAULT_BOUNDARY,
|
76
76
|
response.headers['Content-Type']
|
77
|
-
|
78
|
-
response.body.send(:ios).map
|
77
|
+
|
78
|
+
response.body.send(:ios).map{|io| io.read}.each do |io|
|
79
79
|
if re = regexes.detect { |r| io =~ r }
|
80
80
|
regexes.delete re
|
81
81
|
end
|
@@ -45,3 +45,30 @@ class ResponseMiddlewareTest < Faraday::TestCase
|
|
45
45
|
assert_equal '<BODY></BODY>', @conn.get('ok').body
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
class ResponseNoBodyMiddleWareTest < Faraday::TestCase
|
50
|
+
def setup
|
51
|
+
@conn = Faraday.new do |b|
|
52
|
+
b.response :raise_error
|
53
|
+
b.adapter :test do |stub|
|
54
|
+
stub.get('not modified') { [304, nil, nil] }
|
55
|
+
stub.get('no content') { [204, nil, nil] }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
@conn.builder.insert(0, NotCalled)
|
59
|
+
end
|
60
|
+
|
61
|
+
class NotCalled < Faraday::Response::Middleware
|
62
|
+
def parse(body)
|
63
|
+
raise "this should not be called"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_204
|
68
|
+
assert_equal nil, @conn.get('no content').body
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_304
|
72
|
+
assert_equal nil, @conn.get('not modified').body
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 7
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Rick Olson
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-06-09 00:00:00 -07:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,45 +26,97 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
24
|
-
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
version: "0.9"
|
25
34
|
type: :development
|
26
35
|
version_requirements: *id001
|
27
36
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
37
|
+
name: test-unit
|
29
38
|
prerelease: false
|
30
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
40
|
none: false
|
32
41
|
requirements:
|
33
42
|
- - ~>
|
34
43
|
- !ruby/object:Gem::Version
|
35
|
-
|
36
|
-
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 3
|
48
|
+
version: "2.3"
|
49
|
+
type: :development
|
37
50
|
version_requirements: *id002
|
38
51
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
52
|
+
name: webmock
|
40
53
|
prerelease: false
|
41
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
55
|
none: false
|
43
56
|
requirements:
|
44
57
|
- - ~>
|
45
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 6
|
63
|
+
version: "1.6"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: addressable
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ~>
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 11
|
75
|
+
segments:
|
76
|
+
- 2
|
77
|
+
- 2
|
78
|
+
- 6
|
79
|
+
version: 2.2.6
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id004
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: multipart-post
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ~>
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
hash: 19
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 1
|
94
|
+
- 0
|
46
95
|
version: 1.1.0
|
47
96
|
type: :runtime
|
48
|
-
version_requirements: *
|
97
|
+
version_requirements: *id005
|
49
98
|
- !ruby/object:Gem::Dependency
|
50
99
|
name: rack
|
51
100
|
prerelease: false
|
52
|
-
requirement: &
|
101
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
53
102
|
none: false
|
54
103
|
requirements:
|
55
104
|
- - ">="
|
56
105
|
- !ruby/object:Gem::Version
|
106
|
+
hash: 19
|
107
|
+
segments:
|
108
|
+
- 1
|
109
|
+
- 1
|
110
|
+
- 0
|
57
111
|
version: 1.1.0
|
58
112
|
- - <
|
59
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 7
|
115
|
+
segments:
|
116
|
+
- 2
|
60
117
|
version: "2"
|
61
118
|
type: :runtime
|
62
|
-
version_requirements: *
|
119
|
+
version_requirements: *id006
|
63
120
|
description: HTTP/REST API client library.
|
64
121
|
email: technoweenie@gmail.com
|
65
122
|
executables: []
|
@@ -70,9 +127,10 @@ extra_rdoc_files: []
|
|
70
127
|
|
71
128
|
files:
|
72
129
|
- Gemfile
|
73
|
-
- LICENSE
|
130
|
+
- LICENSE.md
|
74
131
|
- README.md
|
75
132
|
- Rakefile
|
133
|
+
- config.ru
|
76
134
|
- faraday.gemspec
|
77
135
|
- lib/faraday.rb
|
78
136
|
- lib/faraday/adapter.rb
|
@@ -121,17 +179,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
179
|
requirements:
|
122
180
|
- - ">="
|
123
181
|
- !ruby/object:Gem::Version
|
182
|
+
hash: 3
|
183
|
+
segments:
|
184
|
+
- 0
|
124
185
|
version: "0"
|
125
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
187
|
none: false
|
127
188
|
requirements:
|
128
189
|
- - ">="
|
129
190
|
- !ruby/object:Gem::Version
|
191
|
+
hash: 17
|
192
|
+
segments:
|
193
|
+
- 1
|
194
|
+
- 3
|
195
|
+
- 5
|
130
196
|
version: 1.3.5
|
131
197
|
requirements: []
|
132
198
|
|
133
199
|
rubyforge_project: faraday
|
134
|
-
rubygems_version: 1.
|
200
|
+
rubygems_version: 1.3.7
|
135
201
|
signing_key:
|
136
202
|
specification_version: 2
|
137
203
|
summary: HTTP/REST API client library.
|