groonga-client 0.2.0 → 0.2.1

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: 7e8cad3043939d233594ca90f8b84ea33725d5b5
4
- data.tar.gz: d8ae56764fe0a86509ef2b6cbe5762242cdb0dcf
3
+ metadata.gz: 6acb75bd146da352188103e7a1970a8a219200c5
4
+ data.tar.gz: f91de40970d46772c874b18558fa9ce8f5383c0c
5
5
  SHA512:
6
- metadata.gz: 3d1f57297335e1d324fea8e867b6703ad44222effb6c6b23aa49163747bc98fbc70013227180b4a0c00e1b632d3f8df70d639157fbfaba169876128fa6796dc8
7
- data.tar.gz: 66bd55f2b48c53208fb0596101b80277e04ab1151321c74e5ff27169998a6b09197039c9793a96f9d3bf68f54534058fddb9c802b5ca820700566d01f2bebbe3
6
+ metadata.gz: e153df284b448608874783c83582fdfada42e13c58d265eda16957cc853999c49128dd2f3e44325eb43befbbf78cb3df32d63613421da90899475429bf47074c
7
+ data.tar.gz: 06c18591b44b11e1ddcaaf0789dd0b23631797d8e7c4175a4022360954e4ca74cd332bc4bb6d73dde4762fd06fea5bf9e616d36dff81dd72c9f57898a9aef8ba
data/doc/text/news.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.2.1 - 2016-03-21
4
+
5
+ ### Improvements
6
+
7
+ * HTTP: Supported path.
8
+
9
+ * HTTP: Accepted `nil` as `:read_timeout` value.
10
+
3
11
  ## 0.2.0 - 2016-03-21
4
12
 
5
13
  ### Improvements
@@ -197,6 +197,7 @@ module Groonga
197
197
  scheme = (options.delete(:protocol) || "gqtp").to_s
198
198
  host = options.delete(:host) || options.delete(:address) || "127.0.0.1"
199
199
  port = options.delete(:port) || default_port(scheme)
200
+ path = options.delete(:path)
200
201
  user = options.delete(:user)
201
202
  password = options.delete(:password)
202
203
  if user and password
@@ -211,7 +212,7 @@ module Groonga
211
212
  host,
212
213
  port,
213
214
  nil,
214
- nil,
215
+ path,
215
216
  nil,
216
217
  nil,
217
218
  nil,
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2014 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2014-2016 Kouhei Sutou <kou@clear-code.com>
2
2
  #
3
3
  # This library is free software; you can redistribute it and/or
4
4
  # modify it under the terms of the GNU Lesser General Public
@@ -18,6 +18,7 @@ require "coolio"
18
18
 
19
19
  require "groonga/client/empty-request"
20
20
  require "groonga/client/protocol/error"
21
+ require "groonga/client/protocol/http/path-resolvable"
21
22
 
22
23
  module Groonga
23
24
  class Client
@@ -38,6 +39,8 @@ module Groonga
38
39
  end
39
40
 
40
41
  class GroongaHTTPClient < ::Coolio::HttpClient
42
+ include PathResolvable
43
+
41
44
  def initialize(socket, callback)
42
45
  super(socket)
43
46
  @body = ""
@@ -73,10 +76,11 @@ module Groonga
73
76
  def send(command, &block)
74
77
  client = GroongaHTTPClient.connect(@host, @port, block)
75
78
  client.attach(@loop)
79
+ url = URI("http://#{@host}:#{@port}")
76
80
  if command.is_a?(Groonga::Command::Load)
77
81
  raw_values = command[:values]
78
82
  command[:values] = nil
79
- path = command.to_uri_format
83
+ path = resolve_path(url, command.to_uri_format)
80
84
  command[:values] = raw_values
