groonga-client 0.1.7 → 0.1.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: 730d0d465dfa172d63dc072c41da07393bac121c
4
- data.tar.gz: 2feb754e982010f661b038ba7dbfc24c65391ce1
3
+ metadata.gz: 0c389ff7c62caafda9b4442772fbb3c156b88ae5
4
+ data.tar.gz: b58f127a618a43eb310451e03c8ea065f6cedf65
5
5
  SHA512:
6
- metadata.gz: 82f16e4c99ff5d2df6bb359502ef877cbe7d8366d086303c8af17af1eec5742119812f06e75f23fcf01852bf1ada1ead65d572949bcf4467150b41fcfe3097f1
7
- data.tar.gz: 44e907e66266757ca60262b32ebca650e361c40930aee2bd53881c54909faa7c0bc4354a4167627f6bcf721be49e2c36c95493da4171700d7fe5fde61a4468e8
6
+ metadata.gz: d75b1913b274ab25c157f7a7dce80cbacc48a6764863098e1967bf9adcff4db52ad1d479ee2c0381aa9eaabd5d6dff522e1689dd0f1baa2d6f92056243c4964e
7
+ data.tar.gz: 4dcd03da83116e1484d46ae22a21b6b07d987502fe00c5b19708a56e8fc72f94c0e5393b9829f04c8f7476af27bdca9c598e7c76bcda24f1e658fa94ffe185ab
data/doc/text/news.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.1.8 - 2015-08-08
4
+
5
+ ### Improvements
6
+
7
+ * `load`: Supported `Array` as `values` value.
8
+
3
9
  ## 0.1.7 - 2015-07-08
4
10
 
5
11
  ### Improvements
@@ -54,4 +54,5 @@ Gem::Specification.new do |spec|
54
54
  spec.add_development_dependency("test-unit-rr")
55
55
  spec.add_development_dependency("packnga")
56
56
  spec.add_development_dependency("redcarpet")
57
+ spec.add_development_dependency("groonga-command-parser")
57
58
  end
@@ -17,6 +17,8 @@
17
17
  # License along with this library; if not, write to the Free Software
18
18
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
19
 
20
+ require "json"
21
+
20
22
  require "groonga/client/default"
21
23
  require "groonga/client/command"
22
24
  require "groonga/client/empty-request"
@@ -155,6 +157,20 @@ module Groonga
155
157
  end
156
158
 
157
159
  def load(parameters, &block)
160
+ values = parameters[:values]
161
+ if values.is_a?(Array)
162
+ json = "["
163
+ values.each_with_index do |value, i|
164
+ if i.zero?
165
+ json << "\n"
166
+ else
167
+ json << ",\n"
168
+ end
169
+ json << JSON.generate(value)
170
+ end
171
+ json << "\n]"
172
+ parameters[:values] = json
173
+ end
158
174
  execute_command("load", parameters, &block)
159
175
  end
160
176
 
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Groonga
20
20
  class Client
21
- VERSION = "0.1.7"
21
+ VERSION = "0.1.8"
22
22
  end
23
23
  end
data/test/run-test.rb CHANGED
@@ -31,6 +31,10 @@ groonga_command_base_dir = base_dir.parent + "groonga-command"
31
31
  groonga_command_lib_dir = groonga_command_base_dir + "lib"
32
32
  $LOAD_PATH.unshift(groonga_command_lib_dir.to_s)
33
33
 
34
+ groonga_command_parser_base_dir = base_dir.parent + "groonga-command-parser"
35
+ groonga_command_parser_lib_dir = groonga_command_parser_base_dir + "lib"
36
+ $LOAD_PATH.unshift(groonga_command_parser_lib_dir.to_s)
37
+
34
38
  lib_dir = base_dir + "lib"
35
39
  test_dir = base_dir + "test"
36
40
 
