retort 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/retort.rb +1 -0
- data/lib/retort/conversion.rb +37 -0
- data/lib/retort/core_ext.rb +6 -19
- data/lib/retort/service.rb +2 -2
- data/lib/retort/torrent.rb +60 -25
- data/lib/retort/version.rb +1 -1
- metadata +3 -2
data/.gitignore
CHANGED
data/lib/retort.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Retort::Conversion
|
2
|
+
|
3
|
+
|
4
|
+
class Call
|
5
|
+
TYPES = { time: 'to_time', date: 'to_date', size: 'to_xb' }
|
6
|
+
attr_accessor :attributes
|
7
|
+
|
8
|
+
def initialize(prefix)
|
9
|
+
@attributes = {}
|
10
|
+
@prefix = prefix
|
11
|
+
end
|
12
|
+
|
13
|
+
def method_missing(*args, &block)
|
14
|
+
property = args.shift
|
15
|
+
options = args.shift || {}
|
16
|
+
|
17
|
+
type = options[:type]
|
18
|
+
method_name = options[:name] || property
|
19
|
+
method_name = "#{@prefix}.#{method_name}" unless @prefix.empty?
|
20
|
+
|
21
|
+
if TYPES.member? type
|
22
|
+
#Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'.
|
23
|
+
@attributes[property] = "#{TYPES[type]}=$#{method_name}"
|
24
|
+
property = "#{property}_raw"
|
25
|
+
end
|
26
|
+
@attributes[property] = method_name
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def build(prefix="")
|
31
|
+
c = Call.new prefix
|
32
|
+
yield c
|
33
|
+
c.attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
data/lib/retort/core_ext.rb
CHANGED
@@ -1,29 +1,16 @@
|
|
1
1
|
class Fixnum
|
2
|
-
def
|
3
|
-
self
|
2
|
+
def truth
|
3
|
+
return [false,true][self] if (0..1).member? self
|
4
4
|
end
|
5
|
-
|
6
|
-
def kilobytes
|
7
|
-
bytes / 1024.0
|
8
|
-
end
|
9
|
-
|
10
|
-
def kbs
|
11
|
-
"#{sprintf('%.2f', kilobytes)}KB/s"
|
12
|
-
end
|
13
|
-
|
14
|
-
def megabytes
|
15
|
-
kilobytes / 1024.0
|
16
|
-
end
|
17
|
-
|
18
5
|
end
|
19
6
|
|
20
7
|
class Float
|
21
|
-
def
|
8
|
+
def percent_raw
|
22
9
|
(self * 100).to_i
|
23
|
-
end
|
10
|
+
end
|
24
11
|
|
25
|
-
def
|
26
|
-
"#{sprintf('%.2f',
|
12
|
+
def percent
|
13
|
+
"#{sprintf('%.2f', percent_raw)}"
|
27
14
|
end
|
28
15
|
end
|
29
16
|
|
data/lib/retort/service.rb
CHANGED
data/lib/retort/torrent.rb
CHANGED
@@ -1,38 +1,45 @@
|
|
1
|
-
module Retort
|
1
|
+
module Retort
|
2
|
+
|
3
|
+
class Exception; end
|
2
4
|
|
3
5
|
class Torrent
|
4
|
-
|
6
|
+
extend Retort::Conversion
|
7
|
+
|
5
8
|
class << self
|
6
|
-
def attr_mappings
|
7
|
-
|
8
|
-
|
9
|
-
name:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
9
|
+
def attr_mappings
|
10
|
+
|
11
|
+
build(:d) do |t|
|
12
|
+
t.info_hash name: 'hash'
|
13
|
+
t.name
|
14
|
+
t.connection_current
|
15
|
+
t.size name: 'size_bytes', type: :size
|
16
|
+
t.completed name: 'completed_bytes', type: :size
|
17
|
+
t.creation_date name: 'creation_date', type: :date
|
18
|
+
t.downloaded name: 'bytes_done', type: :size
|
19
|
+
t.up_rate name: 'up.rate', type: :size
|
20
|
+
t.down_rate name: 'down.rate', type: :size
|
21
|
+
t.message name: 'get_message'
|
22
|
+
t.seeders name: 'peers_complete'
|
23
|
+
t.leechers name: 'peers_connected'
|
24
|
+
t.state
|
25
|
+
t.complete
|
26
|
+
t.is_active
|
27
|
+
t.is_hash_checked
|
28
|
+
t.is_hash_checking
|
29
|
+
t.is_multi_file
|
30
|
+
t.is_open
|
31
|
+
end
|
32
|
+
|
26
33
|
end
|
27
34
|
|
28
35
|
def all(view="main")
|
29
36
|
methods = attr_mappings.map {|key,value| "#{value}="}
|
30
|
-
Service.call("d.multicall", view, *methods).map do |r|
|
37
|
+
Service.call("d.multicall", view, *methods).map do |r|
|
31
38
|
attributes = Hash[attr_mappings.keys.zip(r)]
|
32
39
|
Torrent.new attributes
|
33
40
|
end
|
34
41
|
end
|
35
|
-
|
42
|
+
|
36
43
|
def views
|
37
44
|
Service.call "view.list"
|
38
45
|
end
|
@@ -49,9 +56,37 @@ module Retort
|
|
49
56
|
attr_accessor *(attr_mappings.keys)
|
50
57
|
|
51
58
|
def initialize(attributes)
|
59
|
+
|
52
60
|
attributes.each do |attrib, value|
|
53
|
-
|
61
|
+
variable = "@#{attrib}".to_sym
|
62
|
+
self.instance_variable_set variable, value
|
63
|
+
if attrib =~ /is_/
|
64
|
+
bool_value = value.truth
|
65
|
+
variable = "@#{attrib.to_s.gsub(/is_/, "")}".to_sym
|
66
|
+
self.instance_variable_set variable, bool_value
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
def status
|
73
|
+
return "complete" if @complete.truth
|
74
|
+
end
|
75
|
+
|
76
|
+
def actions
|
77
|
+
actions = []
|
78
|
+
|
79
|
+
actions << (@state.truth ? :stop : :start)
|
80
|
+
#actions << :check_hash unless @hash_checking
|
81
|
+
actions << (@open ? :close : :open)
|
82
|
+
|
83
|
+
unless @complete.truth
|
84
|
+
actions << (@active ? :pause : :resume)
|
54
85
|
end
|
86
|
+
|
87
|
+
actions << :erase
|
88
|
+
|
89
|
+
actions
|
55
90
|
end
|
56
91
|
end
|
57
92
|
end
|
data/lib/retort/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retort
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-04 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: An rTorrent xmlrpc wrapper written in ruby
|
15
15
|
email:
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- README.rdoc
|
25
25
|
- Rakefile
|
26
26
|
- lib/retort.rb
|
27
|
+
- lib/retort/conversion.rb
|
27
28
|
- lib/retort/core_ext.rb
|
28
29
|
- lib/retort/service.rb
|
29
30
|
- lib/retort/torrent.rb
|