deepstream 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2ebced820e2695da9c46c6982d8b83c16bebceb
4
- data.tar.gz: 8646e0465d844e1c2a34bdcbc57b3b061a837084
3
+ metadata.gz: ae5c4c24417b9fee9b35deee733cb98bc8402caf
4
+ data.tar.gz: 4e0f4378e8b7e1c0c05ab07c4b9ff3bf22d31bfd
5
5
  SHA512:
6
- metadata.gz: e2e6b15a7fadb773ab7fc399129700c9de65d76e3d0957578ef30accc3b85d0fc10b9f954223aca44f4e1aa60696e7e2dedcddd112db75c08206dae20639d267
7
- data.tar.gz: c7cae785c5c2c59dd600bbb56c17b382ed323cc15622c896b0e5aee51f0d3132a81f280daf8c658ab24870e7c50b90d947540516197d0d720e604573b3e5448a
6
+ metadata.gz: d2a9d799f057eeeaa687cfbdc1ca5b190aa4b3951a2ab58fff3377b1daa39a35bc1c3baf1232aeeb1a574ecb77a7d96c4af210a285b49a6a9659134242c96271
7
+ data.tar.gz: ff29a8e5642e88ad74685a7f1fd60007e52204c50dcd8bdc38dc33006977b1254402cc456f7094bf80f8d3df52be73934c8f0b61e2f63343930f729862f501a7
data/README.md CHANGED
@@ -1,65 +1,84 @@
1
1
  # deepstream-ruby
2
+
2
3
  deepstream.io ruby client
3
4
 
