Class: Roar::Transport::NetHTTP::Request
- Inherits:
-
Object
- Object
- Roar::Transport::NetHTTP::Request
- Defined in:
- lib/roar/transport/net_http/request.rb
Overview
TODO: implement me.
Instance Method Summary collapse
- #call(what) {|req| ... } ⇒ Object
- #get ⇒ Object
-
#initialize(options) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(options) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/roar/transport/net_http/request.rb', line 8 def initialize() @uri = parse_uri([:uri]) # TODO: add :uri. @as = [:as] @body = [:body] @options = @http = Net::HTTP.new(uri.host, uri.port) unless [:pem_file].nil? pem = File.read([:pem_file]) @http.use_ssl = true @http.cert = OpenSSL::X509::Certificate.new(pem) @http.key = OpenSSL::PKey::RSA.new(pem) @http.verify_mode = [:ssl_verify_mode].nil? ? OpenSSL::SSL::VERIFY_PEER : [:ssl_verify_mode] end end |
Instance Method Details
#call(what) {|req| ... } ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/roar/transport/net_http/request.rb', line 24 def call(what) @req = what.new(uri.request_uri) # if options[:ssl] # uri.port = Net::HTTP.https_default_port() # end https! basic_auth! 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 yield req if block_given? http.request(req).tap do |res| handle_error!(res) end end |
#get ⇒ Object
44 45 46 |
# File 'lib/roar/transport/net_http/request.rb', line 44 def get call(Net::HTTP::Get) end |