Class: Zas::Client
- Inherits:
-
Object
- Object
- Zas::Client
- Defined in:
- lib/zas/client.rb
Instance Method Summary collapse
-
#authenticate(credentials) ⇒ Object
Authenticate the given credentials.
-
#disconnect ⇒ Object
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.
13 14 15 16 17 18 19 20 |
# File 'lib/zas/client.rb', line 13 def initialize(config=ClientConfiguration.new) self.host = config.host self.port = config.port self.context = ZMQ::Context.new self.logger = Syslogger.new(config.name, Syslog::LOG_PID, Syslog::LOG_LOCAL0) at_exit { disconnect } end |
Instance Method Details
#authenticate(credentials) ⇒ Object
Authenticate the given credentials.
credentials - The credentials
Returns the results of the authentication.
27 28 29 30 31 32 33 34 |
# File 'lib/zas/client.rb', line 27 def authenticate(credentials) begin socket.send credentials.to_wire Hashie::Mash.new(Yajl::Parser.parse(socket.recv)) rescue IOError => e logger.error "Shutting down: #{e.}" end end |
#disconnect ⇒ Object
Disconnect the socket.
37 38 39 40 |
# File 'lib/zas/client.rb', line 37 def disconnect socket.close if socket @socket = nil end |