4
- ### Install
5
+ [![Gem Version](https://badge.fury.io/rb/deepstream.svg)](http://badge.fury.io/rb/deepstream)
6
+ [![Gem License](https://img.shields.io/badge/license-Apache-blue.svg)](https://github.com/Currency-One/deepstream-ruby/blob/master/LICENSE)
7
+
8
+ ## Installation
5
9
 
6
10
  ```
7
11
  gem install deepstream
8
12
  ```
9
13
 
10
- ### Usage
14
+ ## Usage
15
+
16
+ ### Client initialization
11
17
  ```ruby
12
- ds = Deepstream::Client.new('localhost',
13
- autologin: false,
14
- verbose: true,
15
- credentials: { username: 'John', password: 'Doe' })
18
+ ds = Deepstream::Client.new('localhost')
16
19
  # or
17
20
  ds = Deepstream::Client.new('ws://localhost:6020')
18
21
  # or
19
- ds = Deepstream::Client.new('ws://localhost:6020/deepstream')
20
-
22
+ ds = Deepstream::Client.new('ws://localhost:6020/deepstream',
23
+ ack_timeout: nil, # ACK timeout; if nil, then the client never checks ACK timeout errors
24
+ autologin: false, # authorise the client when a Websocket connection is initialized; you don't need to call login() then
25
+ credentials: { username: 'John', password: 'Doe' }, # credentials used to authorise the client
26
+ heartbeat_interval: nil # when two server heartbeats are missed the client considers the connection to be lost
27
+ max_reconnect_attempts: nil,
28
+ max_reconnect_interval: 30, # seconds
29
+ reconnect_interval: 1, # seconds, the final interval is a lower number from (reconnect_interval * failed_attempts, max_reconnect_interval)
30
+ emit_timeout: 0, # if 0, then events that failed to be emitted are thrown away
31
+ # if nil, then events are stored in a buffer, waiting for reconnection
32
+ # if another number, then events are stored in a buffer and sent if the client reconnects in emit_timeout seconds
33
+ verbose: false, # show verbose information about connection, incoming and outgoing messages etc.
34
+ debug: false # use for testing only; if true, any exception will terminate the client
35
+ )
21
36
  # log in to the server
22
37
  ds.login
23
38
  # you can use new credentials too
24
39
  ds.login(username: 'John', password: 'betterDoe')
25
-
26
40
  # check if the websocket connection is opened
27
41
  ds.connected?
28
-
29
42
  # check if the client is logged in
30
43
  ds.logged_in?
31
-
32
- # Emit events
33
- ds.emit 'my_event'
44
+ ```
45
+ ### Events
46
+ ```ruby
47
+ # emit an event
48
+ ds.emit('my_event')
34
49
  # or
35
- ds.emit 'my_event', foo: 'bar', bar: 'foo'
36
-
37
- # Subscribe to events
38
- ds.on('some_event') { |data| puts data }
39
-
40
- # Get a record
41
- foo = ds.get('foo')
42
- bar = ds.get('bar', list: 'bar_list') # get a record within a namespace (this one automatically adds it to a list)
43
-
50
+ ds.emit('my_event', foo: 'bar', bar: 'foo')
51
+ # or
52
+ ds.emit('my_event', foo: 'bar', bar: 'foo', timeout: 10) # emit with a custom timeout
53
+ # subscribe to events
54
+ ds.on('my_event') { |data| puts data }
55
+ ```
56
+ ### Records
57
+ ```ruby
58
+ # get a record
59
+ # list is an optional argument; when given, the client adds the record to a list with given name
60
+ foo = ds.get('foo', list: 'bar')
61
+ # or
62
+ foo = ds.get_record('foo', list: 'bar')
44
63
  # Update a record
45
- foo.set('bar', 'bar')
46
-
47
- # Set the whole record
48
- foo.set(foo: 'foo', bar: 1)
49
-
50
- # Get a list
51
- foo = ds.get_list('bar')
52
-
53
- # Add to the list
54
- foo.add('foo')
55
-
64
+ foo.set('bar', 'bar') # update 'bar' attribute
65
+ # or
66
+ foo.bar = 'bar'
67
+ # or set the whole record data at once
68
+ foo.set(bar: 'bar', baz: 'baz')
69
+ ```
70
+ ### Lists
71
+ ```ruby
72
+ # get a list
73
+ foo = ds.get_list('foo')
74
+ # add to the list
75
+ foo.add('bar')
56
76
  # Remove from list
57
77
  foo.remove('foo')
58
-
59
- # Show record names on the list
78
+ # show record names in the list
60
79
  foo.data
61
80
  # or
62
81
  foo.keys
63
-
64
- # Access records on the list
82
+ # get records from the list
65
83
  foo.all
84
+ ```
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "deepstream"
7
- spec.version = "0.2.7"
7
+ spec.version = "0.2.8"
8
8
  spec.authors = ["Currency-One S.A."]
9
9
  spec.email = ["piotr.szczudlak@currency-one.com"]
10
10
 
@@ -8,7 +8,12 @@ module Deepstream
8
8
  end
9
9
 
10
10
  def add(record_name)
11
- set(@data << record_name) unless @data.include?(record_name)
11
+ unless @data.include?(record_name)
12
+ @data << record_name
13
+ set
14
+ end
15
+ rescue => e
16
+ @client.on_exception(e)
12
17
  end
13
18
 
14
19
  def read(version, data)
@@ -21,7 +26,7 @@ module Deepstream
21
26
  end
22
27
 
23
28
  def remove(record_name)
24
- set(@data) if @data.delete(record_name)
29
+ set if @data.delete(record_name)
25
30
  end
26
31
 
27
32
  def keys
@@ -31,5 +36,11 @@ module Deepstream
31
36
  def all
32
37
  @data.map { |record_name| @client.get(record_name) }
33
38
  end
39
+
40
+ private
41
+
42
+ def set
43
+ @client.send_message(TOPIC::RECORD, ACTION::UPDATE, @name, (@version += 1), @data.to_json) if @version
44
+ end
34
45
  end
35
46
  end
@@ -28,6 +28,7 @@ module Deepstream
28
28
 
29
29
  def set(*args)
30
30
  if args.one?
31
+ raise(ArgumentError, "Record data must be a hash") unless args.first.is_a?(Hash)
31
32
  @data = args.first
32
33
  @client.send_message(TOPIC::RECORD, ACTION::UPDATE, @name, (@version += 1), @data.to_json) if @version
33
34
  elsif args.size == 2
@@ -35,6 +36,8 @@ module Deepstream
35
36
  set_path(@data, path, value)
36
37
  @client.send_message(TOPIC::RECORD, ACTION::PATCH, @name, (@version += 1), path, Helpers.to_deepstream_type(value)) if @version
37
38
  end
39
+ rescue => e
40
+ @client.on_exception(e)
38
41
  end
39
42
 
40
43
  def read(version, data)
@@ -44,22 +47,28 @@ module Deepstream
44
47
  def patch(version, path, value)
45
48
  @version = version.to_i
46
49
  set_path(@data, path, Helpers.to_type(value))
50
+ rescue => e
51
+ @client.on_exception(e)
47
52
  end
48
53
 
49
54
  def update(version, data)
50
55
  @version = version.to_i
51
56
  @data = JSON.parse(data)
57
+ rescue => e
58
+ @client.on_exception(e)
52
59
  end
53
60
 
54
61
  def method_missing(name, *args)
55
- return @data.fetch(name.to_s, nil) if args.empty?
62
+ name = name.to_s
63
+ return @data.fetch(name, nil) if args.empty?
64
+ return set(name[0..-2], *args) if name.end_with?('=') && !args.empty?
56
65
  raise(NoMethodError, name)
57
66
  end
58
67
 
59
68
  private
60
69
 
61
70
  def set_path(data, path, value)
62
- key, subkey = path.split('.', 2)
71
+ key, subkey = path.to_s.split('.', 2)
63
72
  if data.is_a?(Hash)
64
73
  subkey ? set_path(data.fetch(key), subkey, value) : data[key] = value
65
74
  elsif data.is_a?(Array)
@@ -21,6 +21,7 @@ module Deepstream
21
21
  end
22
22
 
23
23
  def get(name, list: nil)
24
+ name = name.to_s
24
25
  if list
25
26
  name.prepend("#{list}/")
26
27
  @records[list] ||= List.new(@client, list)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deepstream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Currency-One S.A.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-09 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: celluloid-websocket-client