retort 0.0.2

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.
@@ -0,0 +1,29 @@
1
+ class Fixnum
2
+ def bytes
3
+ self
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
+ end
19
+
20
+ class Float
21
+ def percent
22
+ (self * 100).to_i
23
+ end
24
+
25
+ def fmt
26
+ "#{sprintf('%.2f', self)}"
27
+ end
28
+ end
29
+
@@ -0,0 +1,24 @@
1
+ module Retort
2
+
3
+ class Config
4
+ attr_accessor :url
5
+ end
6
+
7
+ class Service
8
+
9
+ class << self
10
+
11
+ def configure
12
+ config = Config.new
13
+ yield config
14
+ @@service = XMLRPC::Client.new2(config.url)
15
+ end
16
+
17
+ def call(*args)
18
+ @@service.call_async *args
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,58 @@
1
+ module Retort
2
+
3
+ class Torrent
4
+
5
+ class << self
6
+ def attr_mappings
7
+ {
8
+ info_hash: 'd.hash',
9
+ name: 'd.name',
10
+ connection_current: 'd.connection_current',
11
+ size_bytes: 'd.size_bytes',
12
+ completed_bytes: 'd.completed_bytes',
13
+ creation_date: 'd.creation_date',
14
+ bytes_done: 'd.bytes_done',
15
+ up_rate: 'd.up.rate',
16
+ down_rate: 'd.down.rate',
17
+ seeders: 'd.peers_complete',
18
+ leechers: 'd.peers_connected',
19
+ is_completed: 'd.complete',
20
+ is_active: 'd.is_active',
21
+ is_hash_checked: 'd.is_hash_checked',
22
+ is_hash_checking: 'd.is_hash_checking',
23
+ is_multifile: 'd.is_multi_file',
24
+ is_open: 'd.is_open'
25
+ }
26
+ end
27
+
28
+ def all(view="main")
29
+ methods = attr_mappings.map {|key,value| "#{value}="}
30
+ Service.call("d.multicall", view, *methods).map do |r|
31
+ attributes = Hash[attr_mappings.keys.zip(r)]
32
+ Torrent.new attributes
33
+ end
34
+ end
35
+
36
+ def views
37
+ Service.call "view.list"
38
+ end
39
+
40
+ def load(url)
41
+ Service.call "load_start", url
42
+ end
43
+
44
+ def action(name, info_hash)
45
+ Service.call "d.#{name}", info_hash
46
+ end
47
+ end
48
+
49
+ attr_accessor *(attr_mappings.keys)
50
+
51
+ def initialize(attributes)
52
+ attributes.each do |attrib, value|
53
+ self.instance_variable_set "@#{attrib}".to_sym, value
54
+ end
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,3 @@
1
+ module Retort
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'xmlrpc/client'
2
+
3
+ class XMLRPC::XMLParser::AbstractStreamParser
4
+
5
+ #A patch for the response method as rtorrent xmlrpc
6
+ #call returns some integers as i8 instead of i4 expected
7
+ #this results in int8 fields showing up with no data
8
+ #as the parse method is not capable of handling such
9
+ #a tag.
10
+ alias original_parseMethodResponse parseMethodResponse
11
+ def parseMethodResponse(str)
12
+ str.gsub!(/<((\/)*)i8>/, "<\\1i4>")
13
+ original_parseMethodResponse(str)
14
+ end
15
+ end
16
+
data/lib/retort.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'retort/core_ext'
2
+ require 'retort/xmlrpc_client'
3
+ require 'retort/service'
4
+ require 'retort/torrent'
5
+
6
+ module Retort
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retort
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Marcel Morgan
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-09-01 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: An rTorrent xmlrpc wrapper written in ruby
22
+ email:
23
+ - marcel.morgan@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/retort.rb
32
+ - lib/retort/core_ext.rb
33
+ - lib/retort/version.rb
34
+ - lib/retort/torrent.rb
35
+ - lib/retort/xmlrpc_client.rb
36
+ - lib/retort/service.rb
37
+ has_rdoc: true
38
+ homepage: https://github.com/mcmorgan/retort
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
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: An rTorrent xmlrpc wrapper written in ruby
69
+ test_files: []
70
+