transmission-rpc-ruby 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.travis.yml +3 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +34 -3
- data/README.md +141 -47
- data/Rakefile +2 -0
- data/lib/transmission.rb +3 -1
- data/lib/transmission/arguments.rb +29 -6
- data/lib/transmission/arguments/session_set.rb +48 -48
- data/lib/transmission/arguments/torrent_add.rb +16 -12
- data/lib/transmission/arguments/torrent_set.rb +24 -24
- data/lib/transmission/fields.rb +42 -0
- data/lib/transmission/fields/session_get.rb +63 -0
- data/lib/transmission/fields/session_stats.rb +17 -0
- data/lib/transmission/fields/torrent_get.rb +78 -0
- data/lib/transmission/model/session.rb +19 -10
- data/lib/transmission/model/session_stats.rb +25 -0
- data/lib/transmission/model/torrent.rb +42 -27
- data/lib/transmission/rpc.rb +48 -44
- data/lib/transmission/rpc/connector.rb +3 -4
- data/lib/transmission/utils.rb +28 -0
- data/spec/helpers/stubs.rb +15 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/transmission/arguments_spec.rb +54 -7
- data/spec/transmission/fields_spec.rb +63 -0
- data/spec/transmission/model/session_spec.rb +84 -0
- data/spec/transmission/model/torrent_spec.rb +82 -0
- data/spec/transmission/rpc/connector_spec.rb +4 -3
- data/spec/transmission/rpc_spec.rb +3 -8
- data/spec/transmission/utils_spec.rb +70 -0
- data/transmission-rpc-ruby.gemspec +2 -2
- metadata +13 -6
- data/lib/transmission/arguments/session_get.rb +0 -63
- data/lib/transmission/arguments/session_stats.rb +0 -17
- data/lib/transmission/arguments/torrent_get.rb +0 -78
@@ -3,18 +3,22 @@ module Transmission
|
|
3
3
|
class TorrentAdd < Transmission::Arguments
|
4
4
|
|
5
5
|
ATTRIBUTES = [
|
6
|
-
'cookies',
|
7
|
-
'download-dir',
|
8
|
-
'filename',
|
9
|
-
'metainfo',
|
10
|
-
'paused',
|
11
|
-
'peer-limit',
|
12
|
-
'bandwidthPriority',
|
13
|
-
'files-wanted',
|
14
|
-
'files-unwanted',
|
15
|
-
'priority-high',
|
16
|
-
'priority-low',
|
17
|
-
'priority-normal'
|
6
|
+
{field: 'cookies'},
|
7
|
+
{field: 'download-dir'},
|
8
|
+
{field: 'filename'},
|
9
|
+
{field: 'metainfo'},
|
10
|
+
{field: 'paused'},
|
11
|
+
{field: 'peer-limit'},
|
12
|
+
{field: 'bandwidthPriority'},
|
13
|
+
{field: 'files-wanted'},
|
14
|
+
{field: 'files-unwanted'},
|
15
|
+
{field: 'priority-high'},
|
16
|
+
{field: 'priority-low'},
|
17
|
+
{field: 'priority-normal'}
|
18
|
+
]
|
19
|
+
|
20
|
+
REQUIRED = [
|
21
|
+
'filename metainfo'
|
18
22
|
]
|
19
23
|
|
20
24
|
end
|
@@ -3,30 +3,30 @@ module Transmission
|
|
3
3
|
class TorrentSet < Transmission::Arguments
|
4
4
|
|
5
5
|
ATTRIBUTES = [
|
6
|
-
'bandwidthPriority',
|
7
|
-
'downloadLimit',
|
8
|
-
'downloadLimited',
|
9
|
-
'downloadLimit',
|
10
|
-
'files-wanted',
|
11
|
-
'files-unwanted',
|
12
|
-
'honorsSessionLimits',
|
13
|
-
'ids',
|
14
|
-
'location',
|
15
|
-
'peer-limit',
|
16
|
-
'priority-high',
|
17
|
-
'priority-low',
|
18
|
-
'priority-normal',
|
19
|
-
'queuePosition',
|
20
|
-
'seedIdleLimit',
|
21
|
-
'seedIdleMode',
|
22
|
-
'seedRatioLimit',
|
23
|
-
'seedRatioMode',
|
24
|
-
'trackerAdd',
|
25
|
-
'trackerRemove',
|
26
|
-
'trackerReplace',
|
27
|
-
'uploadLimit',
|
28
|
-
'uploadLimited',
|
29
|
-
'uploadLimit'
|
6
|
+
{field: 'bandwidthPriority'},
|
7
|
+
{field: 'downloadLimit'},
|
8
|
+
{field: 'downloadLimited'},
|
9
|
+
{field: 'downloadLimit'},
|
10
|
+
{field: 'files-wanted'},
|
11
|
+
{field: 'files-unwanted'},
|
12
|
+
{field: 'honorsSessionLimits'},
|
13
|
+
{field: 'ids'},
|
14
|
+
{field: 'location'},
|
15
|
+
{field: 'peer-limit'},
|
16
|
+
{field: 'priority-high'},
|
17
|
+
{field: 'priority-low'},
|
18
|
+
{field: 'priority-normal'},
|
19
|
+
{field: 'queuePosition'},
|
20
|
+
{field: 'seedIdleLimit'},
|
21
|
+
{field: 'seedIdleMode'},
|
22
|
+
{field: 'seedRatioLimit'},
|
23
|
+
{field: 'seedRatioMode'},
|
24
|
+
{field: 'trackerAdd'},
|
25
|
+
{field: 'trackerRemove'},
|
26
|
+
{field: 'trackerReplace'},
|
27
|
+
{field: 'uploadLimit'},
|
28
|
+
{field: 'uploadLimited'},
|
29
|
+
{field: 'uploadLimit'}
|
30
30
|
]
|
31
31
|
|
32
32
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'fields', 'torrent_get')
|
2
|
+
require File.join(File.dirname(__FILE__), 'fields', 'session_get')
|
3
|
+
require File.join(File.dirname(__FILE__), 'fields', 'session_stats')
|
4
|
+
require File.join(File.dirname(__FILE__), 'utils')
|
5
|
+
|
6
|
+
module Transmission
|
7
|
+
class Fields
|
8
|
+
class InvalidField < StandardError; end
|
9
|
+
|
10
|
+
attr_accessor :fields
|
11
|
+
|
12
|
+
ATTRIBUTES = []
|
13
|
+
|
14
|
+
def initialize(fields = nil)
|
15
|
+
@fields = fields.inject([]) do |fields, field|
|
16
|
+
found = self.class::ATTRIBUTES.select { |attr| attr[:field] == field}
|
17
|
+
raise Transmission::Fields::InvalidField, field if found.empty?
|
18
|
+
fields << field
|
19
|
+
end if fields
|
20
|
+
@fields = self.class::ATTRIBUTES.collect do |key|
|
21
|
+
key[:field]
|
22
|
+
end if fields.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_fields
|
26
|
+
@fields
|
27
|
+
end
|
28
|
+
|
29
|
+
class << self
|
30
|
+
include Transmission::Utils
|
31
|
+
|
32
|
+
def is_valid?(key)
|
33
|
+
is_valid_key? key, self::ATTRIBUTES
|
34
|
+
end
|
35
|
+
|
36
|
+
def real_key(key)
|
37
|
+
option_key key, self::ATTRIBUTES
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Transmission
|
2
|
+
class Fields
|
3
|
+
class SessionGet < Transmission::Fields
|
4
|
+
|
5
|
+
ATTRIBUTES = [
|
6
|
+
{field: 'alt-speed-down'},
|
7
|
+
{field: 'alt-speed-enabled'},
|
8
|
+
{field: 'alt-speed-time-begin'},
|
9
|
+
{field: 'alt-speed-time-enabled'},
|
10
|
+
{field: 'alt-speed-time-end'},
|
11
|
+
{field: 'alt-speed-time-day'},
|
12
|
+
{field: 'alt-speed-up'},
|
13
|
+
{field: 'blocklist-url'},
|
14
|
+
{field: 'blocklist-update'},
|
15
|
+
{field: 'blocklist-enabled'},
|
16
|
+
{field: 'blocklist-size'},
|
17
|
+
{field: 'cache-size-mb'},
|
18
|
+
{field: 'config-dir'},
|
19
|
+
{field: 'download-dir'},
|
20
|
+
{field: 'download-queue-size'},
|
21
|
+
{field: 'download-queue-enabled'},
|
22
|
+
{field: 'dht-enabled'},
|
23
|
+
{field: 'encryption'},
|
24
|
+
{field: 'required'},
|
25
|
+
{field: 'preferred'},
|
26
|
+
{field: 'tolerated'},
|
27
|
+
{field: 'idle-seeding-limit'},
|
28
|
+
{field: 'idle-seeding-limit-enabled'},
|
29
|
+
{field: 'incomplete-dir'},
|
30
|
+
{field: 'incomplete-dir-enabled'},
|
31
|
+
{field: 'lpd-enabled'},
|
32
|
+
{field: 'peer-limit-global'},
|
33
|
+
{field: 'peer-limit-per-torrent'},
|
34
|
+
{field: 'pex-enabled'},
|
35
|
+
{field: 'peer-port'},
|
36
|
+
{field: 'peer-port-random-on-start'},
|
37
|
+
{field: 'port-forwarding-enabled'},
|
38
|
+
{field: 'queue-stalled-enabled'},
|
39
|
+
{field: 'queue-stalled-minutes'},
|
40
|
+
{field: 'rename-partial-files'},
|
41
|
+
{field: 'rpc-version'},
|
42
|
+
{field: 'rpc-version-minimum'},
|
43
|
+
{field: 'script-torrent-done-filename'},
|
44
|
+
{field: 'script-torrent-done-enabled'},
|
45
|
+
{field: 'done'},
|
46
|
+
{field: 'seedRatioLimit'},
|
47
|
+
{field: 'seedRatioLimited'},
|
48
|
+
{field: 'seed-queue-size'},
|
49
|
+
{field: 'seed-queue-enabled'},
|
50
|
+
{field: 'speed-limit-down'},
|
51
|
+
{field: 'speed-limit-down-enabled'},
|
52
|
+
{field: 'speed-limit-up'},
|
53
|
+
{field: 'speed-limit-up-enabled'},
|
54
|
+
{field: 'start-added-torrents'},
|
55
|
+
{field: 'trash-original-torrent-files'},
|
56
|
+
{field: 'units'},
|
57
|
+
{field: 'utp-enabled'},
|
58
|
+
{field: 'version'}
|
59
|
+
]
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Transmission
|
2
|
+
class Fields
|
3
|
+
class SessionStats < Transmission::Fields
|
4
|
+
|
5
|
+
ATTRIBUTES = [
|
6
|
+
{field: 'activeTorrentCount'},
|
7
|
+
{field: 'downloadSpeed'},
|
8
|
+
{field: 'pausedTorrentCount'},
|
9
|
+
{field: 'torrentCount'},
|
10
|
+
{field: 'uploadSpeed'},
|
11
|
+
{field: 'cumulative-stats'},
|
12
|
+
{field: 'current-stats'}
|
13
|
+
]
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Transmission
|
2
|
+
class Fields
|
3
|
+
class TorrentGet < Transmission::Fields
|
4
|
+
|
5
|
+
ATTRIBUTES = [
|
6
|
+
{field: 'id'},
|
7
|
+
{field: 'activityDate'},
|
8
|
+
{field: 'addedDate'},
|
9
|
+
{field: 'bandwidthPriority'},
|
10
|
+
{field: 'comment'},
|
11
|
+
{field: 'corruptEver'},
|
12
|
+
{field: 'creator'},
|
13
|
+
{field: 'dateCreated'},
|
14
|
+
{field: 'desiredAvailable'},
|
15
|
+
{field: 'doneDate'},
|
16
|
+
{field: 'downloadDir'},
|
17
|
+
{field: 'downloadedEver'},
|
18
|
+
{field: 'downloadLimit'},
|
19
|
+
{field: 'downloadLimited'},
|
20
|
+
{field: 'error'},
|
21
|
+
{field: 'errorString'},
|
22
|
+
{field: 'eta'},
|
23
|
+
{field: 'etaIdle'},
|
24
|
+
{field: 'files'},
|
25
|
+
{field: 'fileStats'},
|
26
|
+
{field: 'hashString'},
|
27
|
+
{field: 'haveUnchecked'},
|
28
|
+
{field: 'haveValid'},
|
29
|
+
{field: 'honorsSessionLimits'},
|
30
|
+
{field: 'isFinished'},
|
31
|
+
{field: 'isPrivate'},
|
32
|
+
{field: 'isStalled'},
|
33
|
+
{field: 'leftUntilDone'},
|
34
|
+
{field: 'magnetLink'},
|
35
|
+
{field: 'manualAnnounceTime'},
|
36
|
+
{field: 'maxConnectedPeers'},
|
37
|
+
{field: 'metadataPercentComplete'},
|
38
|
+
{field: 'name'},
|
39
|
+
{field: 'peer-limit'},
|
40
|
+
{field: 'peers'},
|
41
|
+
{field: 'peersConnected'},
|
42
|
+
{field: 'peersFrom'},
|
43
|
+
{field: 'peersGettingFromUs'},
|
44
|
+
{field: 'peersSendingToUs'},
|
45
|
+
{field: 'percentDone'},
|
46
|
+
{field: 'pieces'},
|
47
|
+
{field: 'pieceCount'},
|
48
|
+
{field: 'pieceSize'},
|
49
|
+
{field: 'priorities'},
|
50
|
+
{field: 'queuePosition'},
|
51
|
+
{field: 'rateDownload'},
|
52
|
+
{field: 'rateUpload'},
|
53
|
+
{field: 'recheckProgress'},
|
54
|
+
{field: 'secondsDownloading'},
|
55
|
+
{field: 'secondsSeeding'},
|
56
|
+
{field: 'seedIdleLimit'},
|
57
|
+
{field: 'seedIdleMode'},
|
58
|
+
{field: 'seedRatioLimit'},
|
59
|
+
{field: 'seedRatioMode'},
|
60
|
+
{field: 'sizeWhenDone'},
|
61
|
+
{field: 'startDate'},
|
62
|
+
{field: 'status'},
|
63
|
+
{field: 'trackers'},
|
64
|
+
{field: 'trackerStats'},
|
65
|
+
{field: 'totalSize'},
|
66
|
+
{field: 'torrentFile'},
|
67
|
+
{field: 'uploadedEver'},
|
68
|
+
{field: 'uploadLimit'},
|
69
|
+
{field: 'uploadLimited'},
|
70
|
+
{field: 'uploadRatio'},
|
71
|
+
{field: 'wanted'},
|
72
|
+
{field: 'webseeds'},
|
73
|
+
{field: 'webseedsSendingToUs'}
|
74
|
+
]
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -3,27 +3,36 @@ module Transmission
|
|
3
3
|
class Session
|
4
4
|
class SessionError < StandardError; end
|
5
5
|
|
6
|
-
attr_accessor :attributes
|
6
|
+
attr_accessor :attributes, :connector
|
7
7
|
|
8
|
-
def initialize(session_object)
|
8
|
+
def initialize(session_object, connector)
|
9
9
|
@attributes = session_object
|
10
|
+
@connector = connector
|
10
11
|
end
|
11
12
|
|
12
|
-
def
|
13
|
-
@attributes
|
13
|
+
def save!
|
14
|
+
filtered = Transmission::Arguments::SessionSet.filter @attributes
|
15
|
+
connector.set_session filtered
|
14
16
|
end
|
15
17
|
|
16
|
-
def
|
17
|
-
|
18
|
+
def method_missing(symbol, *args)
|
19
|
+
string = symbol.to_s
|
20
|
+
if string[-1] == '='
|
21
|
+
string = string[0..-2]
|
22
|
+
key = Transmission::Arguments::SessionSet.real_key string
|
23
|
+
return @attributes[key] = args.first if !!key
|
24
|
+
else
|
25
|
+
key = Transmission::Fields::SessionGet.real_key string
|
26
|
+
return @attributes[key] if !!key
|
27
|
+
end
|
28
|
+
super
|
18
29
|
end
|
19
30
|
|
20
31
|
class << self
|
21
32
|
def get(options = {})
|
22
33
|
rpc = options[:connector] || connector
|
23
|
-
|
24
|
-
|
25
|
-
merged_body = session_body.merge(session_stats_body)
|
26
|
-
Session.new merged_body
|
34
|
+
body = rpc.get_session options[:fields]
|
35
|
+
Session.new body, rpc
|
27
36
|
end
|
28
37
|
|
29
38
|
def connector
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Transmission
|
2
|
+
module Model
|
3
|
+
class SessionStats
|
4
|
+
|
5
|
+
attr_accessor :attributes, :connector
|
6
|
+
|
7
|
+
def initialize(session_object, connector)
|
8
|
+
@attributes = session_object
|
9
|
+
@connector = connector
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def get(options = {})
|
14
|
+
rpc = options[:connector] || connector
|
15
|
+
body = rpc.get_session_stats options[:fields]
|
16
|
+
SessionStats.new body, rpc
|
17
|
+
end
|
18
|
+
|
19
|
+
def connector
|
20
|
+
Transmission::Config.get_connector
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -6,55 +6,57 @@ module Transmission
|
|
6
6
|
class MissingAttributesError < StandardError; end
|
7
7
|
class DuplicateTorrentError < StandardError; end
|
8
8
|
|
9
|
-
attr_accessor :attributes, :deleted
|
9
|
+
attr_accessor :attributes, :deleted, :connector
|
10
10
|
|
11
|
-
def initialize(torrent_object)
|
11
|
+
def initialize(torrent_object, connector)
|
12
12
|
@attributes = torrent_object
|
13
|
+
@connector = connector
|
13
14
|
end
|
14
15
|
|
15
16
|
def delete!(remove_local_data = false)
|
16
|
-
|
17
|
+
connector.remove_torrent [self.id], remove_local_data
|
17
18
|
@deleted = true
|
18
19
|
end
|
19
20
|
|
20
|
-
def
|
21
|
-
|
21
|
+
def save!
|
22
|
+
filtered = Transmission::Arguments::TorrentSet.filter @attributes
|
23
|
+
connector.set_torrent [self.id], filtered
|
22
24
|
end
|
23
25
|
|
24
|
-
def move_up
|
25
|
-
|
26
|
+
def move_up!
|
27
|
+
connector.move_up_torrent [self.id]
|
26
28
|
end
|
27
29
|
|
28
|
-
def move_down
|
29
|
-
|
30
|
+
def move_down!
|
31
|
+
connector.move_down_torrent [self.id]
|
30
32
|
end
|
31
33
|
|
32
|
-
def move_top
|
33
|
-
|
34
|
+
def move_top!
|
35
|
+
connector.move_top_torrent [self.id]
|
34
36
|
end
|
35
37
|
|
36
|
-
def move_bottom
|
37
|
-
|
38
|
+
def move_bottom!
|
39
|
+
connector.move_bottom_torrent [self.id]
|
38
40
|
end
|
39
41
|
|
40
|
-
def start
|
41
|
-
|
42
|
+
def start!
|
43
|
+
connector.start_torrent [self.id]
|
42
44
|
end
|
43
45
|
|
44
|
-
def start_now
|
45
|
-
|
46
|
+
def start_now!
|
47
|
+
connector.start_torrent_now [self.id]
|
46
48
|
end
|
47
49
|
|
48
|
-
def stop
|
49
|
-
|
50
|
+
def stop!
|
51
|
+
connector.stop_torrent [self.id]
|
50
52
|
end
|
51
53
|
|
52
|
-
def verify
|
53
|
-
|
54
|
+
def verify!
|
55
|
+
connector.verify_torrent [self.id]
|
54
56
|
end
|
55
57
|
|
56
|
-
def re_announce
|
57
|
-
|
58
|
+
def re_announce!
|
59
|
+
connector.re_announce_torrent [self.id]
|
58
60
|
end
|
59
61
|
|
60
62
|
def finished?
|
@@ -65,20 +67,33 @@ module Transmission
|
|
65
67
|
|
66
68
|
end
|
67
69
|
|
70
|
+
def method_missing(symbol, *args)
|
71
|
+
string = symbol.to_s
|
72
|
+
if string[-1] == '='
|
73
|
+
string = string[0..-2]
|
74
|
+
key = Transmission::Arguments::TorrentSet.real_key string
|
75
|
+
return @attributes[key] = args.first if !!key
|
76
|
+
else
|
77
|
+
key = Transmission::Fields::TorrentGet.real_key string
|
78
|
+
return @attributes[key] if !!key
|
79
|
+
end
|
80
|
+
super
|
81
|
+
end
|
82
|
+
|
68
83
|
class << self
|
69
84
|
def all(options = {})
|
70
85
|
rpc = options[:connector] || connector
|
71
|
-
body = rpc.get_torrent nil, options
|
86
|
+
body = rpc.get_torrent nil, options[:fields]
|
72
87
|
body['torrents'].inject([]) do |torrents, torrent|
|
73
|
-
torrents << Torrent.new(torrent)
|
88
|
+
torrents << Torrent.new(torrent, rpc)
|
74
89
|
end
|
75
90
|
end
|
76
91
|
|
77
92
|
def find(id, options = {})
|
78
93
|
rpc = options[:connector] || connector
|
79
|
-
body = rpc.get_torrent [id], options
|
94
|
+
body = rpc.get_torrent [id], options[:fields]
|
80
95
|
raise TorrentNotFoundError if body['torrents'].size == 0
|
81
|
-
Torrent.new body['torrents'].first
|
96
|
+
Torrent.new body['torrents'].first, rpc
|
82
97
|
end
|
83
98
|
|
84
99
|
def add(options = {})
|