81
85
  options = {
82
86
  :head => {
@@ -87,7 +91,8 @@ module Groonga
87
91
  }
88
92
  client.request("POST", path, options)
89
93
  else
90
- client.request("GET", command.to_uri_format)
94
+ path = resolve_path(url, command.to_uri_format)
95
+ client.request("GET", path)
91
96
  end
92
97
  Request.new(client, @loop)
93
98
  end
@@ -0,0 +1,30 @@
1
+ # Copyright (C) 2016 Kouhei Sutou <kou@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
+ module Groonga
18
+ class Client
19
+ module Protocol
20
+ class HTTP
21
+ module PathResolvable
22
+ private
23
+ def resolve_path(uri, path)
24
+ uri.path.chomp("/") + path
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -20,12 +20,15 @@ require "net/http"
20
20
  require "groonga/client/version"
21
21
  require "groonga/client/empty-request"
22
22
  require "groonga/client/protocol/error"
23
+ require "groonga/client/protocol/http/path-resolvable"
23
24
 
24
25
  module Groonga
25
26
  class Client
26
27
  module Protocol
27
28
  class HTTP
28
29
  class Synchronous
30
+ include PathResolvable
31
+
29
32
  def initialize(url, options={})
30
33
  @url = url
31
34
  @options = options
@@ -108,7 +111,7 @@ module Groonga
108
111
 
109
112
  def read_timeout
110
113
  timeout = @options[:read_timeout]
111
- if timeout < 0
114
+ if timeout.nil? or timeout < 0
112
115
  nil
113
116
  else
114
117
  timeout
@@ -119,14 +122,15 @@ module Groonga
119
122
  if command.is_a?(Groonga::Command::Load)
120
123
  raw_values = command[:values]
121
124
  command[:values] = nil
122
- path = command.to_uri_format
125
+ path = resolve_path(@url, command.to_uri_format)
123
126
  command[:values] = raw_values
124
127
  request = Net::HTTP::Post.new(path, headers)
125
128
  request.content_type = "application/json"
126
129
  request.content_length = raw_values.bytesize
127
130
  request.body_stream = StringIO.new(raw_values)
128
131
  else
129
- request = Net::HTTP::Get.new(command.to_uri_format, headers)
132
+ path = resolve_path(@url, command.to_uri_format)
133
+ request = Net::HTTP::Get.new(path, headers)
130
134
  end
131
135
  setup_authentication(request)
132
136
  http.request(request)
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2013-2015 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
@@ -18,6 +16,6 @@
18
16
 
19
17
  module Groonga
20
18
  class Client
21
- VERSION = "0.2.0"
19
+ VERSION = "0.2.1"
22
20
  end
23
21
  end
data/test/test-client.rb CHANGED
@@ -469,5 +469,33 @@ EOH
469
469
  @request_headers["authorization"])
470
470
  end
471
471
  end
472
+
473
+ class TestPath < self
474
+ def component_based_open_options
475
+ {
476
+ :protocol => @protocol,
477
+ :host => @address,
478
+ :port => @port,
479
+ }
480
+ end
481
+
482
+ def test_with_trailing_slash
483
+ stub_response("[]")
484
+ options = component_based_open_options.merge(:path => "/sub_path/")
485
+ Groonga::Client.open(options) do |client|
486
+ client.status
487
+ end
488
+ assert_equal("/sub_path/d/status", @request_path)
489
+ end
490
+
491
+ def test_without_trailing_slash
492
+ stub_response("[]")
493
+ options = component_based_open_options.merge(:path => "/sub_path")
494
+ Groonga::Client.open(options) do |client|
495
+ client.status
496
+ end
497
+ assert_equal("/sub_path/d/status", @request_path)
498
+ end
499
+ end
472
500
  end
473
501
  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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
@@ -181,6 +181,7 @@ files:
181
181
  - lib/groonga/client/protocol/gqtp.rb
182
182
  - lib/groonga/client/protocol/http.rb
183
183
  - lib/groonga/client/protocol/http/coolio.rb
184
+ - lib/groonga/client/protocol/http/path-resolvable.rb
184
185
  - lib/groonga/client/protocol/http/synchronous.rb
185
186
  - lib/groonga/client/protocol/http/thread.rb
186
187
  - lib/groonga/client/response.rb