groonga-client 0.6.8 → 0.7.0
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 +4 -4
- data/doc/text/news.md +18 -0
- data/lib/groonga/client/error.rb +30 -0
- data/lib/groonga/client/protocol/http/synchronous.rb +10 -6
- data/lib/groonga/client/request/error.rb +3 -17
- data/lib/groonga/client/response/base.rb +9 -2
- data/lib/groonga/client/version.rb +2 -2
- data/test/response/test-base.rb +15 -0
- metadata +3 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 55cca8c755088db978d5f1064f0fa737289074b7ad06cfe248b42cf44032ad49
         | 
| 4 | 
            +
              data.tar.gz: c6d8c400c8c14ab86955480743bdc9c14cf7a4c34f2b05b3dbbcda62a4a37baf
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2311b2192456fdec99cd357e1f281e3d4242aa4ab0cdc2f4fb274bc88434a5fd158cf36201badc90ddacd7e9e00d20ee5d32f0e23244a8560d39193c3b33947e
         | 
| 7 | 
            +
              data.tar.gz: aead1e7ea6c6225ff0b4a1c802857527a154556fbfaa055f3b300fc34eeed482ad3f845393eef85e3960ec1fea588129fcec6d314625efb945d16b8b64e7d2db
         | 
    
        data/doc/text/news.md
    CHANGED
    
    | @@ -1,5 +1,23 @@ | |
| 1 1 | 
             
            # NEWS
         | 
| 2 2 |  | 
| 3 | 
            +
            ## 0.7.0 - 2024-10-16
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ### Improvements
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              * Improved error message on JSON parse error.
         | 
| 8 | 
            +
                * GH-32
         | 
| 9 | 
            +
                * Patch by Abe Tomoaki
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ### Thanks
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              * Abe Tomoaki
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## 0.6.9 - 2024-04-10
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ### Improvements
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              * HTTP: Added support for request cancel.
         | 
| 20 | 
            +
             | 
| 3 21 | 
             
            ## 0.6.8 - 2023-11-07
         | 
| 4 22 |  | 
| 5 23 | 
             
            ### Improvements
         | 
    
        data/lib/groonga/client/error.rb
    CHANGED
    
    | @@ -18,5 +18,35 @@ module Groonga | |
| 18 18 | 
             
              class Client
         | 
| 19 19 | 
             
                class Error < StandardError
         | 
| 20 20 | 
             
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                class ErrorResponse < Error
         | 
| 23 | 
            +
                  attr_reader :response
         | 
| 24 | 
            +
                  def initialize(response)
         | 
| 25 | 
            +
                    @response = response
         | 
| 26 | 
            +
                    command = @response.command
         | 
| 27 | 
            +
                    status_code = @response.status_code
         | 
| 28 | 
            +
                    error_message = @response.error_message
         | 
| 29 | 
            +
                    message = "failed to execute: "
         | 
| 30 | 
            +
                    message << "#{command.command_name}: #{status_code}: "
         | 
| 31 | 
            +
                    message << "<#{error_message}>: "
         | 
| 32 | 
            +
                    message << command.to_command_format
         | 
| 33 | 
            +
                    super(message)
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                class InvalidResponse < Error
         | 
| 38 | 
            +
                  attr_reader :command
         | 
| 39 | 
            +
                  attr_reader :raw_response
         | 
| 40 | 
            +
                  def initialize(command, raw_response, error_message)
         | 
| 41 | 
            +
                    @command = command
         | 
| 42 | 
            +
                    @raw_response = raw_response
         | 
| 43 | 
            +
                    message = +"invalid response: "
         | 
| 44 | 
            +
                    message << "#{command.command_name}: "
         | 
| 45 | 
            +
                    message << "#{error_message}: "
         | 
| 46 | 
            +
                    message << "<#{command.to_command_format}>: "
         | 
| 47 | 
            +
                    message << "<#{raw_response}>"
         | 
| 48 | 
            +
                    super(message)
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 21 51 | 
             
              end
         | 
| 22 52 | 
             
            end
         | 
| @@ -66,15 +66,19 @@ module Groonga | |
| 66 66 | 
             
                          http.start do
         | 
