Class: Angus::Remote::ProxyClient
- Inherits:
-
Object
- Object
- Angus::Remote::ProxyClient
- Defined in:
- lib/angus/remote/proxy_client.rb
Overview
A client for service invocation when proxing requests.
Instance Method Summary collapse
-
#initialize(url, timeout = 60) ⇒ ProxyClient
constructor
A new instance of ProxyClient.
-
#make_request(method, path, query, headers = {}, body = nil) ⇒ Object
Makes a request to the service.
- #to_s ⇒ Object
Constructor Details
#initialize(url, timeout = 60) ⇒ ProxyClient
Returns a new instance of ProxyClient.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/angus/remote/proxy_client.rb', line 13 def initialize(url, timeout = 60) url = url[0..-2] if url[-1] == '/' @connection = PersistentHTTP.new( :pool_size => 4, :pool_timeout => 10, :warn_timeout => 0.25, :force_retry => false, :url => url, :read_timeout => timeout, :open_timeout => timeout ) @api_base_path = @connection.default_path end |
Instance Method Details
#make_request(method, path, query, headers = {}, body = nil) ⇒ Object
Makes a request to the service
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/angus/remote/proxy_client.rb', line 32 def make_request(method, path, query, headers = {}, body = nil) full_path = @api_base_path + path request = ProxyClientUtils.build_request(method, full_path, query, headers, body) begin response = @connection.request(request) from_headers = ProxyClientUtils.normalize_headers( ProxyClientUtils.filter_response_headers(response.to_hash) ) [response.code.to_i, from_headers, [response.body]] rescue Errno::ECONNREFUSED => e raise RemoteConnectionError.new("#{self.class.base_uri} - #{e.class}: #{e.}") end end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/angus/remote/proxy_client.rb', line 50 def to_s "#<#{self.class}:#{object_id}>" end |