groonga-client 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -4
- data/doc/text/news.md +33 -0
- data/groonga-client.gemspec +4 -4
- data/lib/groonga/client.rb +108 -98
- data/lib/groonga/client/protocol/gqtp.rb +4 -5
- data/lib/groonga/client/protocol/http.rb +3 -4
- data/lib/groonga/client/protocol/http/coolio.rb +1 -1
- data/lib/groonga/client/protocol/http/synchronous.rb +35 -8
- data/lib/groonga/client/response.rb +2 -0
- data/lib/groonga/client/response/base.rb +13 -3
- data/lib/groonga/client/response/table_remove.rb +28 -0
- data/lib/groonga/client/version.rb +1 -1
- data/test/protocol/test-gqtp.rb +9 -10
- data/test/protocol/test-http.rb +4 -8
- data/test/response/test-table-create.rb +32 -0
- data/test/response/test-table-remove.rb +32 -0
- data/test/test-client.rb +102 -7
- data/test/test-command.rb +11 -6
- metadata +20 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e8cad3043939d233594ca90f8b84ea33725d5b5
|
4
|
+
data.tar.gz: d8ae56764fe0a86509ef2b6cbe5762242cdb0dcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d1f57297335e1d324fea8e867b6703ad44222effb6c6b23aa49163747bc98fbc70013227180b4a0c00e1b632d3f8df70d639157fbfaba169876128fa6796dc8
|
7
|
+
data.tar.gz: 66bd55f2b48c53208fb0596101b80277e04ab1151321c74e5ff27169998a6b09197039c9793a96f9d3bf68f54534058fddb9c802b5ca820700566d01f2bebbe3
|
data/README.md
CHANGED
@@ -50,10 +50,6 @@ TODO: use commands with parameters for examples
|
|
50
50
|
* English: [groonga-talk@lists.sourceforge.net](https://lists.sourceforge.net/lists/listinfo/groonga-talk)
|
51
51
|
* Japanese: [groonga-dev@lists.sourceforge.jp](http://lists.sourceforge.jp/mailman/listinfo/groonga-dev)
|
52
52
|
|
53
|
-
## Thanks
|
54
|
-
|
55
|
-
* ...
|
56
|
-
|
57
53
|
## Authors
|
58
54
|
|
59
55
|
* Haruka Yoshihara \<yoshihara@clear-code.com\>
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,38 @@
|
|
1
1
|
# NEWS
|
2
2
|
|
3
|
+
## 0.2.0 - 2016-03-21
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* HTTP: Supported basic authentication.
|
8
|
+
[GitHub#4][Patch by KITAITI Makoto]
|
9
|
+
|
10
|
+
* response: Supported `table_remove`.
|
11
|
+
[GitHub#7][Patch by Masafumi Yokoyama]
|
12
|
+
|
13
|
+
* HTTP: Supported HTTPS by passing `:use_tls => true` option to
|
14
|
+
{Groonga::Client.new}.
|
15
|
+
[GitHub#8][Patch by KITAITI Makoto]
|
16
|
+
|
17
|
+
* Supported URI as server information in {Groonga::Client.new}.
|
18
|
+
|
19
|
+
* Required groonga-command 1.2.0 or later.
|
20
|
+
|
21
|
+
* Accepted `Symbol` as registered command name.
|
22
|
+
|
23
|
+
* Supported dynamic command execution. Now, you can use commands
|
24
|
+
that aren't supported in groonga-client yet.
|
25
|
+
|
26
|
+
* Added {Groonga::Client.default_options}.
|
27
|
+
|
28
|
+
* Added {Groonga::Client.default_options=}.
|
29
|
+
|
30
|
+
### Thanks
|
31
|
+
|
32
|
+
* KITAITI Makoto
|
33
|
+
|
34
|
+
* Masafumi Yokoyama
|
35
|
+
|
3
36
|
## 0.1.9 - 2015-09-04
|
4
37
|
|
5
38
|
### Improvements
|
data/groonga-client.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# -*- mode: ruby
|
1
|
+
# -*- mode: ruby -*-
|
2
2
|
#
|
3
3
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2014-
|
4
|
+
# Copyright (C) 2014-2016 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
|
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
clean_white_space.call(entries[entries.index("Description") + 1])
|
38
38
|
description = clean_white_space.call(entries[entries.index("Description") + 1])
|
39
39
|
spec.summary, spec.description, = description.split(/\n\n+/, 3)
|
40
|
-
spec.license = "LGPLv2.1
|
40
|
+
spec.license = "LGPLv2.1+"
|
41
41
|
spec.files = ["README.md", "Rakefile", "Gemfile", "#{spec.name}.gemspec"]
|
42
42
|
spec.files += [".yardopts"]
|
43
43
|
spec.files += Dir.glob("lib/**/*.rb")
|
@@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
|
|
45
45
|
spec.test_files += Dir.glob("test/**/*")
|
46
46
|
|
47
47
|
spec.add_runtime_dependency("gqtp", ">= 1.0.4")
|
48
|
-
spec.add_runtime_dependency("groonga-command", ">= 1.0
|
48
|
+
spec.add_runtime_dependency("groonga-command", ">= 1.2.0")
|
49
49
|
|
50
50
|
spec.add_development_dependency("bundler")
|
51
51
|
spec.add_development_dependency("rake")
|
data/lib/groonga/client.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
5
3
|
#
|
6
4
|
# This library is free software; you can redistribute it and/or
|
7
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -17,6 +15,7 @@
|
|
17
15
|
# License along with this library; if not, write to the Free Software
|
18
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19
17
|
|
18
|
+
require "uri"
|
20
19
|
require "json"
|
21
20
|
|
22
21
|
require "groonga/client/default"
|
@@ -29,10 +28,33 @@ require "groonga/client/script-syntax"
|
|
29
28
|
module Groonga
|
30
29
|
class Client
|
31
30
|
class << self
|
31
|
+
@@deafult_options = {}
|
32
|
+
|
33
|
+
# @return [Hash] The default options for {Groonga::Client.new}.
|
34
|
+
#
|
35
|
+
# @since 0.2.0
|
36
|
+
def default_options
|
37
|
+
@@deafult_options
|
38
|
+
end
|
39
|
+
|
40
|
+
# @param [Hash] options The new default options for
|
41
|
+
# {Groonga::Client.new}.
|
42
|
+
#
|
43
|
+
# @since 0.2.0
|
44
|
+
def default_options=(options)
|
45
|
+
@@deafult_options = options
|
46
|
+
end
|
47
|
+
|
32
48
|
# @!macro [new] initialize_options
|
33
49
|
# @param [Hash] options The options.
|
34
|
-
# @option options [
|
35
|
-
#
|
50
|
+
# @option options [String, URI::Generic, URI::HTTP, URI::HTTPS]
|
51
|
+
# :url The URL of Groonga server.
|
52
|
+
# @option options [:gqtp, :http, :https] :protocol The
|
53
|
+
# protocol that is used by the client.
|
54
|
+
# @option options [String] :user User ID. Currently used for HTTP
|
55
|
+
# Basic Authentication.
|
56
|
+
# @option options [String] :password Password. Currently used for
|
57
|
+
# HTTP Basic Authentication.
|
36
58
|
#
|
37
59
|
# @overload open(options={})
|
38
60
|
# Opens a new client connection.
|
@@ -66,15 +88,22 @@ module Groonga
|
|
66
88
|
|
67
89
|
# @macro initialize_options
|
68
90
|
def initialize(options={})
|
69
|
-
options = options
|
70
|
-
|
91
|
+
options = self.class.default_options.merge(options)
|
92
|
+
url = options[:url] || build_url(options)
|
93
|
+
url = URL.parse(url) unless url.is_a?(URI::Generic)
|
94
|
+
options[:url] = url
|
71
95
|
options[:read_timeout] ||= Default::READ_TIMEOUT
|
72
96
|
|
73
97
|
@connection = nil
|
74
|
-
|
75
|
-
|
98
|
+
case url.scheme
|
99
|
+
when "gqtp"
|
100
|
+
@connection = Groonga::Client::Protocol::GQTP.new(url, options)
|
101
|
+
when "http", "https"
|
102
|
+
@connection = Groonga::Client::Protocol::HTTP.new(url, options)
|
76
103
|
else
|
77
|
-
|
104
|
+
message = "unsupported scheme: <#{url.scheme}>: "
|
105
|
+
message << "supported: [gqtp, http, https]"
|
106
|
+
raise ArgumentError, message
|
78
107
|
end
|
79
108
|
end
|
80
109
|
|
@@ -117,46 +146,6 @@ module Groonga
|
|
117
146
|
end
|
118
147
|
end
|
119
148
|
|
120
|
-
def cache_limit(parameters, &block)
|
121
|
-
execute_command("cache_limit", parameters, &block)
|
122
|
-
end
|
123
|
-
|
124
|
-
def check(parameters, &block)
|
125
|
-
execute_command("check", parameters, &block)
|
126
|
-
end
|
127
|
-
|
128
|
-
def clearlock(parameters={}, &block)
|
129
|
-
execute_command("clearlock", parameters, &block)
|
130
|
-
end
|
131
|
-
|
132
|
-
def column_create(parameters, &block)
|
133
|
-
execute_command("column_create", parameters, &block)
|
134
|
-
end
|
135
|
-
|
136
|
-
def column_list(parameters, &block)
|
137
|
-
execute_command("column_list", parameters, &block)
|
138
|
-
end
|
139
|
-
|
140
|
-
def column_remove(parameters, &block)
|
141
|
-
execute_command("column_remove", parameters, &block)
|
142
|
-
end
|
143
|
-
|
144
|
-
def column_rename(parameters, &block)
|
145
|
-
execute_command("column_rename", parameters, &block)
|
146
|
-
end
|
147
|
-
|
148
|
-
def defrag(parameters={}, &block)
|
149
|
-
execute_command("defrag", parameters, &block)
|
150
|
-
end
|
151
|
-
|
152
|
-
def delete(parameters, &block)
|
153
|
-
execute_command("delete", parameters, &block)
|
154
|
-
end
|
155
|
-
|
156
|
-
def dump(parameters={}, &block)
|
157
|
-
execute_command("dump", parameters, &block)
|
158
|
-
end
|
159
|
-
|
160
149
|
def load(parameters, &block)
|
161
150
|
values = parameters[:values]
|
162
151
|
if values.is_a?(Array)
|
@@ -172,67 +161,84 @@ module Groonga
|
|
172
161
|
json << "\n]"
|
173
162
|
parameters[:values] = json
|
174
163
|
end
|
175
|
-
|
176
|
-
end
|
177
|
-
|
178
|
-
def log_level(parameters, &block)
|
179
|
-
execute_command("log_level", parameters, &block)
|
180
|
-
end
|
181
|
-
|
182
|
-
def log_put(parameters, &block)
|
183
|
-
execute_command("log_put", parameters, &block)
|
164
|
+
execute(:load, parameters, &block)
|
184
165
|
end
|
185
166
|
|
186
|
-
def
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
execute_command(
|
196
|
-
end
|
197
|
-
|
198
|
-
def select(parameters, &block)
|
199
|
-
execute_command("select", parameters, &block)
|
200
|
-
end
|
201
|
-
|
202
|
-
def shutdown(parameters={}, &block)
|
203
|
-
end
|
204
|
-
|
205
|
-
def status(parameters={}, &block)
|
206
|
-
execute_command("status", parameters, &block)
|
207
|
-
end
|
208
|
-
|
209
|
-
def table_create(parameters, &block)
|
210
|
-
execute_command("table_create", parameters, &block)
|
167
|
+
def execute(command_or_name, parameters={}, &block)
|
168
|
+
if command_or_name.is_a?(Command)
|
169
|
+
command = command_or_name
|
170
|
+
else
|
171
|
+
command_name = command_or_name
|
172
|
+
parameters = normalize_parameters(parameters)
|
173
|
+
command_class = Groonga::Command.find(command_name)
|
174
|
+
command = command_class.new(command_name, parameters)
|
175
|
+
end
|
176
|
+
execute_command(command, &block)
|
211
177
|
end
|
212
178
|
|
213
|
-
def
|
214
|
-
|
179
|
+
def method_missing(name, *args, **kwargs, &block)
|
180
|
+
if groonga_command_name?(name)
|
181
|
+
execute(name, *args, **kwargs, &block)
|
182
|
+
else
|
183
|
+
super
|
184
|
+
end
|
215
185
|
end
|
216
186
|
|
217
|
-
def
|
187
|
+
def respond_to_missing?(name, include_private)
|
188
|
+
if groonga_command_name?(name)
|
189
|
+
true
|
190
|
+
else
|
191
|
+
super
|
192
|
+
end
|
218
193
|
end
|
219
194
|
|
220
|
-
|
221
|
-
|
195
|
+
private
|
196
|
+
def build_url(options)
|
197
|
+
scheme = (options.delete(:protocol) || "gqtp").to_s
|
198
|
+
host = options.delete(:host) || options.delete(:address) || "127.0.0.1"
|
199
|
+
port = options.delete(:port) || default_port(scheme)
|
200
|
+
user = options.delete(:user)
|
201
|
+
password = options.delete(:password)
|
202
|
+
if user and password
|
203
|
+
userinfo = "#{user}:#{password}"
|
204
|
+
else
|
205
|
+
userinfo = nil
|
206
|
+
end
|
222
207
|
|
223
|
-
|
208
|
+
arguments = [
|
209
|
+
scheme,
|
210
|
+
userinfo,
|
211
|
+
host,
|
212
|
+
port,
|
213
|
+
nil,
|
214
|
+
nil,
|
215
|
+
nil,
|
216
|
+
nil,
|
217
|
+
nil,
|
218
|
+
]
|
219
|
+
case scheme
|
220
|
+
when "http"
|
221
|
+
URI::HTTP.new(*arguments)
|
222
|
+
when "https"
|
223
|
+
URI::HTTPS.new(*arguments)
|
224
|
+
else
|
225
|
+
URI::Generic.new(*arguments)
|
226
|
+
end
|
224
227
|
end
|
225
228
|
|
226
|
-
def
|
227
|
-
|
229
|
+
def default_port(scheme)
|
230
|
+
case scheme
|
231
|
+
when "gqtp"
|
232
|
+
10043
|
233
|
+
when "http", "https"
|
234
|
+
10041
|
235
|
+
else
|
236
|
+
nil
|
237
|
+
end
|
228
238
|
end
|
229
239
|
|
230
|
-
|
231
|
-
|
232
|
-
parameters = normalize_parameters(parameters)
|
233
|
-
command_class = Groonga::Command.find(command_name)
|
234
|
-
command = command_class.new(command_name, parameters)
|
235
|
-
execute(command, &block)
|
240
|
+
def groonga_command_name?(name)
|
241
|
+
/\A[a-zA-Z][a-zA-Z\d_]+\z/ === name.to_s
|
236
242
|
end
|
237
243
|
|
238
244
|
def normalize_parameters(parameters)
|
@@ -242,5 +248,9 @@ module Groonga
|
|
242
248
|
end
|
243
249
|
normalized_parameters
|
244
250
|
end
|
251
|
+
|
252
|
+
def execute_command(command, &block)
|
253
|
+
Client::Command.new(command).execute(@connection, &block)
|
254
|
+
end
|
245
255
|
end
|
246
256
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
5
3
|
#
|
6
4
|
# This library is free software; you can redistribute it and/or
|
7
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -29,9 +27,10 @@ module Groonga
|
|
29
27
|
class Client
|
30
28
|
module Protocol
|
31
29
|
class GQTP
|
32
|
-
def initialize(options)
|
30
|
+
def initialize(url, options={})
|
33
31
|
begin
|
34
|
-
@client = ::GQTP::Client.new(
|
32
|
+
@client = ::GQTP::Client.new(:host => url.host,
|
33
|
+
:port => url.port)
|
35
34
|
rescue ::GQTP::ConnectionError
|
36
35
|
raise WrappedError.new($!)
|
37
36
|
end
|
@@ -32,9 +32,8 @@ module Groonga
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def initialize(options)
|
36
|
-
@
|
37
|
-
@port = options[:port] || 10041
|
35
|
+
def initialize(url, options)
|
36
|
+
@url = url
|
38
37
|
@options = default_options.merge(options)
|
39
38
|
@backend = create_backend
|
40
39
|
end
|
@@ -69,7 +68,7 @@ module Groonga
|
|
69
68
|
|
70
69
|
backend_name = backend.to_s.capitalize
|
71
70
|
backend_class = self.class.const_get(backend_name)
|
72
|
-
backend_class.new(@
|
71
|
+
backend_class.new(@url, @options)
|
73
72
|
end
|
74
73
|
end
|
75
74
|
end
|
@@ -73,7 +73,7 @@ module Groonga
|
|
73
73
|
def send(command, &block)
|
74
74
|
client = GroongaHTTPClient.connect(@host, @port, block)
|
75
75
|
client.attach(@loop)
|
76
|
-
if command.
|
76
|
+
if command.is_a?(Groonga::Command::Load)
|
77
77
|
raw_values = command[:values]
|
78
78
|
command[:values] = nil
|
79
79
|
path = command.to_uri_format
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
2
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
3
3
|
#
|
4
4
|
# This library is free software; you can redistribute it and/or
|
5
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -26,15 +26,14 @@ module Groonga
|
|
26
26
|
module Protocol
|
27
27
|
class HTTP
|
28
28
|
class Synchronous
|
29
|
-
def initialize(
|
30
|
-
@
|
31
|
-
@port = port
|
29
|
+
def initialize(url, options={})
|
30
|
+
@url = url
|
32
31
|
@options = options
|
33
32
|
end
|
34
33
|
|
35
34
|
def send(command)
|
36
35
|
begin
|
37
|
-
Net::HTTP.start(@host, @port) do |http|
|
36
|
+
Net::HTTP.start(@url.host, @url.port, start_options) do |http|
|
38
37
|
http.read_timeout = read_timeout
|
39
38
|
response = send_request(http, command)
|
40
39
|
case response
|
@@ -90,6 +89,23 @@ module Groonga
|
|
90
89
|
end
|
91
90
|
|
92
91
|
private
|
92
|
+
def start_options
|
93
|
+
tls_options = @options[:tls] || {}
|
94
|
+
case tls_options[:verify_mode]
|
95
|
+
when :none
|
96
|
+
tls_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE
|
97
|
+
when :peer
|
98
|
+
tls_options[:verify_mode] = OpenSSL::SSL::VERIFY_PEER
|
99
|
+
end
|
100
|
+
|
101
|
+
{
|
102
|
+
:use_ssl => @url.scheme == "https",
|
103
|
+
:ca_file => tls_options[:ca_file],
|
104
|
+
:ca_path => tls_options[:ca_path],
|
105
|
+
:verify_mode => tls_options[:verify_mode],
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
93
109
|
def read_timeout
|
94
110
|
timeout = @options[:read_timeout]
|
95
111
|
if timeout < 0
|
@@ -100,7 +116,7 @@ module Groonga
|
|
100
116
|
end
|
101
117
|
|
102
118
|
def send_request(http, command)
|
103
|
-
if command.
|
119
|
+
if command.is_a?(Groonga::Command::Load)
|
104
120
|
raw_values = command[:values]
|
105
121
|
command[:values] = nil
|
106
122
|
path = command.to_uri_format
|
@@ -109,10 +125,11 @@ module Groonga
|
|
109
125
|
request.content_type = "application/json"
|
110
126
|
request.content_length = raw_values.bytesize
|
111
127
|
request.body_stream = StringIO.new(raw_values)
|
112
|
-
http.request(request)
|
113
128
|
else
|
114
|
-
|
129
|
+
request = Net::HTTP::Get.new(command.to_uri_format, headers)
|
115
130
|
end
|
131
|
+
setup_authentication(request)
|
132
|
+
http.request(request)
|
116
133
|
end
|
117
134
|
|
118
135
|
def headers
|
@@ -120,6 +137,16 @@ module Groonga
|
|
120
137
|
"user-agent" => @options[:user_agent],
|
121
138
|
}
|
122
139
|
end
|
140
|
+
|
141
|
+
def setup_authentication(request)
|
142
|
+
userinfo = @url.userinfo
|
143
|
+
return if userinfo.nil?
|
144
|
+
|
145
|
+
user, password = userinfo.split(/:/, 2).collect do |component|
|
146
|
+
URI.decode_www_form_component(component)
|
147
|
+
end
|
148
|
+
request.basic_auth(user, password)
|
149
|
+
end
|
123
150
|
end
|
124
151
|
end
|
125
152
|
end
|
@@ -36,4 +36,6 @@ require "groonga/client/response/quit"
|
|
36
36
|
require "groonga/client/response/register"
|
37
37
|
require "groonga/client/response/select"
|
38
38
|
require "groonga/client/response/status"
|
39
|
+
require "groonga/client/response/table_create"
|
39
40
|
require "groonga/client/response/table_list"
|
41
|
+
require "groonga/client/response/table_remove"
|
@@ -27,11 +27,11 @@ module Groonga
|
|
27
27
|
class << self
|
28
28
|
@@registered_commands = {}
|
29
29
|
def register(name, klass)
|
30
|
-
@@registered_commands[name] = klass
|
30
|
+
@@registered_commands[normalize_name(name)] = klass
|
31
31
|
end
|
32
32
|
|
33
33
|
def find(name)
|
34
|
-
@@registered_commands[name] || Base
|
34
|
+
@@registered_commands[normalize_name(name)] || Base
|
35
35
|
end
|
36
36
|
|
37
37
|
# Parses the response for the request of the command and returns
|
@@ -42,9 +42,19 @@ module Groonga
|
|
42
42
|
# server.
|
43
43
|
# @return [Base]
|
44
44
|
def parse(command, raw_response)
|
45
|
-
klass = find(command.
|
45
|
+
klass = find(command.command_name)
|
46
46
|
klass.parse(command, raw_response)
|
47
47
|
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def normalize_name(name)
|
51
|
+
case name
|
52
|
+
when String
|
53
|
+
name.to_sym
|
54
|
+
else
|
55
|
+
name
|
56
|
+
end
|
57
|
+
end
|
48
58
|
end
|
49
59
|
|
50
60
|
class Base
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "groonga/client/response/base"
|
18
|
+
|
19
|
+
module Groonga
|
20
|
+
class Client
|
21
|
+
module Response
|
22
|
+
class TableRemove < Base
|
23
|
+
Response.register("table_remove", self)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
data/test/protocol/test-gqtp.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
4
2
|
#
|
5
3
|
# This library is free software; you can redistribute it and/or
|
6
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -60,11 +58,10 @@ class TestProtocolGQTP < Test::Unit::TestCase
|
|
60
58
|
|
61
59
|
private
|
62
60
|
def connect(options={})
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Groonga::Client::Protocol::GQTP.new(default_options.merge(options))
|
61
|
+
url = URI::Generic.build(:scheme => "gqtp",
|
62
|
+
:host => @address,
|
63
|
+
:port => @port)
|
64
|
+
Groonga::Client::Protocol::GQTP.new(url, options)
|
68
65
|
end
|
69
66
|
|
70
67
|
def process_client_close(client)
|
@@ -84,9 +81,11 @@ class TestProtocolGQTP < Test::Unit::TestCase
|
|
84
81
|
server = TCPServer.new("127.0.0.1", 0)
|
85
82
|
free_port = server.addr[1]
|
86
83
|
server.close
|
84
|
+
url = URI::Generic.build(:scheme => "gqtp",
|
85
|
+
:host => "127.0.0.1",
|
86
|
+
:port => free_port)
|
87
87
|
assert_raise(Groonga::Client::Protocol::WrappedError) do
|
88
|
-
Groonga::Client::Protocol::GQTP.new(
|
89
|
-
:port => free_port)
|
88
|
+
Groonga::Client::Protocol::GQTP.new(url, {})
|
90
89
|
end
|
91
90
|
end
|
92
91
|
end
|
data/test/protocol/test-http.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
# Copyright (C) 2013-2014 Kouhei Sutou <kou@clear-code.com>
|
1
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
4
2
|
#
|
5
3
|
# This library is free software; you can redistribute it and/or
|
6
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -74,11 +72,9 @@ EOH
|
|
74
72
|
end
|
75
73
|
|
76
74
|
def connect(options={})
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
Groonga::Client::Protocol::HTTP.new(default_options.merge(options))
|
75
|
+
url = URI::HTTP.build(:host => @address,
|
76
|
+
:port => @port)
|
77
|
+
Groonga::Client::Protocol::HTTP.new(url, options)
|
82
78
|
end
|
83
79
|
|
84
80
|
def test_connected?
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "response/helper"
|
18
|
+
|
19
|
+
class TestResponseTableCreate < Test::Unit::TestCase
|
20
|
+
class TestParseRawResponse < self
|
21
|
+
include TestResponseHelper
|
22
|
+
|
23
|
+
def test_table_create
|
24
|
+
header = [0,1372430096.70991,0.000522851943969727]
|
25
|
+
body = true
|
26
|
+
raw_response = [header, body].to_json
|
27
|
+
|
28
|
+
response = parse_raw_response("table_create", raw_response)
|
29
|
+
assert_equal(Groonga::Client::Response::TableCreate, response.class)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (C) 2016 Masafumi Yokoyama <yokoyama@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "response/helper"
|
18
|
+
|
19
|
+
class TestResponseTableRemove < Test::Unit::TestCase
|
20
|
+
class TestParseRawResponse < self
|
21
|
+
include TestResponseHelper
|
22
|
+
|
23
|
+
def test_table_remove
|
24
|
+
header = [0,1372430096.70991,0.000522851943969727]
|
25
|
+
body = true
|
26
|
+
raw_response = [header, body].to_json
|
27
|
+
|
28
|
+
response = parse_raw_response("table_remove", raw_response)
|
29
|
+
assert_equal(Groonga::Client::Response::TableRemove, response.class)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/test-client.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
#
|
3
1
|
# Copyright (C) 2013 Haruka Yoshihara <yoshihara@clear-code.com>
|
4
|
-
# Copyright (C) 2013-
|
2
|
+
# Copyright (C) 2013-2016 Kouhei Sutou <kou@clear-code.com>
|
5
3
|
#
|
6
4
|
# This library is free software; you can redistribute it and/or
|
7
5
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -49,9 +47,20 @@ class TestClient < Test::Unit::TestCase
|
|
49
47
|
@client ||= open_client
|
50
48
|
end
|
51
49
|
|
50
|
+
def open_options
|
51
|
+
url = "#{@protocol}://"
|
52
|
+
if @user and @password
|
53
|
+
url << URI.encode_www_form_component(@user)
|
54
|
+
url << ":"
|
55
|
+
url << URI.encode_www_form_component(@password)
|
56
|
+
url << "@"
|
57
|
+
end
|
58
|
+
url << "#{@address}:#{@port}"
|
59
|
+
{:url => URI.parse(url)}
|
60
|
+
end
|
61
|
+
|
52
62
|
def open_client(&block)
|
53
|
-
|
54
|
-
Groonga::Client.open(options, &block)
|
63
|
+
Groonga::Client.open(open_options, &block)
|
55
64
|
end
|
56
65
|
|
57
66
|
def stub_response(body, output_type=:json)
|
@@ -223,6 +232,19 @@ JSON
|
|
223
232
|
end
|
224
233
|
assert_equal("response", response)
|
225
234
|
end
|
235
|
+
|
236
|
+
def test_open_components
|
237
|
+
stub_response("[29]")
|
238
|
+
options = {
|
239
|
+
:host => @address,
|
240
|
+
:port => @port,
|
241
|
+
:protocol => @protocol,
|
242
|
+
}
|
243
|
+
response = Groonga::Client.open(options) do |client|
|
244
|
+
client.status
|
245
|
+
end
|
246
|
+
assert_equal([29], response.body)
|
247
|
+
end
|
226
248
|
end
|
227
249
|
|
228
250
|
module LoadTests
|
@@ -255,6 +277,29 @@ JSON
|
|
255
277
|
end
|
256
278
|
end
|
257
279
|
|
280
|
+
module DefaultOptionsTests
|
281
|
+
def test_default_options
|
282
|
+
change_default_options(open_options) do
|
283
|
+
expected_response = {"key" => "value"}
|
284
|
+
stub_response(expected_response.to_json)
|
285
|
+
response = Groonga::Client.open do |client|
|
286
|
+
client.status
|
287
|
+
end
|
288
|
+
assert_equal(expected_response, response.body)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def change_default_options(options)
|
293
|
+
default_options = Groonga::Client.default_options
|
294
|
+
begin
|
295
|
+
Groonga::Client.default_options = options
|
296
|
+
yield
|
297
|
+
ensure
|
298
|
+
Groonga::Client.default_options = default_options
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
258
303
|
module Tests
|
259
304
|
include Utils
|
260
305
|
include Assertions
|
@@ -264,6 +309,7 @@ JSON
|
|
264
309
|
include ParametersTests
|
265
310
|
include OpenTests
|
266
311
|
include LoadTests
|
312
|
+
include DefaultOptionsTests
|
267
313
|
end
|
268
314
|
|
269
315
|
class TestGQTP < self
|
@@ -276,6 +322,8 @@ JSON
|
|
276
322
|
@port = @server.addr[1]
|
277
323
|
@protocol = :gqtp
|
278
324
|
|
325
|
+
@user = nil
|
326
|
+
@password = nil
|
279
327
|
@actual_commands = []
|
280
328
|
@response_body = nil
|
281
329
|
@thread = Thread.new do
|
@@ -316,6 +364,9 @@ JSON
|
|
316
364
|
@port = @server.addr[1]
|
317
365
|
@protocol = :http
|
318
366
|
|
367
|
+
setup_authentication
|
368
|
+
@request_headers = {}
|
369
|
+
@request_path = nil
|
319
370
|
@actual_commands = []
|
320
371
|
@response_body = nil
|
321
372
|
@thread = Thread.new do
|
@@ -323,7 +374,7 @@ JSON
|
|
323
374
|
first_line = client.gets
|
324
375
|
if /\A([\w]+) ([^ ]+) HTTP/ =~ first_line
|
325
376
|
# http_method = $1
|
326
|
-
|
377
|
+
@request_path = $2
|
327
378
|
headers = {}
|
328
379
|
client.each_line do |line|
|
329
380
|
case line
|
@@ -334,13 +385,14 @@ JSON
|
|
334
385
|
headers[name.downcase] = value
|
335
386
|
end
|
336
387
|
end
|
388
|
+
@request_headers = headers
|
337
389
|
content_length = headers["content-length"]
|
338
390
|
if content_length
|
339
391
|
body = client.read(Integer(content_length))
|
340
392
|
else
|
341
393
|
body = nil
|
342
394
|
end
|
343
|
-
command = Groonga::Command::Parser.parse(
|
395
|
+
command = Groonga::Command::Parser.parse(@request_path)
|
344
396
|
command[:values] = body if body
|
345
397
|
@actual_commands << command
|
346
398
|
end
|
@@ -374,5 +426,48 @@ EOH
|
|
374
426
|
client.close
|
375
427
|
end
|
376
428
|
end
|
429
|
+
|
430
|
+
def setup_authentication
|
431
|
+
@user = nil
|
432
|
+
@password = nil
|
433
|
+
end
|
434
|
+
|
435
|
+
class TestLoad < self
|
436
|
+
def test_path
|
437
|
+
stub_response("[]")
|
438
|
+
client.load(:table => "Memos", :values => [])
|
439
|
+
assert_equal("/d/load?table=Memos", @request_path)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
class TestBasicAuthentication < self
|
444
|
+
def setup_authentication
|
445
|
+
@user = "Aladdin"
|
446
|
+
@password = "open sesame"
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_request_header
|
450
|
+
stub_response("[]")
|
451
|
+
client.status
|
452
|
+
assert_equal("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
|
453
|
+
@request_headers["authorization"])
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_open_components
|
457
|
+
stub_response("[]")
|
458
|
+
options = {
|
459
|
+
:host => @address,
|
460
|
+
:port => @port,
|
461
|
+
:protocol => @protocol,
|
462
|
+
:user => @user,
|
463
|
+
:password => @password,
|
464
|
+
}
|
465
|
+
Groonga::Client.open(options) do |client|
|
466
|
+
client.status
|
467
|
+
end
|
468
|
+
assert_equal("Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
|
469
|
+
@request_headers["authorization"])
|
470
|
+
end
|
471
|
+
end
|
377
472
|
end
|
378
473
|
end
|
data/test/test-command.rb
CHANGED
@@ -5,7 +5,7 @@ class TestCommand < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
def test_column_create
|
7
7
|
response = Object.new
|
8
|
-
mock(@client).
|
8
|
+
mock(@client).execute(:column_create, :table => :Test, :name => :Body, :type => :ShortText) do
|
9
9
|
response
|
10
10
|
end
|
11
11
|
@client.column_create(:table => :Test, :name => :Body, :type => :ShortText)
|
@@ -13,7 +13,7 @@ class TestCommand < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
def test_column_list
|
15
15
|
response = Object.new
|
16
|
-
mock(@client).
|
16
|
+
mock(@client).execute(:column_list, :table => :Test) do
|
17
17
|
response
|
18
18
|
end
|
19
19
|
@client.column_list(:table => :Test)
|
@@ -27,7 +27,7 @@ class TestCommand < Test::Unit::TestCase
|
|
27
27
|
}
|
28
28
|
]
|
29
29
|
response = Object.new
|
30
|
-
mock(@client).
|
30
|
+
mock(@client).execute(:load, :table => :Test, :values => values.to_json) do
|
31
31
|
response
|
32
32
|
end
|
33
33
|
@client.load(:table => :Test, :values => values.to_json)
|
@@ -35,7 +35,7 @@ class TestCommand < Test::Unit::TestCase
|
|
35
35
|
|
36
36
|
def test_select
|
37
37
|
response = Object.new
|
38
|
-
mock(@client).
|
38
|
+
mock(@client).execute(:select, :table => :Test) do
|
39
39
|
response
|
40
40
|
end
|
41
41
|
@client.select(:table => :Test)
|
@@ -43,7 +43,7 @@ class TestCommand < Test::Unit::TestCase
|
|
43
43
|
|
44
44
|
def test_table_create
|
45
45
|
response = Object.new
|
46
|
-
mock(@client).
|
46
|
+
mock(@client).execute(:table_create, :name => :Test) do
|
47
47
|
response
|
48
48
|
end
|
49
49
|
@client.table_create(:name => :Test)
|
@@ -51,9 +51,14 @@ class TestCommand < Test::Unit::TestCase
|
|
51
51
|
|
52
52
|
def test_table_list
|
53
53
|
response = Object.new
|
54
|
-
mock(@client).
|
54
|
+
mock(@client).execute(:table_list, {}) do
|
55
55
|
response
|
56
56
|
end
|
57
57
|
@client.table_list
|
58
58
|
end
|
59
|
+
|
60
|
+
def test_table_remove
|
61
|
+
mock(@client).execute(:table_remove, :name => "Test")
|
62
|
+
@client.table_remove(:name => "Test")
|
63
|
+
end
|
59
64
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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:
|
13
|
+
date: 2016-03-21 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: gqtp
|
@@ -32,14 +32,14 @@ dependencies:
|
|
32
32
|
requirements:
|
33
33
|
- - ">="
|
34
34
|
- !ruby/object:Gem::Version
|
35
|
-
version: 1.0
|
35
|
+
version: 1.2.0
|
36
36
|
type: :runtime
|
37
37
|
prerelease: false
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: 1.0
|
42
|
+
version: 1.2.0
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: bundler
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- lib/groonga/client/response/status.rb
|
207
207
|
- lib/groonga/client/response/table_create.rb
|
208
208
|
- lib/groonga/client/response/table_list.rb
|
209
|
+
- lib/groonga/client/response/table_remove.rb
|
209
210
|
- lib/groonga/client/script-syntax.rb
|
210
211
|
- lib/groonga/client/version.rb
|
211
212
|
- test/protocol/test-gqtp.rb
|
@@ -216,7 +217,9 @@ files:
|
|
216
217
|
- test/response/test-error.rb
|
217
218
|
- test/response/test-select.rb
|
218
219
|
- test/response/test-status.rb
|
220
|
+
- test/response/test-table-create.rb
|
219
221
|
- test/response/test-table-list.rb
|
222
|
+
- test/response/test-table-remove.rb
|
220
223
|
- test/results/test-column-list.rb
|
221
224
|
- test/results/test-table-list.rb
|
222
225
|
- test/run-test.rb
|
@@ -225,7 +228,7 @@ files:
|
|
225
228
|
- test/test-script-syntax.rb
|
226
229
|
homepage: https://github.com/ranguba/groonga-client
|
227
230
|
licenses:
|
228
|
-
- LGPLv2.1
|
231
|
+
- LGPLv2.1+
|
229
232
|
metadata: {}
|
230
233
|
post_install_message:
|
231
234
|
rdoc_options: []
|
@@ -243,25 +246,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
246
|
version: '0'
|
244
247
|
requirements: []
|
245
248
|
rubyforge_project:
|
246
|
-
rubygems_version: 2.
|
249
|
+
rubygems_version: 2.5.1
|
247
250
|
signing_key:
|
248
251
|
specification_version: 4
|
249
252
|
summary: Groonga-client is a client for groonga (http://groonga.org/) implemented
|
250
253
|
with pure ruby.
|
251
254
|
test_files:
|
255
|
+
- test/test-client.rb
|
252
256
|
- test/test-script-syntax.rb
|
253
|
-
- test/
|
257
|
+
- test/test-command.rb
|
254
258
|
- test/protocol/test-gqtp.rb
|
255
|
-
- test/
|
256
|
-
- test/
|
257
|
-
- test/response/test-
|
259
|
+
- test/protocol/test-http.rb
|
260
|
+
- test/run-test.rb
|
261
|
+
- test/response/test-base.rb
|
258
262
|
- test/response/test-column-list.rb
|
259
263
|
- test/response/helper.rb
|
260
|
-
- test/response/test-
|
264
|
+
- test/response/test-error.rb
|
265
|
+
- test/response/test-table-list.rb
|
261
266
|
- test/response/test-status.rb
|
262
|
-
- test/
|
267
|
+
- test/response/test-select.rb
|
268
|
+
- test/response/test-table-create.rb
|
269
|
+
- test/response/test-table-remove.rb
|
263
270
|
- test/results/test-column-list.rb
|
264
|
-
- test/test-
|
265
|
-
- test/run-test.rb
|
266
|
-
- test/test-client.rb
|
271
|
+
- test/results/test-table-list.rb
|
267
272
|
has_rdoc:
|