| 67 67 | 
             
                            http.read_timeout = read_timeout
         | 
| 68 68 | 
             
                            response = send_request(http, command)
         | 
| 69 | 
            +
                            body = response.body
         | 
| 69 70 | 
             
                            case response
         | 
| 70 | 
            -
                            when Net::HTTPSuccess, | 
| 71 | 
            -
             | 
| 71 | 
            +
                            when Net::HTTPSuccess,
         | 
| 72 | 
            +
                                 Net::HTTPBadRequest, # for invalid request
         | 
| 73 | 
            +
                                 Net::HTTPRequestTimeOut # for canceled request
         | 
| 74 | 
            +
                              yield(body)
         | 
| 72 75 | 
             
                            else
         | 
| 73 | 
            -
                               | 
| 74 | 
            -
             | 
| 76 | 
            +
                              # "[[" is for command_version=1
         | 
| 77 | 
            +
                              # "{" is for command_version=3
         | 
| 78 | 
            +
                              if body.start_with?("[[") or body.start_with?("{")
         | 
| 79 | 
            +
                                yield(body)
         | 
| 75 80 | 
             
                              else
         | 
| 76 | 
            -
                                message =
         | 
| 77 | 
            -
                                  "#{response.code} #{response.message}: #{response.body}"
         | 
| 81 | 
            +
                                message = "#{response.code} #{response.message}: #{body}"
         | 
| 78 82 | 
             
                                raise Error.new(message)
         | 
| 79 83 | 
             
                              end
         | 
| 80 84 | 
             
                            end
         | 
| @@ -19,23 +19,9 @@ require "groonga/client/error" | |
| 19 19 | 
             
            module Groonga
         | 
| 20 20 | 
             
              class Client
         | 
| 21 21 | 
             
                module Request
         | 
| 22 | 
            -
                   | 
| 23 | 
            -
                   | 
| 24 | 
            -
             | 
| 25 | 
            -
                  class ErrorResponse < Error
         | 
| 26 | 
            -
                    attr_reader :response
         | 
| 27 | 
            -
                    def initialize(response)
         | 
| 28 | 
            -
                      @response = response
         | 
| 29 | 
            -
                      command = @response.command
         | 
| 30 | 
            -
                      status_code = @response.status_code
         | 
| 31 | 
            -
                      error_message = @response.error_message
         | 
| 32 | 
            -
                      message = "failed to execute: "
         | 
| 33 | 
            -
                      message << "#{command.command_name}: #{status_code}: "
         | 
| 34 | 
            -
                      message << "<#{error_message}>: "
         | 
| 35 | 
            -
                      message << command.to_command_format
         | 
| 36 | 
            -
                      super(message)
         | 
| 37 | 
            -
                    end
         | 
| 38 | 
            -
                  end
         | 
| 22 | 
            +
                  # For backward compatibility
         | 
| 23 | 
            +
                  Error = Client::Error
         | 
| 24 | 
            +
                  ErrorResponse = Client::ErrorResponse
         | 
| 39 25 | 
             
                end
         | 
| 40 26 | 
             
              end
         | 
| 41 27 | 
             
            end
         | 
| @@ -73,9 +73,16 @@ module Groonga | |
| 73 73 | 
             
                          callback = command["callback"]
         | 
| 74 74 | 
             
                          if callback and
         | 
| 75 75 | 
             
                              /\A#{Regexp.escape(callback)}\((.+)\);\z/ =~ raw_response
         | 
| 76 | 
            -
                             | 
| 76 | 
            +
                            json = $1
         | 
| 77 77 | 
             
                          else
         | 
| 78 | 
            -
                             | 
| 78 | 
            +
                            json = raw_response
         | 
| 79 | 
            +
                          end
         | 
| 80 | 
            +
                          begin
         | 
| 81 | 
            +
                            response = JSON.parse(json)
         | 
| 82 | 
            +
                          rescue JSON::ParserError => error
         | 
| 83 | 
            +
                            raise InvalidResponse.new(command,
         | 
| 84 | 
            +
                                                      raw_response,
         | 
| 85 | 
            +
                                                      "invalid JSON: #{error}")
         | 
