Skip to content

Instantly share code, notes, and snippets.

@BitOfUniverse
Last active March 28, 2019 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BitOfUniverse/8558b04f5ccd845f5605ad1dabbc5285 to your computer and use it in GitHub Desktop.
Save BitOfUniverse/8558b04f5ccd845f5605ad1dabbc5285 to your computer and use it in GitHub Desktop.
Ruby implicit block capture
def new(url = nil, options = nil)
block = block_given? ? Proc.new : nil
options = options ? default_connection_options.merge(options) : default_connection_options
Faraday::Connection.new(url, options, &block)
end
# And it should be used like this:
conn = Faraday.new(:url => 'https://www.smartly.io/developer') do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment