Permalink
Browse files

Faraday.new shortcut

  • Loading branch information...
1 parent 65b818e commit 7d12ed5ddbc38e9a0c99b94410e761c6d7ec3fbe @technoweenie technoweenie committed Feb 27, 2011
View
@@ -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
@@ -5,6 +5,11 @@ class << self
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 @@ def setup
@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 @@ def call(env)
end
def setup
- @conn = Faraday::Connection.new do |b|
+ @conn = Faraday.new do |b|
b.use TestMiddleWare
b.use TestAdapter
end
View
@@ -2,7 +2,7 @@
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'}, ''] }

0 comments on commit 7d12ed5

Please sign in to comment.