1
1
# deepstream-ruby
2
2
deepstream.io ruby client
3
3
4
-
5
4
### Install
6
5
7
6
```
8
7
gem install deepstream
9
8
```
10
9
11
-
12
10
### Usage
13
11
``` 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?
15
31
16
32
# Emit events
17
33
ds.emit ' my_event'
18
34
# or
19
35
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
-
25
36
26
37
# Subscribe to events
27
- ds.on(' some_event' ) do |msg |
38
+ ds.on(' some_event' ) do |event_name , msg |
28
39
puts msg
29
40
end
30
41
31
-
32
42
# Get a record
33
43
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)
34
45
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
41
47
foo.set(' bar' , ' bar' )
42
48
43
49
# Set the whole record
@@ -46,13 +52,15 @@ foo.set(foo: 'foo', bar: 1)
46
52
# Get a list
47
53
foo = ds.get_list(' bar' )
48
54
49
- # Add to list
55
+ # Add to the list
50
56
foo.add(' foo' )
51
57
52
58
# Remove from list
53
59
foo.remove(' foo' )
54
60
55
61
# Show record names on the list
62
+ foo.data
63
+ # or
56
64
foo.keys
57
65
58
66
# Access records on the list
0 commit comments