Class: Angus::Remote::Client
- Inherits:
-
Object
- Object
- Angus::Remote::Client
- Defined in:
- lib/angus/remote/client.rb
Overview
A client for service invocation
Instance Method Summary collapse
-
#initialize(api_url, timeout = nil) ⇒ Client
constructor
A new instance of Client.
-
#make_request(path, method, encode_as_json, path_params, request_params) ⇒ Net::HTTPResponse
Makes a request to the service.
- #to_s ⇒ Object
Constructor Details
#initialize(api_url, timeout = nil) ⇒ Client
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/angus/remote/client.rb', line 14 def initialize(api_url, timeout = nil) api_url = api_url[0..-2] if api_url[-1] == '/' @connection = PersistentHTTP.new( :pool_size => 10, :pool_timeout => 10, :warn_timeout => 0.25, :force_retry => false, :url => api_url, :read_timeout => timeout, :open_timeout => timeout ) @api_base_path = @connection.default_path end |
Instance Method Details
#make_request(path, method, encode_as_json, path_params, request_params) ⇒ Net::HTTPResponse
Makes a request to the service
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/angus/remote/client.rb', line 48 def make_request(path, method, encode_as_json, path_params, request_params) path = @api_base_path + Utils.build_path(path, path_params) request = Utils.build_request(method, path, request_params, encode_as_json) begin response = @connection.request(request) if Utils.severe_error_response?(response) raise RemoteSevereError.new((response.body)) end response rescue Errno::ECONNREFUSED, PersistentHTTP::Error raise RemoteConnectionError.new(@api_base_path) end end |
#to_s ⇒ Object
66 67 68 |
# File 'lib/angus/remote/client.rb', line 66 def to_s "#<#{self.class}:#{object_id}>" end |