transmission-client 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ transmission-client.gemspec
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dominik Sander
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,28 @@
1
+ # transmission-client: A Transmission RPC Client
2
+
3
+ The goal is to support all requests described in the Transmission [RPC Specifications](http://trac.transmissionbt.com/browser/trunk/doc/rpc-spec.txt).
4
+
5
+ ## Installing
6
+ You need to have http://gemcutter.org in you gem sources. To add it you can execute either
7
+
8
+ sudo gem install gemcutter
9
+ sudo gem tumble`
10
+
11
+ or
12
+
13
+ sudo gem source -a http://gemcutter.org
14
+
15
+ To install transmission-client:
16
+
17
+ sudo gem install transmission-client
18
+
19
+ ## Usage
20
+ Get a list of torrents and print its file names:
21
+
22
+ require 'transmission-client'
23
+ t = Transmission::Client.new('192.168.0.2')
24
+ t.torrents.each do |torrent|
25
+ puts torrent.name
26
+ end
27
+
28
+ RDoc is still to be written, at the meantime have a look at the code to find out which methods are supported.
data/README.rdoc ADDED
@@ -0,0 +1,28 @@
1
+ # tranmission-client: A Transmission RPC Client
2
+
3
+ The goal is to support all requests described in the Transmission [RPC Specifications](http://trac.transmissionbt.com/browser/trunk/doc/rpc-spec.txt).
4
+
5
+ ## Installing
6
+ You need to have http://gemcutter.org in you gem sources. To add it you can execute either
7
+
8
+ sudo gem install gemcutter
9
+ sudo gem tumble`
10
+
11
+ or
12
+
13
+ sudo gem source -a http://gemcutter.org
14
+
15
+ To install transmission-client:
16
+
17
+ sudo gem install transmission-client
18
+
19
+ ## Usage
20
+ Get a list of torrents and print its file names:
21
+
22
+ require 'transmission-client'
23
+ t = Transmission::Client.new('192.168.0.2')
24
+ t.torrents.each do |torrent|
25
+ puts torrent.name
26
+ end
27
+
28
+ RDoc is still to be written, at the meantime have a look at the code to find out which methods are supported.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "transmission-client"
8
+ gem.summary = %Q{A Transmission RPC Client}
9
+ #gem.description = %Q{}
10
+ gem.email = "git@dsander.de"
11
+ gem.homepage = "http://github.com/dsander/transmission-client"
12
+ gem.authors = ["Dominik Sander"]
13
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
+ gem.files += Dir['lib/**/*.rb','README.markdown']
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "transmission-rpc #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,11 @@
1
+ require 'net/http'
2
+ require 'singleton'
3
+ require 'json'
4
+
5
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ require 'transmission-client/client'
8
+ require 'transmission-client/connection'
9
+ require 'transmission-client/torrent'
10
+ require 'transmission-client/session'
11
+
@@ -0,0 +1,58 @@
1
+ module Transmission
2
+ class Client
3
+ def initialize(host='localhost',port=9091)
4
+ Connection.instance.init(host, port)
5
+ end
6
+
7
+ def start_all
8
+ Connection.instance.send('torrent-start')
9
+ end
10
+
11
+ def start(id)
12
+ Connection.instance.send('torrent-start', {'ids' => id.class == Array ? id : [id]})
13
+ end
14
+
15
+ def stop(id)
16
+ Connection.instance.send('torrent-stop', {'ids' => id.class == Array ? id : [id]})
17
+ end
18
+
19
+ def stop_all
20
+ Connection.instance.send('torrent-stop')
21
+ end
22
+
23
+ def remove(id, delete_data = false)
24
+ Connection.instance.send('torrent-remove', {'ids' => id.class == Array ? id : [id], 'delete-local-data' => delete_data })
25
+ end
26
+
27
+ def remove_all(delete_data = false)
28
+ Connection.instance.send('torrent-remove', {'delete-local-data' => delete_data })
29
+ end
30
+
31
+ def add_torrent(a)
32
+ if a['filename'].nil? && a['metainfo'].nil?
33
+ raise "You need to provide either a 'filename' or 'metainfo'."
34
+ end
35
+ Connection.instance.send('torrent-add', a)
36
+ end
37
+
38
+ def add_torrent_by_file(filename)
39
+ add_torrent({'filename' => filename})
40
+ end
41
+
42
+ def add_torrent_by_data(data)
43
+ add_torrent({'metainfo' => data})
44
+ end
45
+
46
+ def session
47
+ Session.new Connection.instance.request('session-get')
48
+ end
49
+
50
+ def torrents(fields = nil)
51
+ torrs = []
52
+ Connection.instance.request('torrent-get', {'fields' => fields ? fields : Transmission::Torrent::ATTRIBUTES})['torrents'].each do |t|
53
+ torrs << Torrent.new(t)
54
+ end
55
+ torrs
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,42 @@
1
+ module Transmission
2
+ class Connection
3
+ include Singleton
4
+
5
+ def init(host, port)
6
+ @host = host
7
+ @port = port
8
+ uri = URI.parse("http://#{@host}:#{@port}")
9
+ @conn = Net::HTTP.start(uri.host, uri.port)
10
+ @header = {}
11
+ end
12
+
13
+ def request(method, attributes={})
14
+ res = @conn.post('/transmission/rpc',build_json(method,attributes),@header)
15
+ if res.class == Net::HTTPConflict && @header['x-transmission-session-id'].nil?
16
+ @header['x-transmission-session-id'] = res['x-transmission-session-id']
17
+ request(method,attributes)
18
+ elsif res.class == Net::HTTPOK
19
+ resp = JSON.parse(res.body)
20
+ if resp["result"] == 'success'
21
+ #pp resp
22
+ resp['arguments']
23
+ else
24
+ resp
25
+ end
26
+ end
27
+ end
28
+
29
+ def send(method, attributes={})
30
+ request(method, attributes)['result'].nil?
31
+ end
32
+
33
+ def build_json(method,attributes = {})
34
+ if attributes.length == 0
35
+ {'method' => method}.to_json
36
+ else
37
+ {'method' => method, 'arguments' => attributes }.to_json
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,22 @@
1
+ module Transmission
2
+ class Session
3
+ ATTRIBUTES = ['alt-speed-down', 'alt-speed-enabled', 'alt-speed-time-begin', 'alt-speed-time-enabled', 'alt-speed-time-end', 'alt-speed-time-day', 'alt-speed-up', 'blocklist-enabled', 'blocklist-size', 'download-dir', 'dht-enabled', 'encryption', 'incomplete-dir', 'incomplete-dir-enabled', 'peer-limit-global', 'peer-limit-per-torrent', 'pex-enabled', 'peer-port', 'peer-port-random-on-start', 'port-forwarding-enabled', 'rpc-version', 'rpc-version-minimum', 'seedRatioLimit', 'seedRatioLimited', 'speed-limit-down', 'speed-limit-down-enabled', 'speed-limit-up', 'speed-limit-up-enabled', 'version']
4
+ def initialize(attributes)
5
+ @attributes = attributes
6
+ end
7
+
8
+ def method_missing(m, *args, &block)
9
+ m = m.to_s.gsub('_','-')
10
+ if ATTRIBUTES.include? m
11
+ return @attributes[m]
12
+ elsif m[-1..-1] == '='
13
+ if ["blocklist-size","rpc-version", "rpc-version-minimum", "version"].include? m[0..-2]
14
+ raise "Invalid Attribute."
15
+ end
16
+ return Connection.instance.send('session-set', {m[0..-2] => args.first})
17
+ else
18
+ raise "Invalid Attribute."
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,48 @@
1
+ module Transmission
2
+ class Torrent
3
+ ATTRIBUTES = ['activityDate', 'addedDate', 'bandwidthPriority', 'comment', 'corruptEver', 'creator', 'dateCreated', 'desiredAvailable', 'doneDate', 'downloadDir', 'downloadedEver', 'downloadLimit', 'downloadLimited', 'error', 'errorString', 'eta', 'hashString', 'haveUnchecked', 'haveValid', 'honorsSessionLimits', 'id', 'isPrivate', 'leftUntilDone', 'manualAnnounceTime', 'maxConnectedPeers', 'name', 'peer-limit', 'peersConnected', 'peersGettingFromUs', 'peersKnown', 'peersSendingToUs', 'percentDone', 'pieces', 'pieceCount', 'pieceSize', 'rateDownload', 'rateUpload', 'recheckProgress', 'seedRatioLimit', 'seedRatioMode', 'sizeWhenDone', 'startDate', 'status', 'swarmSpeed', 'totalSize', 'torrentFile', 'uploadedEver', 'uploadLimit', 'uploadLimited', 'uploadRatio', 'webseedsSendingToUs']
4
+ ADV_ATTRIBUTES = ['files', 'fileStats', 'peers', 'peersFrom', 'priorities', 'trackers', 'trackerStats', 'wanted', 'webseeds']
5
+ SETABLE_ATTRIBUTES = ['bandwidthPriority', 'downloadLimit', 'downloadLimited', 'files-wanted', 'files-unwanted', 'honorsSessionLimits', 'ids', 'location', 'peer-limit', 'priority-high', 'priority-low', 'priority-normal', 'seedRatioLimit', 'seedRatioMode', 'uploadLimit', 'uploadLimited']
6
+
7
+ def initialize(attributes)
8
+ @attributes = attributes
9
+ end
10
+
11
+ def start
12
+ Connection.instance.send('torrent-start', {'ids' => @attributes['id']})
13
+ end
14
+
15
+ def stop
16
+ Connection.instance.send('torrent-stop', {'ids' => @attributes['id']})
17
+ end
18
+
19
+ def verify
20
+ Connection.instance.send('torrent-verify', {'ids' => @attributes['id']})
21
+ end
22
+
23
+ def reannounce
24
+ Connection.instance.send('torrent-reannounce', {'ids' => @attributes['id']})
25
+ end
26
+
27
+ def remove(delete_data = false)
28
+ Connection.instance.send('torrent-remove', {'ids' => @attributes['id'], 'delete-local-data' => delete_data })
29
+ end
30
+
31
+ def method_missing(m, *args, &block)
32
+ pp m
33
+ if ATTRIBUTES.include? m.to_s
34
+ return @attributes[m.to_s]
35
+ elsif ADV_ATTRIBUTES.include? m.to_s
36
+ raise "Attribute not yet supported."
37
+ elsif m[-1..-1] == '='
38
+ if SETABLE_ATTRIBUTES.include? m[0..-2]
39
+ Connection.instance.send('torrent-set', {'ids' => [@attributes['id']], m[0..-2] => args.first})
40
+ else
41
+ raise "Invalid Attribute."
42
+ end
43
+ else
44
+ raise "Invalid Attribute."
45
+ end
46
+ end
47
+ end # end class
48
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'transmission-rpc'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestTransmissionRpc < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transmission-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Sander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-23 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thoughtbot-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: git@dsander.de
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.markdown
34
+ - README.rdoc
35
+ files:
36
+ - .document
37
+ - .gitignore
38
+ - LICENSE
39
+ - README.markdown
40
+ - README.rdoc
41
+ - Rakefile
42
+ - VERSION
43
+ - lib/transmission-client.rb
44
+ - lib/transmission-client/client.rb
45
+ - lib/transmission-client/connection.rb
46
+ - lib/transmission-client/session.rb
47
+ - lib/transmission-client/torrent.rb
48
+ - test/helper.rb
49
+ - test/test_transmission-rpc.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/dsander/transmission-client
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ requirements: []
72
+
73
+ rubyforge_project:
74
+ rubygems_version: 1.3.5
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: A Transmission RPC Client
78
+ test_files:
79
+ - test/test_transmission-rpc.rb
80
+ - test/helper.rb