rtransmission 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright
10
+ notice, this list of conditions and the following disclaimer in the
11
+ documentation and/or other materials provided with the distribution.
12
+ 3. Neither the name of the author nor the names of its
13
+ contributors may be used to endorse or promote products derived from
14
+ this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ RTransmission
2
+ -------------
3
+
4
+ Ruby Transmission Bindings
5
+
6
+ Basic Usage
7
+ -----------
8
+
9
+ requre 'rtransmission'
10
+
11
+ RTransmission::Client.new(:user => 'foo', :password => 'bar') do |client|
12
+ url = 'http://torrents.gentoo.org/torrents/livedvd-x86-amd64-32ul-11.1.torrent'
13
+ torrent = RTransmission::Torrent.add(client, :url => url)
14
+ torrent = RTransmission::Torrent.list(client)[0]
15
+
16
+ files = torrent.files
17
+ files.each { |f| puts f.name }
18
+
19
+ torrent.upload_limited = false
20
+ end
21
+
22
+ Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
23
+ All rights reserved.
24
+ Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
@@ -0,0 +1,45 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'net/http'
6
+
7
+ module RTransmission
8
+ class Client
9
+ attr_accessor :host
10
+ attr_accessor :port
11
+ attr_accessor :path
12
+ attr_accessor :user
13
+ attr_accessor :password
14
+
15
+ attr_reader :session_id
16
+
17
+ def initialize(args = {}, &block)
18
+ @host = args[:host] || 'localhost'
19
+ @port = args[:port] || 9091
20
+ @path = args[:path] || '/transmission/rpc'
21
+ @user = args[:user] || nil
22
+ @password = args[:password] || nil
23
+
24
+ block.call(self) if block
25
+ end
26
+
27
+ def call(request)
28
+ req = Net::HTTP::Post.new(@path)
29
+ req.basic_auth(@user, @password) if @user || @password
30
+ req['X-Transmission-Session-Id'] = @session_id if @session_id
31
+ req.body = request.to_json
32
+
33
+ res = Net::HTTP.start(@host, @port) do |http|
34
+ http.request(req)
35
+ end
36
+
37
+ if res.code.to_i == 409
38
+ @session_id = res['X-Transmission-Session-Id']
39
+ return call(request)
40
+ end
41
+
42
+ return RTransmission::Response.new(res.body, request.response_prefix, request.response_block).parse
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ class Exception < ::Exception
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ class Field
7
+ def self.unmap(value)
8
+ value
9
+ end
10
+
11
+ def self.define_attribute(name, rpc_name, args = {})
12
+ self.send :define_method, name.to_s do
13
+ value = @hash[rpc_name]
14
+ value = args[:type].unmap(value) if args[:type]
15
+
16
+ value
17
+ end
18
+ end
19
+
20
+ def initialize(hash)
21
+ @hash = hash
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Error
8
+ MAP = {0 => :ok, 1 => :tracker_warning, 2 => :tracker_error, 3 => :local_error}
9
+
10
+ def self.unmap(value)
11
+ MAP[value]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class ETA
8
+ MAP = {-1 => :not_available, -2 => :unknown}
9
+
10
+ def self.unmap(value)
11
+ return value if value >= 0
12
+ MAP[value]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class File < RTransmission::Field
8
+ define_attribute :name, 'name'
9
+ define_attribute :length, 'length'
10
+ define_attribute :bytes_completed, 'bytesCompleted'
11
+
12
+ def self.unmap(value)
13
+ RTransmission::Fields::File.new(value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class FileStat < RTransmission::Field
8
+ define_attribute :bytes_completed, 'bytesCompleted'
9
+ define_attribute :wanted?, 'wanted'
10
+ define_attribute :priority, 'priority', :type => RTransmission::Fields::Priority
11
+
12
+ def self.unmap(value)
13
+ RTransmission::Fields::FileStat.new(value)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Peer < RTransmission::Field
8
+ define_attribute :address, 'address'
9
+ define_attribute :client_choked?, 'clientIsChoked'
10
+ define_attribute :client_interested?, 'clientIsInterested'
11
+ define_attribute :client_name, 'clientName'
12
+ define_attribute :flag_str, 'flagStr'
13
+ define_attribute :downloading_from?, 'isDownloadingFrom'
14
+ define_attribute :encrypted?, 'isEncrypted'
15
+ define_attribute :incoming?, 'isIncoming'
16
+ define_attribute :utp?, 'isUTP'
17
+ define_attribute :uploading_to?, 'isUploadingTo'
18
+ define_attribute :peer_choked?, 'peerIsChoked'
19
+ define_attribute :peer_interested?, 'peerIsInterested'
20
+ define_attribute :port, 'port'
21
+ define_attribute :progress, 'progress', :type => RTransmission::Fields::Percent
22
+ define_attribute :rate_to_client, 'rateToClient'
23
+ define_attribute :rate_to_peer, 'rateToPeer'
24
+
25
+ def self.unmap(value)
26
+ RTransmission::Fields::Peer.new(value)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class PeersFrom < RTransmission::Field
8
+ define_attribute :cache, 'fromCache'
9
+ define_attribute :dht, 'fromDht'
10
+ define_attribute :incoming, 'fromIncoming'
11
+ define_attribute :ltep, 'fromLtep'
12
+ define_attribute :pex, 'fromPex'
13
+ define_attribute :tracker, 'fromTracker'
14
+
15
+ def self.unmap(value)
16
+ RTransmission::Fields::PeersFrom.new(value)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Percent
8
+ def self.unmap(value)
9
+ value
10
+ end
11
+
12
+ def self.map(value)
13
+ value
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Pieces
8
+ def self.unmap(value)
9
+ value
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Priority
8
+ MAP = {-1 => :low, 0 => :normal, 1 => :high}
9
+
10
+ def self.unmap(value)
11
+ MAP[value]
12
+ end
13
+
14
+ def self.map(value)
15
+ MAP.key(value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class SeedIdleMode
8
+ MAP = {0 => :global, 1 => :single, 2 => :unlimited}
9
+
10
+ def self.unmap(value)
11
+ MAP[value]
12
+ end
13
+
14
+ def self.map(value)
15
+ MAP.key(value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class SeedRatioMode
8
+ MAP = {0 => :global, 1 => :single, 2 => :unlimited}
9
+
10
+ def self.unmap(value)
11
+ MAP[value]
12
+ end
13
+
14
+ def self.map(value)
15
+ MAP.key(value)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Status
8
+ MAP = {1 => :check_wait, 2 => :check, 4 => :download, 8 => :seed, 16 => :stopped}
9
+
10
+ def self.unmap(value)
11
+ result = []
12
+ MAP.each do |mask, status|
13
+ result << status if mask & value != 0
14
+ end
15
+
16
+ result
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Time
8
+ def self.unmap(value)
9
+ value == 0 ? nil : ::Time.at(value)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module Fields
7
+ class Tracker < RTransmission::Field
8
+ define_attribute :id, 'id'
9
+ define_attribute :announce, 'announce'
10
+ define_attribute :scrape, 'scrape'
11
+ define_attribute :tier, 'tier'
12
+
13
+ def self.unmap(value)
14
+ RTransmission::Fields::Tracker.new(value)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ # FIXME: add types where needed
6
+ module RTransmission
7
+ module Fields
8
+ class TrackerStat < RTransmission::Field
9
+ define_attribute :id, 'id'
10
+ define_attribute :announce, 'announce'
11
+ define_attribute :announce_state, 'announceState'
12
+ define_attribute :download_count, 'downloadCount'
13
+ define_attribute :has_announced, 'hasAnnounced'
14
+ define_attribute :has_scraped, 'hasScraped'
15
+ define_attribute :host, 'host'
16
+ define_attribute :is_backup, 'isBackup'
17
+ define_attribute :last_announce_peer_count, 'lastAnnouncePeerCount'
18
+ define_attribute :last_announce_result, 'lastAnnounceResult'
19
+ define_attribute :last_announce_start_time, 'lastAnnounceStartTime'
20
+ define_attribute :last_announce_succeeded, 'lastAnnounceSucceeded'
21
+ define_attribute :last_announce_time, 'lastAnnounceTime'
22
+ define_attribute :last_announce_timed_out, 'lastAnnounceTimedOut'
23
+ define_attribute :last_scrape_result, 'lastScrapeResult'
24
+ define_attribute :last_scrape_start_time, 'lastScrapeStartTime'
25
+ define_attribute :last_scrape_succeeded, 'lastScrapeSucceeded'
26
+ define_attribute :last_scrape_time, 'lastScrapeTime'
27
+ define_attribute :last_scrape_timed_out, 'lastScrapeTimedOut'
28
+ define_attribute :leecher_count, 'leecherCount'
29
+ define_attribute :next_announce_time, 'nextAnnounceTime'
30
+ define_attribute :next_scrape_time, 'nextScrapeTime'
31
+ define_attribute :scrape, 'scrape'
32
+ define_attribute :scrape_state, 'scrapeState'
33
+ define_attribute :seeder_count, 'seederCount'
34
+ define_attribute :tier, 'tier'
35
+
36
+ def self.unmap(value)
37
+ RTransmission::Fields::TrackerStat.new(value)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'rtransmission/fields/error'
6
+ require 'rtransmission/fields/eta'
7
+ require 'rtransmission/fields/percent'
8
+ require 'rtransmission/fields/priority'
9
+ require 'rtransmission/fields/time'
10
+ require 'rtransmission/fields/file'
11
+ require 'rtransmission/fields/file_stat'
12
+ require 'rtransmission/fields/peer'
13
+ require 'rtransmission/fields/peers_from'
14
+ require 'rtransmission/fields/pieces'
15
+ require 'rtransmission/fields/seed_idle_mode'
16
+ require 'rtransmission/fields/seed_ratio_mode'
17
+ require 'rtransmission/fields/status'
18
+ require 'rtransmission/fields/tracker'
19
+ require 'rtransmission/fields/tracker_stat'
@@ -0,0 +1,25 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'json'
6
+
7
+ module RTransmission
8
+ class Request
9
+ attr_accessor :method
10
+ attr_accessor :arguments
11
+ attr_accessor :response_prefix
12
+ attr_accessor :response_block
13
+
14
+ def initialize(method, arguments, response_prefix, &response_block)
15
+ @method = method
16
+ @arguments = arguments
17
+ @response_prefix = response_prefix
18
+ @response_block = response_block
19
+ end
20
+
21
+ def to_json
22
+ {'method' => @method, 'arguments' => @arguments}.to_json
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'json'
6
+
7
+ module RTransmission
8
+ class Response
9
+ attr_accessor :body
10
+ attr_accessor :prefix
11
+ attr_accessor :block
12
+
13
+ def initialize(body, prefix, block)
14
+ @body = body
15
+ @prefix = prefix
16
+ @block = block
17
+ end
18
+
19
+ def parse
20
+ body = JSON.parse(@body)
21
+ raise RTransmission::Exception.new((@prefix ? @prefix + ': ' : '') + body['result']) if body['result'] != 'success'
22
+ return @block.call(body['arguments']) if @block
23
+ body['arguments']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,192 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'base64'
6
+
7
+ # FIXME: files-wanted/unwanted & prioriry-high/low/normal for both add and new torrents
8
+ # FIXME: add/remove/replace trackers
9
+ module RTransmission
10
+ class Torrent
11
+ attr_reader :id
12
+
13
+ def self.add(client, args = {})
14
+ pargs = {}
15
+
16
+ raise RTransmission::Exception.new('Torrent#add: only one of remote_file, url, or torrent must be specified') if (args.keys & [:remote_file, :url, :torrent]).count != 1
17
+ pargs['filename'] = args[:remote_file] if args[:remote_file]
18
+ pargs['filename'] = args[:url] if args[:url]
19
+ pargs['metainfo'] = Base64::encode(args[:torrent]) if args[:torrent]
20
+
21
+ pargs['cookies'] = args[:cookies] if args[:cookies]
22
+ pargs['download-dir'] = args[:download_dir] if args[:download_dir]
23
+ pargs['paused'] = args[:paused] if args[:paused]
24
+ pargs['peer-limit'] = args[:peer_limit] if args[:peer_limit]
25
+ pargs['bandwithPriority'] = args[:bandwith_priority] if args[:bandwith_priority] # FIXME: use field here
26
+
27
+ request = RTransmission::Request.new('torrent-add', pargs, 'Torrent#add') do |arguments|
28
+ RTransmission::Torrent.new(client, arguments['torrent-added']['id'])
29
+ end
30
+
31
+ client.call(request)
32
+ end
33
+
34
+ def self.list(client)
35
+ request = RTransmission::Request.new('torrent-get', {'fields' => ['id']}, 'Torrent#list') do |arguments|
36
+ torrents = []
37
+ arguments['torrents'].each do |torrent|
38
+ torrents << RTransmission::Torrent.new(client, torrent['id'])
39
+ end
40
+
41
+ torrents
42
+ end
43
+
44
+ client.call(request)
45
+ end
46
+
47
+ def self.define_field(name, rpc_name, args = {})
48
+ self.send :define_method, name.to_s do
49
+ request = RTransmission::Request.new('torrent-get', {'ids' => @id, 'fields' => [rpc_name]}, 'Torrent.' + name.to_s) do |arguments|
50
+ result = arguments['torrents'][0][rpc_name]
51
+ if args[:type]
52
+ type = args[:type]
53
+ if type.class == Array
54
+ type = type[0]
55
+ result.map! { |r| type.unmap(r) }
56
+ else
57
+ result = type.unmap(result)
58
+ end
59
+ end
60
+
61
+ result
62
+ end
63
+
64
+ @client.call(request)
65
+ end
66
+
67
+ if args[:writeable] == true
68
+ self.send :define_method, name.to_s.gsub('?', '') + '=' do |value|
69
+ rpc_value = value
70
+ if args[:type]
71
+ type = args[:type]
72
+ if type.class == Array
73
+ type = type[0]
74
+ rpc_value.map! { |r| type.map(r) }
75
+ else
76
+ rpc_value = type.map(rpc_value)
77
+ end
78
+ end
79
+
80
+ request = RTransmission::Request.new('torrent-set', {'ids' => @id, rpc_name => rpc_value}, 'Torrent.' + name.to_s + '=') do
81
+ value
82
+ end
83
+
84
+ @client.call(request)
85
+ end
86
+ end
87
+ end
88
+
89
+ define_field :activity_date, 'activityDate', :type => RTransmission::Fields::Time
90
+ define_field :added_date, 'addedDate', :type => RTransmission::Fields::Time
91
+ define_field :bandwidth_priority, 'bandwidthPriority', :type => RTransmission::Fields::Priority, :writeable => true
92
+ define_field :comment, 'comment'
93
+ define_field :corrupt_ever, 'corruptEver'
94
+ define_field :creator, 'creator'
95
+ define_field :date_created, 'dateCreated', :type => RTransmission::Fields::Time
96
+ define_field :desired_available, 'desiredAvailable'
97
+ define_field :done_date, 'doneDate', :type => RTransmission::Fields::Time
98
+ define_field :download_dir, 'downloadDir'
99
+ define_field :downloaded_ever, 'downloadedEver'
100
+ define_field :download_limit, 'downloadLimit', :writeable => true
101
+ define_field :download_limited?, 'downloadLimited', :writeable => true
102
+ define_field :error, 'error', :type => RTransmission::Fields::Error
103
+ define_field :error_string, 'errorString'
104
+ define_field :eta, 'eta', :type => RTransmission::Fields::ETA
105
+ define_field :files, 'files', :type => [RTransmission::Fields::File]
106
+ define_field :file_stats, 'fileStats', :type => [RTransmission::Fields::FileStat]
107
+ define_field :hash_string, 'hashString'
108
+ define_field :have_unchecked, 'haveUnchecked'
109
+ define_field :have_valid, 'haveValid'
110
+ define_field :honors_session_limits?, 'honorsSessionLimits', :writeable => true
111
+ define_field :finished?, 'isFinished'
112
+ define_field :private?, 'isPrivate'
113
+ define_field :left_until_done, 'leftUntilDone'
114
+ define_field :magnet_link, 'magnetLink'
115
+ define_field :manual_announce_time, 'manualAnnounceTime' # FIXME: add type
116
+ define_field :max_connected_peers, 'maxConnectedPeers'
117
+ define_field :metadata_percent_complete, 'metadataPercentComplete'
118
+ define_field :name, 'name'
119
+ define_field :peer_limit, 'peer-limit', :writeable => true
120
+ define_field :peers, 'peers', :type => [RTransmission::Fields::Peer]
121
+ define_field :peers_connected, 'peersConnected'
122
+ define_field :peers_from, 'peersFrom', :type => RTransmission::Fields::PeersFrom
123
+ define_field :peers_getting_from_us, 'peersGettingFromUs'
124
+ define_field :peers_sending_to_us, 'peersSendingToUs'
125
+ define_field :percent_done, 'percentDone', :type => RTransmission::Fields::Percent
126
+ define_field :pieces, 'pieces', :type => RTransmission::Fields::Pieces
127
+ define_field :piece_count, 'pieceCount'
128
+ define_field :piece_size, 'pieceSize'
129
+ define_field :priorities, 'priorities', :type => [RTransmission::Fields::Priority]
130
+ define_field :rate_download, 'rateDownload'
131
+ define_field :rate_upload, 'rateUpload'
132
+ define_field :recheck_progress, 'recheckProgress', :type => RTransmission::Fields::Percent
133
+ define_field :seconds_downloading, 'secondsDownloading'
134
+ define_field :seconds_seeding, 'secondsSeeding'
135
+ define_field :seed_idle_limit, 'seedIdleLimit', :writeable => true
136
+ define_field :seed_idle_mode, 'seedIdleMode', :type => RTransmission::Fields::SeedIdleMode, :writeable => true
137
+ define_field :seed_ratio_limit, 'seedRatioLimit', :type => RTransmission::Fields::Percent, :writeable => true
138
+ define_field :seed_ratio_mode, 'seedRatioMode', :type => RTransmission::Fields::SeedRatioMode, :writeable => true
139
+ define_field :size_when_done, 'sizeWhenDone'
140
+ define_field :start_date, 'startDate', :type => RTransmission::Fields::Time
141
+ define_field :status, 'status', :type => RTransmission::Fields::Status
142
+ define_field :trackers, 'trackers', :type => [RTransmission::Fields::Tracker]
143
+ define_field :tracker_stats, 'trackerStats', :type => [RTransmission::Fields::TrackerStat]
144
+ define_field :total_size, 'totalSize'
145
+ define_field :torrent_file, 'torrentFile'
146
+ define_field :uploaded_ever, 'uploadedEver'
147
+ define_field :upload_limit, 'uploadLimit', :writeable => true
148
+ define_field :upload_limited?, 'uploadLimited', :writeable => true
149
+ define_field :upload_ratio, 'uploadRatio', :type => RTransmission::Fields::Percent
150
+ define_field :wanted, 'wanted'
151
+ define_field :webseeds, 'webseeds' # FIXME: add type
152
+ define_field :webseeds_sending_to_us, 'webseedsSendingToUs'
153
+
154
+ def initialize(client, id)
155
+ @client = client
156
+ @id = id
157
+ end
158
+
159
+ def start
160
+ @client.call(RTransmission::Request.new('torrent-start', {'ids' => @id}, 'Torrent.start'))
161
+ end
162
+
163
+ def stop
164
+ @client.call(RTransmission::Request.new('torrent-stop', {'ids' => @id}, 'Torrent.stop'))
165
+ end
166
+
167
+ def verify
168
+ @client.call(RTransmission::Request.new('torrent-verify', {'ids' => @id}, 'Torrent.verify'))
169
+ end
170
+
171
+ def reannounce
172
+ @client.call(RTransmission::Request.new('torrent-reannounce', {'ids' => @id}, 'Torrent.reannounce'))
173
+ end
174
+
175
+ def remove(args = {})
176
+ pargs = {}
177
+
178
+ pargs['delete-local-data'] = args[:delete_local_data] if args[:delete_local_data]
179
+
180
+ @client.call(RTransmission::Request.new('torrent-remove', {'ids' => @id}.merge(pargs), 'Torrent.remove'))
181
+ end
182
+
183
+ def move(args = {})
184
+ pargs = {}
185
+
186
+ pargs['location'] = args[:location] if args[:location]
187
+ pargs['move'] = args[:move] if args[:move]
188
+
189
+ @client.call(RTransmission::Request.new('torrent-set-location', {'ids' => @id}.merge(pargs), 'Torrent.move'))
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,13 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ module RTransmission
6
+ module VERSION
7
+ MAJOR = 0
8
+ MINOR = 1
9
+
10
+ STRING = [MAJOR, MINOR].join('.')
11
+ end
12
+ end
13
+
@@ -0,0 +1,12 @@
1
+ # Copyright (c) 2011, Andrew Kirilenko <andrew.kirilenko@gmail.com>
2
+ # All rights reserved.
3
+ # Use of this source code is governed by a BSD-style license that can be found in the COPYING file.
4
+
5
+ require 'rtransmission/version'
6
+ require 'rtransmission/exception'
7
+ require 'rtransmission/client'
8
+ require 'rtransmission/request'
9
+ require 'rtransmission/response'
10
+ require 'rtransmission/field'
11
+ require 'rtransmission/fields'
12
+ require 'rtransmission/torrent'
@@ -0,0 +1,15 @@
1
+ require File.expand_path("../lib/rtransmission/version", __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rtransmission"
5
+ s.version = RTransmission::VERSION::STRING
6
+ s.author = "Andrew Kirilenko"
7
+ s.email = "andrew.kirilenko@gmail.com"
8
+ s.homepage = "http://github.com/iced/rtransmission"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "Ruby Transmission Bindings"
11
+ s.description = "RTransmission allows you to interract with Transmission daemon"
12
+ s.files = ["COPYING", "README.md", "rtransmission.gemspec"] + Dir.glob('lib/**/*')
13
+ s.require_path = "lib"
14
+ s.has_rdoc = false
15
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rtransmission
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Kirilenko
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-03 00:00:00 +03:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: RTransmission allows you to interract with Transmission daemon
18
+ email: andrew.kirilenko@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - COPYING
27
+ - README.md
28
+ - rtransmission.gemspec
29
+ - lib/rtransmission/fields.rb
30
+ - lib/rtransmission/client.rb
31
+ - lib/rtransmission/version.rb
32
+ - lib/rtransmission/torrent.rb
33
+ - lib/rtransmission/response.rb
34
+ - lib/rtransmission/exception.rb
35
+ - lib/rtransmission/request.rb
36
+ - lib/rtransmission/fields/eta.rb
37
+ - lib/rtransmission/fields/time.rb
38
+ - lib/rtransmission/fields/tracker_stat.rb
39
+ - lib/rtransmission/fields/error.rb
40
+ - lib/rtransmission/fields/tracker.rb
41
+ - lib/rtransmission/fields/peers_from.rb
42
+ - lib/rtransmission/fields/file_stat.rb
43
+ - lib/rtransmission/fields/percent.rb
44
+ - lib/rtransmission/fields/pieces.rb
45
+ - lib/rtransmission/fields/file.rb
46
+ - lib/rtransmission/fields/status.rb
47
+ - lib/rtransmission/fields/seed_ratio_mode.rb
48
+ - lib/rtransmission/fields/peer.rb
49
+ - lib/rtransmission/fields/priority.rb
50
+ - lib/rtransmission/fields/seed_idle_mode.rb
51
+ - lib/rtransmission/field.rb
52
+ - lib/rtransmission.rb
53
+ has_rdoc: true
54
+ homepage: http://github.com/iced/rtransmission
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.6.2
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Ruby Transmission Bindings
81
+ test_files: []
82
+