Class: Artifice::Net::HTTP
- Inherits:
-
Net::HTTP
- Object
- Net::HTTP
- Artifice::Net::HTTP
- Defined in:
- lib/artifice.rb
Class Attribute Summary collapse
-
.endpoint ⇒ Object
Returns the value of attribute endpoint.
Instance Method Summary collapse
-
#connect ⇒ Object
We don’t need to connect, so blank out this method.
-
#request(req, body = nil) {|Net::HTTPResponse| ... } ⇒ Net::HTTPResponse
Replace the Net::HTTP request method with a method that converts the request into a Rack request and dispatches it to the Rack endpoint.
Class Attribute Details
.endpoint ⇒ Object
Returns the value of attribute endpoint.
55 56 57 |
# File 'lib/artifice.rb', line 55 def endpoint @endpoint end |
Instance Method Details
#connect ⇒ Object
We don’t need to connect, so blank out this method
64 65 |
# File 'lib/artifice.rb', line 64 def connect end |
#request(req, body = nil) {|Net::HTTPResponse| ... } ⇒ Net::HTTPResponse
Replace the Net::HTTP request method with a method that converts the request into a Rack request and dispatches it to the Rack endpoint.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/artifice.rb', line 81 def request(req, body = nil, &block) rack_request = RackRequest.new(self.class.endpoint) req.each_header do |header, value| rack_request.header(header, value) end scheme = use_ssl? ? "https" : "http" prefix = "#{scheme}://#{addr_port}" response = rack_request.request("#{prefix}#{req.path}", {:method => req.method, :input => body || req.body}) make_net_http_response(response, &block) end |