fleet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +29 -0
  3. data/lib/fleet.rb +27 -0
  4. metadata +66 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Mark McGranaghan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # fleet-rb
2
+
3
+ A Ruby client for FleetDB.
4
+
5
+ ## Setup
6
+
7
+ Install and start FleetDB as described in the [FleetDB getting started guide](http://fleetdb.org/docs/getting_started.html), then install this client library with:
8
+
9
+ $ sudo gem install fleet
10
+
11
+ ## Usage
12
+
13
+ require "rubygems"
14
+ require "fleet"
15
+
16
+ client = Fleet.new("127.0.0.1", 3400)
17
+
18
+ client.query(["ping"])
19
+ #=> "pong"
20
+
21
+ client.query(["select", "accounts", {"where" => ["=", "id", 2]}])
22
+ #=> [{"id" => 2, "owner" => "Alice", "credits" => 150}]
23
+
24
+ The client will raise an exception in the case of an error:
25
+
26
+ => (c/query client ["bogus"])
27
+ java.lang.Exception: Malformed query: unrecognized query type '"bogus"'
28
+
29
+ See the [FleetDB getting started guide](http://fleetdb.org/docs/getting_started.html) and the [FleetDB query reference](http://fleetdb.org/docs/queries.html) for documentation on the queries available to clients.
data/lib/fleet.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "socket"
2
+ require "yajl"
3
+
4
+ class Fleet
5
+ def initialize(host, port)
6
+ @host = host
7
+ @port = port
8
+ @socket = TCPSocket.new(host, port)
9
+ end
10
+
11
+ def query(q)
12
+ request = Yajl::Encoder.encode(q)
13
+ @socket.write(request)
14
+ @socket.write("\r\n")
15
+ response = @socket.gets
16
+ status, value = Yajl::Parser.parse(response)
17
+ status == 0 ? value : raise(value)
18
+ end
19
+
20
+ def close
21
+ @socket.close
22
+ end
23
+
24
+ def to_s
25
+ "FleetDB client connected to #{@host}:#{@port}"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fleet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark McGranaghan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-31 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: yajl-ruby
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.6.7
24
+ version:
25
+ description: FleetDB client library.
26
+ email: mmcgrana@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ files:
34
+ - LICENSE
35
+ - README.md
36
+ - lib/fleet.rb
37
+ has_rdoc: true
38
+ homepage: http://github.com/mmcgrana/fleet-rb
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: A simple FleetDB client library.
65
+ test_files: []
66
+