droonga-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8451550565af3065d58578612f6a93f66346a5d2
4
+ data.tar.gz: 24a9b4f1bd9d8a055ac12d100a324590fb527ca9
5
+ SHA512:
6
+ metadata.gz: 5b5ec6bfd26accbe56311256ef64fe349cbcad404fdf659da43c5d19558277abe21c342e621e95d81e94560abd56d6e0c49b1c8ce402bbd6e0509401da7d823f
7
+ data.tar.gz: a83b71c182458ae873ad27913defd1f67172a04a302f7ec67d977ccd6acd48f3f8307bab72b2054e7c330a65ba705c6d65ad2bf15c0045975d57111df8398803
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ /Gemfile.lock
2
+ /.yardoc/
3
+ /doc/reference/
data/.yardopts ADDED
@@ -0,0 +1,7 @@
1
+ --output-dir doc/reference/en
2
+ --markup markdown
3
+ --markup-provider kramdown
4
+ lib/**/*.rb
5
+ -
6
+ LICENSE.txt
7
+ doc/text/**/*.*
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ source 'https://rubygems.org'
19
+
20
+ # Specify your gem's dependencies in droonga-client.gemspec
21
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (C) 2013 Droonga Project
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 version 2.1 as published by the Free Software Foundation.
6
+
7
+ This library is distributed in the hope that it will be useful,
8
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
+ Lesser General Public License for more details.
11
+
12
+ You should have received a copy of the GNU Lesser General Public
13
+ License along with this library; if not, write to the Free Software
14
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Droonga::Client
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'droonga-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install droonga-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "bundler/gem_helper"
19
+ require "packnga"
20
+
21
+ base_dir = File.join(File.dirname(__FILE__))
22
+
23
+ helper = Bundler::GemHelper.new(base_dir)
24
+ def helper.version_tag
25
+ version
26
+ end
27
+
28
+ helper.install
29
+ spec = helper.gemspec
30
+
31
+ Packnga::DocumentTask.new(spec) do |task|
32
+ task.original_language = "en"
33
+ task.translate_languages = ["ja"]
34
+ end
35
+
data/doc/text/news.md ADDED
@@ -0,0 +1,5 @@
1
+ # News
2
+
3
+ ## 0.0.1: 2013-11-29
4
+
5
+ The first release!!!
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ lib = File.expand_path('../lib', __FILE__)
19
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
20
+ require 'droonga/client/version'
21
+
22
+ Gem::Specification.new do |spec|
23
+ spec.name = "droonga-client"
24
+ spec.version = Droonga::Client::VERSION
25
+ spec.authors = ["Droonga Project"]
26
+ spec.email = ["droonga@groonga.org"]
27
+ spec.description = %q{Droonga client for Ruby}
28
+ spec.summary = %q{Droonga client for Ruby}
29
+ spec.homepage = "https://github.com/droonga/droonga-client-ruby"
30
+ spec.license = "LGPL-2.1"
31
+
32
+ spec.files = `git ls-files`.split($/)
33
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
34
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_runtime_dependency "msgpack"
38
+ spec.add_runtime_dependency "fluent-logger"
39
+
40
+ spec.add_development_dependency "bundler", "~> 1.3"
41
+ spec.add_development_dependency "rake"
42
+ spec.add_development_dependency "packnga"
43
+ end
@@ -0,0 +1,34 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "droonga/client/version"
19
+ require "droonga/client/error"
20
+ require "droonga/client/connection/droonga_protocol"
21
+
22
+ module Droonga
23
+ class Client
24
+ attr_reader :connection
25
+
26
+ def initialize(options={})
27
+ @connection = Connection::DroongaProtocol.new(options)
28
+ end
29
+
30
+ def search(body)
31
+ @connection.search(body)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,119 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "socket"
19
+ require "msgpack"
20
+ require "fluent-logger"
21
+
22
+ module Droonga
23
+ class Client
24
+ module Connection
25
+ class DroongaProtocol
26
+ def initialize(options={})
27
+ default_options = {
28
+ :tag => "droonga",
29
+ :host => "127.0.0.1",
30
+ :port => 24224,
31
+ :timeout => 5
32
+ }
33
+ options = default_options.merge(options)
34
+ @logger = Fluent::Logger::FluentLogger.new(options.delete(:tag),
35
+ options)
36
+ @timeout = options[:timeout]
37
+ end
38
+
39
+ def search(body)
40
+ envelope = {
41
+ "id" => Time.now.to_f.to_s,
42
+ "date" => Time.now,
43
+ "statusCode" => 200,
44
+ "type" => "search",
45
+ "body" => body,
46
+ }
47
+ send(envelope, :response => :one)
48
+ end
49
+
50
+ # Sends low level request. Normally, you should use other
51
+ # convenience methods.
52
+ #
53
+ # @param envelope [Hash] Request envelope.
54
+ # @param options [Hash] The options to send request.
55
+ # @option options :response [nil, :none, :one] (nil) The response type.
56
+ # If you specify `nil`, it is treated as `:one`.
57
+ # @return The response. TODO: WRITE ME
58
+ def send(envelope, options={})
59
+ response_type = options[:response] || :one
60
+ case response_type
61
+ when :none
62
+ @logger.post("message", envelope)
63
+ when :one
64
+ receiver = Receiver.new
65
+ begin
66
+ envelope = envelope.dup
67
+ envelope["replyTo"] = "#{receiver.host}:#{receiver.port}/droonga"
68
+ @logger.post("message", envelope)
69
+ receiver.receive(:timeout => @timeout)
70
+ ensure
71
+ receiver.close
72
+ end
73
+ else
74
+ raise InvalidResponseType.new(response_type)
75
+ end
76
+ end
77
+
78
+ class Receiver
79
+ def initialize(options={})
80
+ default_options = {
81
+ :host => "0.0.0.0",
82
+ :port => 0,
83
+ }
84
+ options = default_options.merge(options)
85
+ @socket = TCPServer.new(options[:host], options[:port])
86
+ end
87
+
88
+ def close
89
+ @socket.close
90
+ end
91
+
92
+ def host
93
+ @socket.addr[3]
94
+ end
95
+
96
+ def port
97
+ @socket.addr[1]
98
+ end
99
+
100
+ def receive(options={})
101
+ if IO.select([@socket], nil, nil, options[:timeout])
102
+ client = @socket.accept
103
+ response = nil
104
+ unpacker = MessagePack::Unpacker.new(client)
105
+ unpacker.each do |object|
106
+ response = object
107
+ break
108
+ end
109
+ client.close
110
+ response
111
+ else
112
+ nil
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ require "droonga/client/error"
19
+
20
+ module Droonga
21
+ class Client
22
+ module Connection
23
+ # The top error class of connection module.
24
+ class Error < Client::Error
25
+ end
26
+
27
+ # The error class for invalid response type is specified.
28
+ class InvalidResponseType < Error
29
+ attr_reader :type
30
+ def initialize(type)
31
+ @type = type
32
+ super("Unknown response type: <#{@type}>. " +
33
+ "Available types: [:none, :one]")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,24 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ module Droonga
19
+ class Client
20
+ # The top error class of droonga-client.
21
+ class Error < StandardError
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # Copyright (C) 2013 Droonga Project
4
+ #
5
+ # This library is free software; you can redistribute it and/or
6
+ # modify it under the terms of the GNU Lesser General Public
7
+ # License version 2.1 as published by the Free Software Foundation.
8
+ #
9
+ # This library is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # Lesser General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU Lesser General Public
15
+ # License along with this library; if not, write to the Free Software
16
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
+
18
+ module Droonga
19
+ class Client
20
+ VERSION = "0.0.1"
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: droonga-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Droonga Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: msgpack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fluent-logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: packnga
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Droonga client for Ruby
84
+ email:
85
+ - droonga@groonga.org
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".yardopts"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - doc/text/news.md
97
+ - droonga-client.gemspec
98
+ - lib/droonga/client.rb
99
+ - lib/droonga/client/connection/droonga_protocol.rb
100
+ - lib/droonga/client/connection/error.rb
101
+ - lib/droonga/client/error.rb
102
+ - lib/droonga/client/version.rb
103
+ homepage: https://github.com/droonga/droonga-client-ruby
104
+ licenses:
105
+ - LGPL-2.1
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.0
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Droonga client for Ruby
127
+ test_files: []
128
+ has_rdoc: