gremlin_client 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4694cadbf9dbc8ce9f454f9e20eaf0ad95c1c6b
4
- data.tar.gz: 98c15a631f800a380fa3836914b47c462ee33d77
3
+ metadata.gz: ac1726d69ef30e73f89b9df036282fdaaa2ba7ec
4
+ data.tar.gz: 5cc55e6a074faad8e7ed1b95a3e5832a572ac3b8
5
5
  SHA512:
6
- metadata.gz: b0a39378eb6e2fea15ceb005d1345352dd49bd183a2f28092c94e10c881be6ecd956dd977145b0c9700eab927e00fb7024bcae028cc42b3a4de083d9ee20f46c
7
- data.tar.gz: a795247ff901231d19f47f243b2464134c098d45c96ed6acacab119068c99c6fac576e9d968868a599fdca6db5fe746523739cefac2809631b928a8d8742a5c8
6
+ metadata.gz: 577ae755b2dd6838ae88caa683af726f65b6e8423717608a1fe23173b0dc85a5a96c6f7695e06136de2ed559f337eeafdb0134ced79f53f7765434ce283a6804
7
+ data.tar.gz: ca42b57048b747bf4816aa1b7e4ebd4f556fddcdbe743e0037744c7f4f7153fa59bc31aeb746a4bcf8bdc53a57428980a12a7cdc8cb34d76637a44ca043b26a0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gremlin_client (0.1.2)
4
+ gremlin_client (0.1.3)
5
5
  websocket-client-simple (~> 0.3)
6
6
 
7
7
  GEM
@@ -108,4 +108,4 @@ DEPENDENCIES
108
108
  rubocop (~> 0.47)
109
109
 
110
110
  BUNDLED WITH
111
- 1.14.5
111
+ 1.14.6
@@ -97,7 +97,15 @@ module GremlinClient
97
97
  def receive_message(msg)
98
98
  response = JSON.parse(msg.data)
99
99
  # this check is important in case a request timeout and we make new ones after
100
- @response = response if response['requestId'] == @request_id
100
+ if response['requestId'] == @request_id
101
+ if @response.nil?
102
+ @response = response
103
+ else
104
+ @response['result']['data'].concat response['result']['data']
105
+ @response['result']['meta'].merge! response['result']['meta']
106
+ @response['status'] = response['status']
107
+ end
108
+ end
101
109
  end
102
110
 
103
111
  def receive_error(e)
@@ -128,8 +136,15 @@ module GremlinClient
128
136
  @response = nil
129
137
  end
130
138
 
139
+ def is_finished?
140
+ return true unless @error.nil?
141
+ return false if @response.nil?
142
+ return false if @response['status'].nil?
143
+ return @response['status']['code'] != STATUS[:partial_content]
144
+ end
145
+
131
146
  def wait_response
132
- while @response.nil? and @error.nil? && (Time.now.to_i - @started_at < @timeout)
147
+ while !is_finished? && (Time.now.to_i - @started_at < @timeout)
133
148
  sleep 0.001
134
149
  end
135
150
 
@@ -1,3 +1,3 @@
1
1
  module GremliClient
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -27,9 +27,17 @@ RSpec.describe :connection do
27
27
  def self.data
28
28
  @called ||= 0
29
29
  @called += 1
30
- rid = ", \"requestId\" : \"#{@request_id}\"" unless @request_id.nil?
31
- stt = ", \"status\" : { \"code\" : #{@status_code} }" unless @status_code.nil?
32
- "{\"example\" : \"data #{@called}\"#{rid}#{stt}}"
30
+ #rid = ", \"requestId\" : \"#{@request_id}\"" unless @request_id.nil?
31
+ #stt = ", \"status\" : { \"code\" : #{@status_code} }" unless @status_code.nil?
32
+ #"{\'{\"example\" : \"data #{@called}\"#{rid}#{stt}}"
33
+ {
34
+ requestId: @request_id,
35
+ status: { code: @status_code },
36
+ result: {
37
+ data: [@called],
38
+ meta: {},
39
+ },
40
+ }.to_json
33
41
  end
34
42
  end
35
43
 
@@ -75,8 +83,10 @@ RSpec.describe :connection do
75
83
  it :socket_listeners do
76
84
  Message.called = 0
77
85
  conn = GremlinClient::Connection.new
78
- expect(conn.instance_variable_get('@response')).to eq({'example' => 'data 1'})
79
- expect(conn.instance_variable_get('@error').data).to eq("{\"example\" : \"data 2\"}")
86
+ expect(conn.instance_variable_get('@response')['result']['data']).to eq([1])
87
+ expect(conn.instance_variable_get('@error').data).to eq(
88
+ "{\"requestId\":null,\"status\":{\"code\":null},\"result\":{\"data\":[2],\"meta\":{}}}"
89
+ )
80
90
  end
81
91
  end
82
92
 
@@ -133,9 +143,37 @@ RSpec.describe :connection do
133
143
  conn.send(:reset_request)
134
144
  conn.instance_variable_set('@request_id', '123')
135
145
  conn.receive_message(Message)
136
- expect(conn.instance_variable_get('@response')).to eq({'example' => 'data 2', 'requestId' => '123'})
146
+ expect(conn.instance_variable_get('@response')).to eq({
147
+ 'requestId' => '123',
148
+ 'status' => { 'code' => nil },
149
+ 'result' => { 'data' => [2], 'meta' => {} }
150
+ })
151
+ # exit this block reseting this value
152
+ Message.request_id = nil
153
+ end
154
+
155
+ it :partial_message do
156
+ Message.called = 0
157
+
158
+ conn = GremlinClient::Connection.new
159
+ conn.send(:reset_request)
160
+ Message.request_id = conn.instance_variable_get('@request_id')
161
+ Message.status = :partial_content
162
+ conn.receive_message(Message)
163
+ expect(conn.send('is_finished?')).to be false
164
+ Message.status = :success
165
+ conn.receive_message(Message)
166
+ expect(conn.send('is_finished?')).to be true
167
+ expect(conn.instance_variable_get('@response')).to eq({
168
+ 'requestId' => conn.instance_variable_get('@request_id'),
169
+ 'status' => { 'code' => 200 },
170
+ # not 1, 2 because it is called once uppon init
171
+ 'result' => { 'data' => [2, 3], 'meta' => {} }
172
+ })
137
173
  # exit this block reseting this value
138
174
  Message.request_id = nil
175
+ # clear the status
176
+ Message.status = nil
139
177
  end
140
178
  end
141
179
 
@@ -217,8 +255,9 @@ RSpec.describe :connection do
217
255
  conn.receive_message(Message)
218
256
  conn.send(:wait_response)
219
257
  expect(conn.instance_variable_get('@response')).to eq({
220
- 'example' =>'data 1',
221
- 'requestId' => conn.instance_variable_get('@request_id')
258
+ 'requestId' => conn.instance_variable_get('@request_id'),
259
+ 'status' => { 'code' => nil } ,
260
+ 'result' => { 'data' => [1], 'meta' => {} }
222
261
  })
223
262
  end
224
263
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gremlin_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Coraça de Freitas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-02 00:00:00.000000000 Z
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-client-simple
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
158
  version: '0'
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.5.1
161
+ rubygems_version: 2.6.10
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Simple Gremlin server client for the WebSocketChannelizer