mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-08 00:03:41 -04:00
Make API match the README, remove StringResponse.
For YajlResponse the JSON body was being returned directly instead of the response object, which conflicted with the README. I also removed the StringResponse class since it wasn't really being used.
This commit is contained in:
parent
dc25245ced
commit
47fc27ac6d
@ -1,6 +1,6 @@
|
|||||||
= faraday
|
= faraday
|
||||||
|
|
||||||
experiments in a rest api lib
|
Experiments in a REST API lib
|
||||||
|
|
||||||
Super alpha! Don't use it if you mind throwing away all the code when I change
|
Super alpha! Don't use it if you mind throwing away all the code when I change
|
||||||
the API on a whim.
|
the API on a whim.
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
module Faraday
|
|
||||||
class Response
|
|
||||||
class StringResponse < Response
|
|
||||||
def content
|
|
||||||
body
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -3,7 +3,6 @@ module Faraday
|
|||||||
class Response
|
class Response
|
||||||
class YajlResponse < Response
|
class YajlResponse < Response
|
||||||
attr_reader :body
|
attr_reader :body
|
||||||
alias content body
|
|
||||||
|
|
||||||
def initialize(headers = nil, body = nil)
|
def initialize(headers = nil, body = nil)
|
||||||
super
|
super
|
||||||
|
@ -15,14 +15,9 @@ class AdapterTest < Faraday::TestCase
|
|||||||
assert_equal 'hello world', @connection.get('hello_world').body
|
assert_equal 'hello world', @connection.get('hello_world').body
|
||||||
end
|
end
|
||||||
|
|
||||||
it "retrieves the response JSON with StringResponse" do
|
it "retrieves the response body with YajlResponse" do
|
||||||
@connection.response_class = Faraday::Response::StringResponse
|
|
||||||
assert_equal 'hello world', @connection.get('hello_world')
|
|
||||||
end
|
|
||||||
|
|
||||||
it "retrieves the response JSON with YajlResponse" do
|
|
||||||
@connection.response_class = Faraday::Response::YajlResponse
|
@connection.response_class = Faraday::Response::YajlResponse
|
||||||
assert_equal [1,2,3], @connection.get('json')
|
assert_equal [1,2,3], @connection.get('json').body
|
||||||
end
|
end
|
||||||
|
|
||||||
it "retrieves the response headers" do
|
it "retrieves the response headers" do
|
||||||
|
@ -11,23 +11,13 @@ class ResponseTest < Faraday::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "TestConnection#get with Faraday::StringResponse class" do
|
|
||||||
it "returns string body" do
|
|
||||||
conn = TestConnection.new do |stub|
|
|
||||||
stub.get('/hello') { [200, {}, 'hello world']}
|
|
||||||
end
|
|
||||||
conn.response_class = Faraday::Response::StringResponse
|
|
||||||
assert_equal 'hello world', conn.get('/hello')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "TestConnection#get with Faraday::YajlResponse class" do
|
describe "TestConnection#get with Faraday::YajlResponse class" do
|
||||||
it "returns string body" do
|
it "returns string body" do
|
||||||
conn = TestConnection.new do |stub|
|
conn = TestConnection.new do |stub|
|
||||||
stub.get('/hello') { [200, {}, '[1,2,3]']}
|
stub.get('/hello') { [200, {}, '[1,2,3]']}
|
||||||
end
|
end
|
||||||
conn.response_class = Faraday::Response::YajlResponse
|
conn.response_class = Faraday::Response::YajlResponse
|
||||||
assert_equal [1,2,3], conn.get('/hello')
|
assert_equal [1,2,3], conn.get('/hello').body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user