Skip to content

Commit 2f89b09

Browse files
author
Radosław Luter
committed
update README
1 parent 97c574a commit 2f89b09

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

README.md

+25-17
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,49 @@
11
# deepstream-ruby
22
deepstream.io ruby client
33

4-
54
### Install
65

76
```
87
gem install deepstream
98
```
109

11-
1210
### Usage
1311
```ruby
14-
ds = Deepstream::Client.new('localhost')
12+
ds = Deepstream::Client.new('localhost',
13+
autologin: false,
14+
verbose: true,
15+
credentials: { username: 'John', password: 'Doe' })
16+
# or
17+
ds = Deepstream::Client.new('ws://localhost:6020')
18+
# or
19+
ds = Deepstream::Client.new('ws://localhost:6020/deepstream')
20+
21+
# log in to the server
22+
ds.login
23+
# you can use new credentials too
24+
ds.login(username: 'John', password: 'betterDoe')
25+
26+
# check if the websocket connection is opened
27+
ds.connected?
28+
29+
# check if the client is logged in
30+
ds.logged_in?
1531

1632
# Emit events
1733
ds.emit 'my_event'
1834
# or
1935
ds.emit 'my_event', foo: 'bar', bar: 'foo'
20-
# or
21-
ds.emit 'my_event', {foo: 'bar', bar: 'foo'}, timeout: 3
22-
# or
23-
ds.emit 'my_event', nil, timeout: 3
24-
2536

2637
# Subscribe to events
27-
ds.on('some_event') do |msg|
38+
ds.on('some_event') do |event_name, msg|
2839
puts msg
2940
end
3041

31-
3242
# Get a record
3343
foo = ds.get('foo')
44+
bar = ds.get('bar', list: 'bar_list') # get a record within a namespace (this one automatically adds it to a list)
3445

35-
# Get a record with a namespace (automaticly add to a list)
36-
foo = ds.get_record('foo', list: 'bar') # record can also be accessed by ds.get('bar/foo')
37-
38-
# Update record
39-
foo.bar = 'bar'
40-
# or
46+
# Update a record
4147
foo.set('bar', 'bar')
4248

4349
# Set the whole record
@@ -46,13 +52,15 @@ foo.set(foo: 'foo', bar: 1)
4652
# Get a list
4753
foo = ds.get_list('bar')
4854

49-
# Add to list
55+
# Add to the list
5056
foo.add('foo')
5157

5258
# Remove from list
5359
foo.remove('foo')
5460

5561
# Show record names on the list
62+
foo.data
63+
# or
5664
foo.keys
5765

5866
# Access records on the list

0 commit comments

Comments
 (0)