seaweedrb 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: 40635ace82a6b849e6429965cf5fe16ff6dd42e2
4
+ data.tar.gz: 73393bf1d946f8b1b91a46d523d006296d9e7574
5
+ SHA512:
6
+ metadata.gz: cc1ab879adfd7ee94f648c9e3ea87c113e9fd1079b5d3b9ddc858ba888ed0f26c3c1cbd171416e7f4618616ea5cb36bdc89ba5631084d1efe3b2e46f0b45f974
7
+ data.tar.gz: 8d4069db44c6187ac6d8c239e71857cf7cdfbce10c4a076f704a256fe514a8a3188962967ba06daf33db28ba61b2b8667c64818ee4d7feaa9706ca19cb1fe566
@@ -0,0 +1,36 @@
1
+ class Seaweed::File
2
+ include Seaweed::Client
3
+
4
+ attr_reader :id, :name, :volume_id, :volume_url, :attachment, :size
5
+
6
+ def initialize(fid, volume_url: nil, attachment: nil)
7
+ @id = fid
8
+ @volume_id, @key, @cookie = fid.match(/^(\d),(\w\w)(\w+)$/).captures
9
+ @volume_url = volume_url
10
+ @attachment = attachment
11
+ end
12
+
13
+ def upload!
14
+ response = parse RestClient.put(url, file: File.new(@attachment, 'rb'))
15
+ @name = response[:name]
16
+ @size = response[:size]
17
+ self
18
+ end
19
+
20
+ def delete!
21
+ response = parse RestClient.delete(url)
22
+ !response[:size].nil?
23
+ end
24
+
25
+ def read
26
+ RestClient.get url
27
+ end
28
+
29
+ def url
30
+ "#{@volume_url}/#{@id}"
31
+ end
32
+
33
+ def pretty_url
34
+ "#{@volume_url}/#{@volume_id}/#{@key}#{@cookie}/#{@name}"
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ class Seaweed::Master
2
+ extend Seaweed::Client
3
+ class << self
4
+
5
+ def connect(host: "localhost", port: 9333)
6
+ @host = host
7
+ @port = port
8
+ @base_url = "http://#{@host}:#{@port}"
9
+ end
10
+
11
+ def status
12
+ RestClient.get "#{@base_url}/cluster/status?pretty=y"
13
+ end
14
+
15
+ def dir_assign!
16
+ parse RestClient.post "#{@base_url}/dir/assign", {}
17
+ end
18
+
19
+ def dir_lookup(volume_id)
20
+ data = parse RestClient.get("#{@base_url}/dir/lookup?volumeId=#{volume_id}")
21
+ data[:locations][0]
22
+ end
23
+
24
+ def vaccum!(threshold: 0.3)
25
+ parse RestClient.get "#{@base_url}/vol/vaccum?garbageThreshold=#{threshold}"
26
+ end
27
+ end
28
+ end
data/lib/seaweed.rb ADDED
@@ -0,0 +1,34 @@
1
+ module Seaweed
2
+
3
+ def self.connect(host: "localhost", port: 9333)
4
+ Seaweed::Master.connect host: host, port: port
5
+ end
6
+
7
+ def self.status
8
+ Seaweed::Master.status
9
+ end
10
+
11
+ def self.upload(path)
12
+ location = Seaweed::Master.dir_assign!
13
+ file = Seaweed::File.new location[:fid], volume_url: location[:url], attachment: path
14
+ file.upload!
15
+ end
16
+
17
+ def self.find(fid)
18
+ location = Seaweed::Master.dir_lookup fid.split(",")[0]
19
+ file = Seaweed::File.new fid, volume_url: location[:url]
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
30
+ end
31
+ end
32
+
33
+ require 'seaweed/master'
34
+ require 'seaweed/file'
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seaweedrb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Guest
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Seaweed-FS Ruby Client
14
+ email: guest.john88@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/seaweed.rb
20
+ - lib/seaweed/file.rb
21
+ - lib/seaweed/master.rb
22
+ homepage: http://rubygems.org/gems/seaweedrb
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.0.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.6
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: seaweedrb
46
+ test_files: []
47
+ has_rdoc: