Sha256: 44d6311957b0b1a1be9f54e99b091258e5ca4fa3c76af21545545f6427851376
Contents?: true
Size: 1.27 KB
Versions: 12
Compression:
Stored size: 1.27 KB
Contents
require "net/http" require "uri" module Roar module Representer # Implements the (HTTP) transport interface with Net::HTTP. module Transport # Definitions: every call returns a Response object responding to #body. class NetHTTP # TODO: generically handle return codes. def get_uri(uri, as) do_request(Net::HTTP::Get, uri, as) end def post_uri(uri, body, as) do_request(Net::HTTP::Post, uri, as, body) end def put_uri(uri, body, as) do_request(Net::HTTP::Put, uri, as, body) end def patch_uri(uri, body, as) do_request(Net::HTTP::Patch, uri, as, body) end def delete_uri(uri, as) do_request(Net::HTTP::Delete, uri, as) end private def do_request(what, uri, as, body="") # DISCUSS: can this be made easier? uri = URI.parse(uri) http = Net::HTTP.new(uri.host, uri.port) req = what.new(uri.request_uri) req.content_type = as req["accept"] = as # TODO: test me. # DISCUSS: if Accept is not set, rails treats this request as as "text/html". req.body = body if body http.request(req) end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems