Class: Slash::NetHttpConnection
- Inherits:
-
Connection
- Object
- Connection
- Slash::NetHttpConnection
- Defined in:
- lib/slash/nethttp.rb
Overview
Class to handle connections to remote web services. This class is used by ActiveResource::Base to interface with REST services.
Constant Summary collapse
- @@request_types =
{ :get => Net::HTTP::Get, :post => Net::HTTP::Post, :put => Net::HTTP::Put, :delete => Net::HTTP::Delete }
Instance Attribute Summary collapse
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
Attributes inherited from Connection
Class Method Summary collapse
Instance Method Summary collapse
- #request(method, uri, options = {}) ⇒ Object
-
#timeout=(timeout) ⇒ Object
Set the number of seconds after which HTTP requests to the remote service should time out.
Methods inherited from Connection
create_default, #delete, #get, #head, #post, #put
Instance Attribute Details
#proxy ⇒ Object
Returns the value of attribute proxy.
25 26 27 |
# File 'lib/slash/nethttp.rb', line 25 def proxy @proxy end |
#ssl_options ⇒ Object
Returns the value of attribute ssl_options.
25 26 27 |
# File 'lib/slash/nethttp.rb', line 25 def @ssl_options end |
Class Method Details
.request_types ⇒ Object
21 22 23 |
# File 'lib/slash/nethttp.rb', line 21 def self.request_types @@request_types end |
Instance Method Details
#request(method, uri, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/slash/nethttp.rb', line 45 def request(method, uri, = {}) raise ArgumentError, 'this connection does not support async mode' if [:async] = .dup prepare_request(uri, ) rqtype = @@request_types[method] || raise(ArgumentError, "Unsupported method #{method}") params = [:params] if !params.blank? if [:post, :put].include?(method) form_data = params else uri = uri.dup uri.query_values = (uri.query_values(:notation => :flat) || {}).to_mash.update(params) end end rq = rqtype.new(uri.query.blank? ? uri.path : "#{uri.path}?#{uri.query}", [:headers]) rq.form_data = form_data if form_data rq.body = [:body] if [:body] resp = http_request(uri, rq) if block_given? yield resp else check_and_raise(resp) end end |
#timeout=(timeout) ⇒ Object
Set the number of seconds after which HTTP requests to the remote service should time out.
34 35 36 37 |
# File 'lib/slash/nethttp.rb', line 34 def timeout=(timeout) @timeout = timeout configure_http(@http) if @http end |