Class: Zas::Client
- Inherits:
-
Object
- Object
- Zas::Client
- Defined in:
- lib/zas/client.rb
Instance Method Summary collapse
-
#authenticate(credentials) ⇒ Object
Public: Authenticate the given credentials.
-
#close ⇒ Object
Public: Close the context.
-
#disconnect ⇒ Object
Public: Disconnect the socket.
-
#initialize(config = ClientConfiguration.new) ⇒ Client
constructor
Initialize the client with the given configuration.
Constructor Details
#initialize(config = ClientConfiguration.new) ⇒ Client
Initialize the client with the given configuration.
config - Configuration spec for the client.
20 21 22 23 24 25 26 27 28 |
# File 'lib/zas/client.rb', line 20 def initialize(config=ClientConfiguration.new) self.host = config.host self.port = config.port self.timeout = config.timeout self.context = ZMQ::Context.new self.logger = Syslogger.new(config.name, Syslog::LOG_PID, Syslog::LOG_LOCAL0) at_exit { close } end |
Instance Method Details
#authenticate(credentials) ⇒ Object
Public: Authenticate the given credentials.
credentials - The credentials
Returns the results of the authentication.
Raises a Zas::TimeoutError if the authentication service does not respond within the timeout as specified the configuration.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zas/client.rb', line 38 def authenticate(credentials) begin socket.send credentials.to_wire if ZMQ.select([socket], nil, nil, timeout) Hashie::Mash.new(Yajl::Parser.parse(socket.recv)) else disconnect raise Zas::TimeoutError, "Response from authentication service not received in time" end rescue IOError => e logger.error "IO error occurred: #{e.}" end end |
#close ⇒ Object
Public: Close the context.
59 60 61 |
# File 'lib/zas/client.rb', line 59 def close context.close if context end |
#disconnect ⇒ Object
Public: Disconnect the socket.
53 54 55 56 |
# File 'lib/zas/client.rb', line 53 def disconnect socket.close if socket @socket = nil end |