lib/faraday/adapter/net_http.rb in faraday-0.1.0 vs lib/faraday/adapter/net_http.rb in faraday-0.1.1

- old
+ new

@@ -1,22 +1,42 @@ require 'net/http' +require 'cgi' module Faraday module Adapter module NetHttp extend Faraday::Connection::Options - def _get(uri, request_headers) + def _perform(method, uri, data, request_headers) http = Net::HTTP.new(uri.host, uri.port) response_class.new do |resp| - http_resp = http.get(path_for(uri), request_headers) do |chunk| - resp.process(chunk) - end + http_resp = http.send_request(method, path_for(uri), data, request_headers) + raise Faraday::Error::ResourceNotFound if http_resp.code == '404' + resp.process http_resp.body http_resp.each_header do |key, value| resp.headers[key] = value end end rescue Errno::ECONNREFUSED raise Faraday::Error::ConnectionFailed, "connection refused" end + + def _put(uri, data, request_headers) + request = request_class.new(data, request_headers) + _perform('PUT', uri, request.body, request.headers) + end + + def _post(uri, data, request_headers) + request = request_class.new(data, request_headers) + _perform('POST', uri, request.body, request.headers) + end + + def _get(uri, request_headers) + _perform('GET', uri, uri.query, request_headers) + end + + def _delete(uri, request_headers) + _perform('DELETE', uri, uri.query, request_headers) + end + end end end