lib/faraday/connection.rb in faraday-0.5.6 vs lib/faraday/connection.rb in faraday-0.5.7

- old
+ new

@@ -15,11 +15,11 @@ # :url # :params # :headers # :request # :ssl - def initialize(url = nil, options = {}, &block) + def initialize(url = nil, options = {}) if url.is_a?(Hash) options = url url = options[:url] end @headers = HeaderHash.new @@ -30,11 +30,12 @@ self.url_prefix = url if url proxy(options[:proxy]) merge_params @params, options[:params] if options[:params] merge_headers @headers, options[:headers] if options[:headers] - if block + if block_given? + block = Proc.new @builder = Builder.new @builder.build { block.call(self) } else @builder = options[:builder] || Builder.new end @@ -58,26 +59,31 @@ def build(options = {}, &block) @builder.build(options, &block) end - def get(url = nil, headers = nil, &block) + def get(url = nil, headers = nil) + block = block_given? ? Proc.new : nil run_request(:get, url, nil, headers, &block) end - def post(url = nil, body = nil, headers = nil, &block) + def post(url = nil, body = nil, headers = nil) + block = block_given? ? Proc.new : nil run_request(:post, url, body, headers, &block) end - def put(url = nil, body = nil, headers = nil, &block) + def put(url = nil, body = nil, headers = nil) + block = block_given? ? Proc.new : nil run_request(:put, url, body, headers, &block) end - def head(url = nil, headers = nil, &block) + def head(url = nil, headers = nil) + block = block_given? ? Proc.new : nil run_request(:head, url, nil, headers, &block) end - def delete(url = nil, headers = nil, &block) + def delete(url = nil, headers = nil) + block = block_given? ? Proc.new : nil run_request(:delete, url, nil, headers, &block) end def basic_auth(login, pass) auth = Base64.encode64("#{login}:#{pass}")