Faraday.new shortcut

This commit is contained in:
rick 2011-02-27 10:20:18 -08:00
parent 65b818e1af
commit 7d12ed5ddb
8 changed files with 13 additions and 8 deletions

View File

@ -6,7 +6,7 @@ This mess is gonna get raw, like sushi. So, haters to the left.
## Usage
conn = Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
conn = Faraday.new(:url => 'http://sushi.com') do |builder|
builder.use Faraday::Request::Yajl # convert body to json with Yajl lib
builder.use Faraday::Adapter::Logger # log the request somewhere?
builder.use Faraday::Adapter::Typhoeus # make http request with typhoeus
@ -41,7 +41,7 @@ This mess is gonna get raw, like sushi. So, haters to the left.
# You can pass stubbed request to the test adapter or define them in a block
# or a combination of the two.
test = Faraday::Connection.new do |builder|
test = Faraday.new do |builder|
builder.adapter :test, stubs do |stub|
stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
end

View File

@ -5,6 +5,11 @@ module Faraday
attr_accessor :default_adapter
attr_writer :default_connection
def new(url = nil, options = {})
block = block_given? ? Proc.new : nil
Faraday::Connection.new(url, options, &block)
end
private
def method_missing(name, *args, &block)
default_connection.send(name, *args, &block)

View File

@ -9,7 +9,7 @@ module Adapters
@logger = Logger.new(@io)
@logger.level = Logger::DEBUG
@conn = Faraday::Connection.new do |b|
@conn = Faraday.new do |b|
b.adapter :logger, @logger
b.adapter :test do |stubs|
stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }

View File

@ -4,7 +4,7 @@ module Adapters
class TestMiddleware < Faraday::TestCase
def setup
@stubs = Faraday::Adapter::Test::Stubs.new
@conn = Faraday::Connection.new do |builder|
@conn = Faraday.new do |builder|
builder.adapter :test, @stubs
end
@stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }

View File

@ -23,7 +23,7 @@ class TestConnectionApps < Faraday::TestCase
end
def setup
@conn = Faraday::Connection.new do |b|
@conn = Faraday.new do |b|
b.use TestMiddleWare
b.use TestAdapter
end

View File

@ -2,7 +2,7 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
class TestEnv < Faraday::TestCase
def setup
@conn = Faraday::Connection.new :url => 'http://sushi.com/api', :headers => {'Mime-Version' => '1.0'}
@conn = Faraday.new :url => 'http://sushi.com/api', :headers => {'Mime-Version' => '1.0'}
@conn.options[:timeout] = 3
@conn.options[:open_timeout] = 5
@conn.ssl[:verify] = false

View File

@ -16,7 +16,7 @@ class RequestMiddlewareTest < Faraday::TestCase
private
def create_json_connection(encoder)
Faraday::Connection.new do |b|
Faraday.new do |b|
b.use encoder
b.adapter :test do |stub|
stub.post('echo_body') do |env|

View File

@ -31,7 +31,7 @@ class ResponseMiddlewareTest < Faraday::TestCase
end
def create_json_connection(encoder)
Faraday::Connection.new do |b|
Faraday.new do |b|
b.adapter :test do |stub|
stub.get('json') { [200, {'Content-Type' => 'text/html'}, "[1,2,3]"] }
stub.get('blank') { [200, {'Content-Type' => 'text/html'}, ''] }