| 79 86 | 
             
                          end
         | 
| 80 87 | 
             
                          if response.is_a?(::Array)
         | 
| 81 88 | 
             
                            header, body = response
         | 
| @@ -1,4 +1,4 @@ | |
| 1 | 
            -
            # Copyright (C) 2013- | 
| 1 | 
            +
            # Copyright (C) 2013-2024  Sutou Kouhei <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
         | 
| @@ -16,6 +16,6 @@ | |
| 16 16 |  | 
| 17 17 | 
             
            module Groonga
         | 
| 18 18 | 
             
              class Client
         | 
| 19 | 
            -
                VERSION = "0. | 
| 19 | 
            +
                VERSION = "0.7.0"
         | 
| 20 20 | 
             
              end
         | 
| 21 21 | 
             
            end
         | 
    
        data/test/response/test-base.rb
    CHANGED
    
    | @@ -222,5 +222,20 @@ class TestResponseBase < Test::Unit::TestCase | |
| 222 222 | 
             
                  response = Groonga::Client::Response::Base.parse(command, raw_response)
         | 
| 223 223 | 
             
                  assert_equal(1396012478, response.body["start_time"])
         | 
| 224 224 | 
             
                end
         | 
| 225 | 
            +
             | 
| 226 | 
            +
                def test_invalid_json
         | 
| 227 | 
            +
                  command = Groonga::Command::Base.new("cancel")
         | 
| 228 | 
            +
                  raw_response = '["header", :{"return_code":-77}}'
         | 
| 229 | 
            +
                  begin
         | 
| 230 | 
            +
                    JSON.parse(raw_response)
         | 
| 231 | 
            +
                  rescue JSON::ParserError => error
         | 
| 232 | 
            +
                    parse_error_message = "invalid JSON: #{error}"
         | 
| 233 | 
            +
                  end
         | 
| 234 | 
            +
                  error = Groonga::Client::InvalidResponse.new(command, raw_response, parse_error_message)
         | 
| 235 | 
            +
             | 
| 236 | 
            +
                  assert_raise(error) do
         | 
| 237 | 
            +
                    Groonga::Client::Response::Base.parse(command, raw_response)
         | 
| 238 | 
            +
                  end
         | 
| 239 | 
            +
                end
         | 
| 225 240 | 
             
              end
         | 
| 226 241 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,16 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: groonga-client
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.7.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Haruka Yoshihara
         | 
| 8 8 | 
             
            - Kouhei Sutou
         | 
| 9 9 | 
             
            - Kosuke Asami
         | 
| 10 | 
            -
            autorequire:
         | 
| 11 10 | 
             
            bindir: bin
         | 
| 12 11 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date:  | 
| 12 | 
            +
            date: 2024-10-16 00:00:00.000000000 Z
         | 
| 14 13 | 
             
            dependencies:
         | 
| 15 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 15 | 
             
              name: gqtp
         | 
| @@ -286,7 +285,6 @@ homepage: https://github.com/ranguba/groonga-client | |
| 286 285 | 
             
            licenses:
         | 
| 287 286 | 
             
            - LGPLv2.1+
         | 
| 288 287 | 
             
            metadata: {}
         | 
| 289 | 
            -
            post_install_message:
         | 
| 290 288 | 
             
            rdoc_options: []
         | 
| 291 289 | 
             
            require_paths:
         | 
| 292 290 | 
             
            - lib
         | 
| @@ -301,8 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 301 299 | 
             
                - !ruby/object:Gem::Version
         | 
| 302 300 | 
             
                  version: '0'
         | 
| 303 301 | 
             
            requirements: []
         | 
| 304 | 
            -
            rubygems_version: 3. | 
| 305 | 
            -
            signing_key:
         | 
| 302 | 
            +
            rubygems_version: 3.6.0.dev
         | 
| 306 303 | 
             
            specification_version: 4
         | 
| 307 304 | 
             
            summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
         | 
| 308 305 | 
             
              with pure Ruby. You can use it without Groonga.
         |