seaweedrb 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.md +21 -0
- data/README.md +31 -0
- data/lib/seaweed.rb +5 -13
- data/lib/seaweed/file.rb +7 -7
- data/lib/seaweed/http.rb +20 -0
- data/lib/seaweed/master.rb +9 -9
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36688ffe6cc2c84cd454f873e24eab613b460531
|
4
|
+
data.tar.gz: 66fcf457e08ce4ba4f692d23c3e6502cd69fabe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a050993bac1d838bc29d002eae377d637507d0f29f91df6156088c2baba4b11f9fc16ca718995b25bf034c186de051b586bb5f7d6578dcab14e2c0251b664c36
|
7
|
+
data.tar.gz: a2788e24760ac5c4794ce77accaca398a543b313d281ac1a7a9bd87eb81925d3c093f45da268ebf0fcb685c1ba43676fee1ff2cca85dc28eae8d69bcbe34b781
|
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 John Guest
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
## seaweedrb
|
2
|
+
|
3
|
+
a [seaweed-fs](https://github.com/chrislusf/seaweedfs) ruby client
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/seaweedrb.svg)](http://badge.fury.io/rb/seaweedrb)
|
6
|
+
|
7
|
+
### getting started
|
8
|
+
|
9
|
+
Run `gem install seaweedrb` or include it in your project's Gemfile.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'seaweed'
|
13
|
+
Seaweed.connect host: "localhost", port: 9333
|
14
|
+
```
|
15
|
+
|
16
|
+
### operations
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
# upload a file
|
20
|
+
file = Seaweed.upload "/path/to/test.txt"
|
21
|
+
|
22
|
+
# file info
|
23
|
+
file.pretty_url # => "http://localhost:8080/1/01766888e0/test.txt"
|
24
|
+
file.url # => "http://localhost:8080/1,01766888e0"
|
25
|
+
file.read # => "hello world!"
|
26
|
+
|
27
|
+
# find a file and delete it
|
28
|
+
file = Seaweed.find "1,01766888e0"
|
29
|
+
file.read # => "hello world!"
|
30
|
+
file.delete! # => true
|
31
|
+
```
|
data/lib/seaweed.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Seaweed
|
2
2
|
|
3
|
-
def self.connect(host: "localhost", port: 9333)
|
3
|
+
def self.connect(host: "localhost", port: 9333, http_options: {})
|
4
|
+
Seaweed::HTTP.configure http_options
|
4
5
|
Seaweed::Master.connect host: host, port: port
|
5
6
|
end
|
6
7
|
|
@@ -14,21 +15,12 @@ module Seaweed
|
|
14
15
|
file.upload!
|
15
16
|
end
|
16
17
|
|
17
|
-
def self.find(fid)
|
18
|
+
def self.find(fid, http_options: nil)
|
18
19
|
location = Seaweed::Master.dir_lookup fid.split(",")[0]
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'rest-client'
|
23
|
-
module Client
|
24
|
-
def parse(response)
|
25
|
-
if response.code.between?(200, 300)
|
26
|
-
return JSON.parse response, symbolize_names: true unless block_given?
|
27
|
-
yield
|
28
|
-
end
|
29
|
-
end
|
20
|
+
Seaweed::File.new fid, volume_url: location[:url]
|
30
21
|
end
|
31
22
|
end
|
32
23
|
|
24
|
+
require 'seaweed/http'
|
33
25
|
require 'seaweed/master'
|
34
26
|
require 'seaweed/file'
|
data/lib/seaweed/file.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class Seaweed::File
|
2
|
-
include Seaweed::Client
|
3
2
|
|
4
3
|
attr_reader :id, :name, :volume_id, :volume_url, :attachment, :size
|
5
4
|
|
@@ -11,19 +10,20 @@ class Seaweed::File
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def upload!
|
14
|
-
response =
|
15
|
-
|
16
|
-
@
|
13
|
+
response = Seaweed::HTTP.put url, file: File.new(@attachment, 'rb')
|
14
|
+
data = Seaweed::HTTP.parse response
|
15
|
+
@name = data[:name]
|
16
|
+
@size = data[:size]
|
17
17
|
self
|
18
18
|
end
|
19
19
|
|
20
20
|
def delete!
|
21
|
-
|
22
|
-
!
|
21
|
+
res = Seaweed::HTTP.delete url
|
22
|
+
!(Seaweed::HTTP.parse(res)[:size].nil?)
|
23
23
|
end
|
24
24
|
|
25
25
|
def read
|
26
|
-
|
26
|
+
Seaweed::HTTP.get url
|
27
27
|
end
|
28
28
|
|
29
29
|
def url
|
data/lib/seaweed/http.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
class Seaweed::HTTP
|
6
|
+
class << self
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def configure(http: RestClient, json: JSON)
|
10
|
+
@http = http
|
11
|
+
@json = json
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse(json)
|
15
|
+
@json.parse json, symbolize_names: true
|
16
|
+
end
|
17
|
+
|
18
|
+
def_delegators :@http, :get, :put, :post, :delete
|
19
|
+
end
|
20
|
+
end
|
data/lib/seaweed/master.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
1
|
class Seaweed::Master
|
2
|
-
extend Seaweed::Client
|
3
2
|
class << self
|
4
3
|
|
5
4
|
def connect(host: "localhost", port: 9333)
|
6
|
-
@
|
7
|
-
@port = port
|
8
|
-
@base_url = "http://#{@host}:#{@port}"
|
5
|
+
@base_url = "http://#{host}:#{port}"
|
9
6
|
end
|
10
7
|
|
11
8
|
def status
|
12
|
-
|
9
|
+
res = Seaweed::HTTP.get "#{@base_url}/cluster/status?pretty=y"
|
10
|
+
Seaweed::HTTP.parse res
|
13
11
|
end
|
14
12
|
|
15
13
|
def dir_assign!
|
16
|
-
|
14
|
+
res = Seaweed::HTTP.post "#{@base_url}/dir/assign", {}
|
15
|
+
Seaweed::HTTP.parse res
|
17
16
|
end
|
18
17
|
|
19
18
|
def dir_lookup(volume_id)
|
20
|
-
|
21
|
-
|
19
|
+
res = Seaweed::HTTP.get "#{@base_url}/dir/lookup?volumeId=#{volume_id}"
|
20
|
+
Seaweed::HTTP.parse(res)[:locations][0]
|
22
21
|
end
|
23
22
|
|
24
23
|
def vaccum!(threshold: 0.3)
|
25
|
-
|
24
|
+
res = Seaweed::HTTP.get "#{@base_url}/vol/vaccum?garbageThreshold=#{threshold}"
|
25
|
+
Seaweed::HTTP.parse res
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seaweedrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Guest
|
@@ -16,8 +16,11 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- LICENSE.md
|
20
|
+
- README.md
|
19
21
|
- lib/seaweed.rb
|
20
22
|
- lib/seaweed/file.rb
|
23
|
+
- lib/seaweed/http.rb
|
21
24
|
- lib/seaweed/master.rb
|
22
25
|
homepage: http://rubygems.org/gems/seaweedrb
|
23
26
|
licenses:
|