swarmclient 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +18 -10
- data/lib/swarmclient/communication.rb +35 -21
- data/lib/swarmclient/version.rb +1 -1
- data/swarmclient.gemspec +1 -2
- metadata +9 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7e95eff9380f3baca4790e174a8da717d24f6e0ac0f00527cb6553b9aab6f202
|
4
|
+
data.tar.gz: 37cb9aa517d9c20d797f80b0fefd27a50faac32cdf2ce2efa65c3c4450ab30b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ce1f8bd41ebd42a81ca039bdd7e812c2bb8f6a9671cd3bd31854d488e51940036f98ce0d1d43fdf5f4e3b6254a580ae22fd18825b9913171121b0ff17c73cb5
|
7
|
+
data.tar.gz: 3e6d750e25d49cce360bfed471e237753a029f0c706fb23056857b26de680c0dcc79bd061191e1c2eed10cf0194840196b3995bb190743ecf45982614fd945fb
|
data/README.md
CHANGED
@@ -17,8 +17,9 @@ And then execute:
|
|
17
17
|
Or build and install from src:
|
18
18
|
|
19
19
|
$ git clone https://github.com/wlwanpan/swarmclient-rb.git
|
20
|
+
$ cd swarmclient-rb && bundle install
|
20
21
|
$ gem build swarmclient.gemspec
|
21
|
-
$ gem install swarmclient-
|
22
|
+
$ gem install swarmclient-{GEM_VERSION}.gem
|
22
23
|
|
23
24
|
## Communication API (Swarmclient::Communication)
|
24
25
|
|
@@ -26,7 +27,7 @@ Require and Initialize
|
|
26
27
|
```
|
27
28
|
require 'swarmclient'
|
28
29
|
|
29
|
-
bluzelle = Swarmclient::Communication.new endpoint: "
|
30
|
+
bluzelle = Swarmclient::Communication.new endpoint: "127.0.0.1", port: 50001, uuid: "80174b53-2dda-49f1-9d6a-6a780d4"
|
30
31
|
```
|
31
32
|
|
32
33
|
Note: The uuid is the uniq id of a referenced db hosted in the swarm.
|
@@ -35,17 +36,25 @@ Refer to https://bluzelle.github.io/api/ for more info.
|
|
35
36
|
|
36
37
|
Create New Entry (key-value)
|
37
38
|
```
|
38
|
-
bluzelle.create
|
39
|
+
bluzelle.create 'myKey', 'Your Value'
|
39
40
|
```
|
40
41
|
|
41
42
|
Read Key
|
42
43
|
```
|
43
|
-
|
44
|
-
puts res
|
44
|
+
bluzelle.read 'myKey'
|
45
45
|
```
|
46
46
|
- Result
|
47
47
|
```
|
48
|
-
|
48
|
+
{:value => "Your Value"}
|
49
|
+
```
|
50
|
+
|
51
|
+
Read Multiple Keys
|
52
|
+
```
|
53
|
+
bluzelle.read ['myKey', 'myKey2']
|
54
|
+
```
|
55
|
+
- Result
|
56
|
+
```
|
57
|
+
[{:myKey => "Your Value"}, {:myKey2 => nil}]
|
49
58
|
```
|
50
59
|
|
51
60
|
Update Key value
|
@@ -60,12 +69,11 @@ bluzelle.remove 'myKey'
|
|
60
69
|
|
61
70
|
Check if key exist
|
62
71
|
```
|
63
|
-
|
64
|
-
puts res
|
72
|
+
bluzelle.has 'myKey'
|
65
73
|
```
|
66
74
|
- Result
|
67
75
|
```
|
68
|
-
=> {:
|
76
|
+
=> {:"key-exists" => true}
|
69
77
|
```
|
70
78
|
|
71
79
|
Read all keys stored
|
@@ -74,7 +82,7 @@ bluzelle.keys
|
|
74
82
|
```
|
75
83
|
- Result
|
76
84
|
```
|
77
|
-
=> {:
|
85
|
+
=> {:keys => ["myKey"]}
|
78
86
|
```
|
79
87
|
|
80
88
|
## Pubsub (Swarmclient::Pubsub)
|
@@ -1,9 +1,8 @@
|
|
1
|
-
require 'faye/websocket'
|
2
|
-
require 'eventmachine'
|
3
1
|
require 'websocket-client-simple'
|
2
|
+
require 'eventmachine'
|
4
3
|
require 'json'
|
5
4
|
|
6
|
-
DEFAULT_IP = '127.0.0.1'
|
5
|
+
DEFAULT_IP = 'ws://127.0.0.1'
|
7
6
|
DEFAULT_PORT = 8080
|
8
7
|
|
9
8
|
module Swarmclient
|
@@ -28,8 +27,12 @@ module Swarmclient
|
|
28
27
|
send cmd: 'read', data: { key: key }
|
29
28
|
end
|
30
29
|
|
30
|
+
def read_multiple keys
|
31
|
+
send_multiple cmd: 'read', keys: keys
|
32
|
+
end
|
33
|
+
|
31
34
|
def update key, value
|
32
|
-
send cmd: 'update', data: { key: key }
|
35
|
+
send cmd: 'update', data: { key: key, value: value }
|
33
36
|
end
|
34
37
|
|
35
38
|
def remove key
|
@@ -46,6 +49,13 @@ module Swarmclient
|
|
46
49
|
|
47
50
|
private
|
48
51
|
|
52
|
+
def send_multiple cmd:, keys:
|
53
|
+
keys.map do |key|
|
54
|
+
res = send cmd: cmd, data: { key: key }
|
55
|
+
Hash[key, res ? res[:value] : nil]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
49
59
|
def send cmd:, data:
|
50
60
|
|
51
61
|
endpoint, req = [
|
@@ -73,7 +83,7 @@ module Swarmclient
|
|
73
83
|
|
74
84
|
when nil
|
75
85
|
|
76
|
-
return res
|
86
|
+
return res[:data]
|
77
87
|
|
78
88
|
else
|
79
89
|
|
@@ -89,28 +99,32 @@ module Swarmclient
|
|
89
99
|
|
90
100
|
res, err = [nil, nil]
|
91
101
|
|
92
|
-
|
102
|
+
begin
|
103
|
+
EventMachine.run do
|
93
104
|
|
94
|
-
|
105
|
+
ws = WebSocket::Client::Simple.connect endpoint
|
95
106
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
107
|
+
ws.on :message do |msg|
|
108
|
+
res = msg.data
|
109
|
+
EventMachine::stop_event_loop
|
110
|
+
end
|
100
111
|
|
101
|
-
|
102
|
-
|
103
|
-
|
112
|
+
ws.on :open do
|
113
|
+
ws.send req.to_json
|
114
|
+
end
|
104
115
|
|
105
|
-
|
106
|
-
|
107
|
-
|
116
|
+
ws.on :close do |e|
|
117
|
+
EventMachine::stop_event_loop
|
118
|
+
end
|
108
119
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
120
|
+
ws.on :error do |e|
|
121
|
+
err = e
|
122
|
+
EventMachine::stop_event_loop
|
123
|
+
end
|
113
124
|
|
125
|
+
end
|
126
|
+
rescue => e
|
127
|
+
err = e
|
114
128
|
end
|
115
129
|
|
116
130
|
[err, res]
|
data/lib/swarmclient/version.rb
CHANGED
data/swarmclient.gemspec
CHANGED
@@ -24,8 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.16"
|
25
25
|
spec.add_development_dependency "rake", "~> 10.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
-
spec.add_development_dependency "faye-websocket", "~> 0.10"
|
28
27
|
spec.add_development_dependency "eventmachine", "~> 1.2"
|
29
|
-
spec.add_development_dependency "json", "~> 2.1"
|
30
28
|
spec.add_development_dependency "websocket-client-simple", "~> 0.3"
|
29
|
+
spec.add_development_dependency "json", "~> 2.1"
|
31
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swarmclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Warren
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: faye-websocket
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.10'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.10'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: eventmachine
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,33 +67,33 @@ dependencies:
|
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: '1.2'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: websocket-client-simple
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '0.3'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '0.3'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: json
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
89
|
+
version: '2.1'
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
96
|
+
version: '2.1'
|
111
97
|
description:
|
112
98
|
email:
|
113
99
|
- wlwanpan@uwaterloo.ca
|
@@ -150,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
136
|
version: '0'
|
151
137
|
requirements: []
|
152
138
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.6
|
139
|
+
rubygems_version: 2.7.6
|
154
140
|
signing_key:
|
155
141
|
specification_version: 4
|
156
142
|
summary: A gem for the bluzele SwarmDB
|