Sha256: 6f85fde41076e6189233852b12fbb4b1157dae0c695a5535e2d4346c324d1551
Contents?: true
Size: 1.18 KB
Versions: 3
Compression:
Stored size: 1.18 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.body = body if body http.request(req) end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
roar-0.11.4 | lib/roar/representer/transport/net_http.rb |
roar-0.11.3 | lib/roar/representer/transport/net_http.rb |
roar-0.11.2 | lib/roar/representer/transport/net_http.rb |