deepstream-ruby
deepstream.io ruby client deepstream version >5 needed
Installation
gem install deepstream
Usage
Client initialization
ds = Deepstream::Client.new('localhost')
# or
ds = Deepstream::Client.new('ws://localhost:6020')
# or
ds = Deepstream::Client.new('ws://localhost:6020/deepstream-v3',
ack_timeout: nil, # ACK timeout; if nil, then the client never checks ACK timeout errors
credentials: { username: 'John', password: 'Doe' }, # credentials used to authorise the client
heartbeat_interval: nil # when two server heartbeats are missed the client considers the connection to be lost
emit_timeout: 0, # if 0, then events that failed to be emitted are thrown away
# if nil, then events are stored in a buffer, waiting for reconnection
# if another number, then events are stored in a buffer and sent if the client reconnects in emit_timeout seconds
verbose: false, # show verbose information about connection, incoming and outgoing messages etc.
debug: false, # use for testing only; if true, any exception will terminate the client
in_thread: true # if true, putting client in separated thread
)
# log in to the server
ds.login
# you can use new credentials too
ds.login(username: 'John', password: 'betterDoe')
# check if the websocket connection is opened
ds.connected?
# check if the client is logged in
ds.logged_in?
Events
# emit an event
ds.emit('my_event')
# or
ds.emit('my_event', foo: 'bar', bar: 'foo')
# or
ds.emit('my_event', foo: 'bar', bar: 'foo', timeout: 10) # emit with a custom timeout
# subscribe to events
ds.on('my_event') { |data| puts data }
Records
# get a record
# list is an optional argument; when given, the client adds the record to a list with given name
foo = ds.get('foo', list: 'bar')
# or
foo = ds.get_record('foo', list: 'bar')
# Update a record
foo.set('bar', 'bar') # update 'bar' attribute
# or
foo.bar = 'bar'
# or set the whole record data at once
foo.set(bar: 'bar', baz: 'baz')
Lists
# get a list
foo = ds.get_list('foo')
# add to the list
foo.add('bar')
# Remove from list
foo.remove('foo')
# show record names in the list
foo.data
# or
foo.keys
# get records from the list
foo.all
# callbacks
foo.on(:added) { |record| }
foo.on(:removed) { |record| }
Development
git submodule update --init --recursive
To Do
Adjust tests, to work with new version (without celluloid)