data/test/test-client.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
4
- # Copyright (C) 2013 Kouhei Sutou <kou@clear-code.com>
4
+ # Copyright (C) 2013-2015 Kouhei Sutou <kou@clear-code.com>
5
5
  #
6
6
  # This library is free software; you can redistribute it and/or
7
7
  # modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,8 @@
19
19
 
20
20
  require "time"
21
21
  require "socket"
22
+ require "groonga/command/parser"
23
+
22
24
  require "groonga/client"
23
25
 
24
26
  class TestClient < Test::Unit::TestCase
@@ -224,7 +226,7 @@ JSON
224
226
  end
225
227
 
226
228
  module LoadTests
227
- def test_load
229
+ def test_load_json
228
230
  values = [
229
231
  {"content" => "1st content"},
230
232
  {"content" => "2nd content"},
@@ -234,6 +236,22 @@ JSON
234
236
  response = client.load(:table => "Memos",
235
237
  :values => JSON.generate(values))
236
238
  assert_equal([values.size], response.body)
239
+ assert_equal([values],
240
+ @actual_commands.collect(&:values))
241
+ end
242
+
243
+ def test_load_array
244
+ values = [
245
+ {"content" => "1st content"},
246
+ {"content" => "2nd content"},
247
+ {"content" => "3rd content"},
248
+ ]
249
+ stub_response("[#{values.size}]")
250
+ response = client.load(:table => "Memos",
251
+ :values => values)
252
+ assert_equal([values.size], response.body)
253
+ assert_equal([values],
254
+ @actual_commands.collect(&:values))
237
255
  end
238
256
  end
239
257
 
@@ -258,6 +276,7 @@ JSON
258
276
  @port = @server.addr[1]
259
277
  @protocol = :gqtp
260
278
 
279
+ @actual_commands = []
261
280
  @response_body = nil
262
281
  @thread = Thread.new do
263
282
  client = @server.accept
@@ -268,7 +287,8 @@ JSON
268
287
  break if raw_header.nil?
269
288
 
270
289
  header = GQTP::Header.parse(raw_header)
271
- client.read(header.size)
290
+ body = client.read(header.size)
291
+ @actual_commands << Groonga::Command::Parser.parse(body)
272
292
 
273
293
  response_header = GQTP::Header.new
274
294
  response_header.size = @response_body.bytesize
@@ -296,18 +316,36 @@ JSON
296
316
  @port = @server.addr[1]
297
317
  @protocol = :http
298
318
 
299
- @actual_method = nil
300
- @actual_path = nil
301
-
319
+ @actual_commands = []
302
320
  @response_body = nil
303
321
  @thread = Thread.new do
304
322
  client = @server.accept
305
323
  first_line = client.gets
306
324
  if /\A([\w]+) ([^ ]+) HTTP/ =~ first_line
307
- @actual_method = $1
308
- @actual_path = $2
325
+ # http_method = $1
326
+ path = $2
327
+ headers = {}
328
+ client.each_line do |line|
329
+ case line
330
+ when "\r\n"
331
+ break
332
+ else
333
+ name, value = line.strip.split(/: */, 2)
334
+ headers[name.downcase] = value
335
+ end
336
+ end
337
+ content_length = headers["content-length"]
338
+ if content_length
339
+ body = client.read(Integer(content_length))
340
+ else
341
+ body = nil
342
+ end
343
+ command = Groonga::Command::Parser.parse(path)
344
+ command[:values] = body if body
345
+ @actual_commands << command
309
346
  end
310
347
  @server.close
348
+
311
349
  status = 0
312
350
  start = Time.now.to_f
313
351
  elapsed = rand
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-07-08 00:00:00.000000000 Z
13
+ date: 2015-08-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gqtp
@@ -138,6 +138,20 @@ dependencies:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: groonga-command-parser
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
141
155
  description: |
142
156
  Groonga-client gem supports HTTP or
143
157
  [GQTP (Groonga Query Transfer Protocol)](http://groonga.org/docs/spec/gqtp.html)