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, options = {}) ⇒ 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, options = {}) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/angus/remote/client.rb', line 15 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 store_namespace = "#{['code_name']}.#{['version']}" client_settings = { :public_key => ['public_key'], :private_key => ['private_key'], :service_id => store_namespace, :store => Settings.redis.merge({ :namespace => store_namespace }) } @authentication_client = Authentication::Client.new(client_settings) end |
Instance Method Details
#make_request(path, method, encode_as_json, path_params, request_params) ⇒ Net::HTTPResponse
Makes a request to the service
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/angus/remote/client.rb', line 57 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 @authentication_client.prepare_request(request, method.upcase, path) response = @connection.request(request) @authentication_client.store_session_private_key(response) if Utils.severe_error_response?(response) raise RemoteSevereError.new((response.body)) end response rescue Errno::ECONNREFUSED, PersistentHTTP::Error => e raise RemoteConnectionError.new("#@api_base_path - #{e.class}: #{e.}") end end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/angus/remote/client.rb', line 79 def to_s "#<#{self.class}:#{object_id}>" end |