mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-06 00:03:36 -04:00
Faraday.new shortcut
This commit is contained in:
parent
65b818e1af
commit
7d12ed5ddb
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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'] }
|
||||
|
@ -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'] }
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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|
|
||||
|
@ -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'}, ''] }
|
||||
|
Loading…
x
Reference in New Issue
Block a user