Project

deepstream

0.01
No commit activity in last 3 years
No release in over 3 years
Basic ruby client for the deepstream.io server
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 1.28.9
~> 0.54.1
~> 1.30.2
 Project Readme

deepstream-ruby

deepstream.io ruby client deepstream version >5 needed

Gem Version Gem License

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)