Skip to content

Instantly share code, notes, and snippets.

@sfaxon
Created May 11, 2012 18:25
Show Gist options
  • Save sfaxon/2661525 to your computer and use it in GitHub Desktop.
Save sfaxon/2661525 to your computer and use it in GitHub Desktop.
require 'faraday'
require 'debugger'
@connection = Faraday.new("http://localhost") do |builder|
# builder.use Faraday::Request::BasicAuthentication.header('user', 'pass')
builder.adapter :test do |stub|
stub.get('/something') {[ 200, {}, 'yay' ]}
end
end
debugger
@connection.basic_auth('user', 'pass') #
puts @connection.builder.handlers.to_s # [Faraday::Adapter::Test]
puts @connection.url_prefix.to_s # http://localhost/
puts @connection.get('/something').body # yay
puts @connection.get('/something').env[:request_headers] # {"Authorization"=>"Basic dXNlcjpwYXNz"}
##########
Farady connection:
def basic_auth(login, pass)
headers[Faraday::Request::Authorization::KEY] =
Faraday::Request::BasicAuthentication.header(login, pass)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment