rootor 0.0.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.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +13 -0
  3. data/lib/client.rb +13 -0
  4. data/lib/rootor.rb +57 -0
  5. data/lib/torrent.rb +40 -0
  6. metadata +61 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 912148c0937e0acd613b737892a70f8b18a8181e
4
+ data.tar.gz: 2798192791569c38351114f677d2036e13f1dde7
5
+ SHA512:
6
+ metadata.gz: f522eac20a34c45c3bbad8ea19ebe916c179fc283416167c40cff3b82eb4d7a9524b75b83ecb4b2811200a8a7399fb6e4921c7065e43acf9d64b72079d99b34b
7
+ data.tar.gz: a8e144ea15b08d1fff9d9b8bb2c20dc721a2e28d044117d937270bfbd99933b8192526998ec4f59453b43268c5ad51e55d1ea0c64f622780b7017b67b9484b54
data/README.md ADDED
@@ -0,0 +1,13 @@
1
+ Rootor is an `XMLRPC` frontend for ruby. Requires `Filesize` gem and `xmlrpc/client`.
2
+
3
+ To run:
4
+ ```
5
+ require_realtive 'lib/rootor'
6
+
7
+ queries = {
8
+ id: { call: 'hash', kind: :str },
9
+ name: { call: 'name', kind: :str }
10
+ } # optional
11
+
12
+ r = Rootor.new('https://<user>:<password>@<server>:<port>/<xmlrpc>', queries)
13
+ ```
data/lib/client.rb ADDED
@@ -0,0 +1,13 @@
1
+ class Client < XMLRPC::Client
2
+ def fetch(queries)
3
+ call_async('d.multicall', 'main', *render_queries(queries)).map do |t|
4
+ Torrent.new(t, queries)
5
+ end
6
+ end
7
+
8
+ private
9
+
10
+ def render_queries(queries)
11
+ queries.map { |k, v| "d.#{v[:call]}=" }
12
+ end
13
+ end
data/lib/rootor.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'xmlrpc/client'
2
+ require 'filesize'
3
+ require_relative 'client'
4
+ require_relative 'torrent'
5
+
6
+ class Rootor
7
+ attr_accessor :client, :torrents
8
+
9
+ QUERIES = {
10
+ id: { call: 'hash', kind: :str },
11
+ name: { call: 'name', kind: :str },
12
+ path: { call: 'get_base_path', kind: :str },
13
+ creation_date: { call: 'creation_date', kind: :date },
14
+ message: { call: 'message', kind: :str },
15
+ connection_current: { call: 'connection_current', kind: :str },
16
+ is_active: { call: 'is_active', kind: :bool },
17
+ is_open: { call: 'is_open', kind: :bool },
18
+ size: { call: 'size_bytes', kind: :file },
19
+ uploaded: { call: 'get_up_total', kind: :file },
20
+ downloaded: { call: 'bytes_done', kind: :file },
21
+ ratio: { call: 'get_ratio', kind: :ratio },
22
+ up_rate: { call: 'get_up_rate', kind: :rate },
23
+ down_rate: { call: 'get_down_rate', kind: :rate },
24
+ }
25
+
26
+ def initialize(xmlrpc_url, queries = QUERIES)
27
+ @queries = queries
28
+ @client = Client.new2(xmlrpc_url)
29
+ @torrents = @client.fetch(@queries)
30
+ end
31
+
32
+ def refresh
33
+ @torrents = @client.fetch(@queries)
34
+ end
35
+
36
+ def serialized_torrents
37
+ serialize(@torrents)
38
+ end
39
+
40
+ def find(str)
41
+ return [] unless str.instance_of? String
42
+ return [] if str.empty?
43
+ @torrents.map do |t|
44
+ begin
45
+ t if t.data.any? { |tt| tt.downcase.include? str.downcase }
46
+ rescue
47
+ nil
48
+ end
49
+ end.compact
50
+ end
51
+
52
+ private
53
+
54
+ def serialize(torrents)
55
+ torrents.map(&:serialize)
56
+ end
57
+ end
data/lib/torrent.rb ADDED
@@ -0,0 +1,40 @@
1
+ class Torrent
2
+ attr_accessor :data
3
+
4
+ def initialize(data, queries)
5
+ @data = data
6
+ @queries = queries
7
+ serialize.each do |k, v|
8
+ self.instance_variable_set "@#{k.to_s}", v
9
+ self.class.__send__(:attr_accessor, k)
10
+ end
11
+ end
12
+
13
+ def serialize
14
+ Hash[
15
+ data.each_with_index.map do |value, index|
16
+ [
17
+ @queries.keys[index],
18
+ mutate(@queries[@queries.keys[index]][:kind], value)
19
+ ]
20
+ end
21
+ ]
22
+ end
23
+
24
+ private
25
+
26
+ def mutate(kase, data)
27
+ case kase
28
+ when :file, :rate
29
+ Filesize.from("#{data} B")
30
+ when :date
31
+ Time.at(data)
32
+ when :ratio
33
+ data.to_f/1000
34
+ when :bool
35
+ !!data
36
+ else
37
+ data
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rootor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - lightbright
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: filesize
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
+ description: ''
28
+ email: graham.otte@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/client.rb
35
+ - lib/rootor.rb
36
+ - lib/torrent.rb
37
+ homepage: http://what.com
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.3.0
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.5.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: XMLRPC interface
61
+ test_files: []