transmission-conn 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/transmission.rb +42 -0
- data/config/transmission.yml +4 -0
- data/lib/transmission-connect.rb +7 -0
- data/lib/transmission-connect/client.rb +88 -0
- data/lib/transmission-connect/configuration.rb +108 -0
- data/lib/transmission-connect/server.rb +27 -0
- data/test/helper.rb +18 -0
- data/test/test_client.rb +90 -0
- data/test/test_transmission-connect.rb +7 -0
- data/transmission-conn.gemspec +77 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWJhYWIwMzFlMDYwYzBkYzI3MzQzNDIzZGQwYzQ4NzYwMmE5OWRiMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjY2M2ZkYTUyYWUyNTI0N2MwMGM4ODY2MmMwYWI2MzkyNGNlNzA1ZQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzgxMTM1NTUyNmRiMmYwYWU3YzYyZjY5ZGUxZTZmMjE2NWY5NTIwODJmZGY2
|
10
|
+
MDc0MWM1ZmFjOGRiZWY1ZTg5MWZjZDY0MzRlZTAxNDVhMWFiMjgwZjE0MDBh
|
11
|
+
ZTQwZDViYTdhMGM1ZTE1ZTIxY2JlYWUwOWYzODdlMmFmN2U0ODI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODJjMDg2NzVkNjg5ZTE1ZGI1ZDQyM2Y0OTZjNjg2ZWZhZmM3Zjk0N2NjNmEw
|
14
|
+
NGFiYjVhMDYxZDRiMGIyNTZlMjQzMjM4NzIwNTE4ZWM0OWEyN2MxMjZjZmU0
|
15
|
+
Njg2MDVjMDViMGNkNzcwODkwMjc4NThjOGY2YjM0NzBjMWJmOTk=
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'json'
|
7
|
+
gem 'transmission-client', '>=0.0.9', :git => "git://github.com/Daem0n/transmission-client.git"
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "shoulda", ">= 0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
GIT
|
2
|
+
remote: git://github.com/Daem0n/transmission-client.git
|
3
|
+
revision: 40d8b71df596f0a527633a2a5e9a2e6a34239e68
|
4
|
+
specs:
|
5
|
+
transmission-client (0.0.9)
|
6
|
+
em-http-request
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.2.5)
|
12
|
+
em-http-request (0.3.0)
|
13
|
+
addressable (>= 2.0.0)
|
14
|
+
escape_utils
|
15
|
+
eventmachine (>= 0.12.9)
|
16
|
+
escape_utils (0.2.3)
|
17
|
+
eventmachine (0.12.10)
|
18
|
+
git (1.2.5)
|
19
|
+
jeweler (1.5.2)
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
git (>= 1.2.5)
|
22
|
+
rake
|
23
|
+
json (1.5.1)
|
24
|
+
rake (0.8.7)
|
25
|
+
rcov (0.9.9)
|
26
|
+
shoulda (2.11.3)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.0.0)
|
33
|
+
jeweler (~> 1.5.2)
|
34
|
+
json
|
35
|
+
rcov
|
36
|
+
shoulda
|
37
|
+
transmission-client (>= 0.0.9)!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Dmitry Brazhkin
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= transmission-connect
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to transmission-connect
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Dmitry Brazhkin. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "transmission-connect"
|
16
|
+
gem.homepage = "http://github.com/Daem0n/transmission-connect"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Simple connector to transmission bittorrent client}
|
19
|
+
gem.description = %Q{Simple connector to transmission bittorrent client by HTTP-RPC}
|
20
|
+
gem.email = "dbrazhkin@gmail.com"
|
21
|
+
gem.authors = ["Dmitry Brazhkin"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "transmission-connect #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.4
|
data/bin/transmission.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'yaml'
|
5
|
+
require 'transmission-client'
|
6
|
+
require 'lib/transmission-connect'
|
7
|
+
|
8
|
+
CONFIG = "config/transmission.yml"
|
9
|
+
@exit = false
|
10
|
+
|
11
|
+
trap("INT") do
|
12
|
+
EventMachine::stop_event_loop
|
13
|
+
@exit = true
|
14
|
+
end
|
15
|
+
|
16
|
+
trap("TERM") do
|
17
|
+
EventMachine::stop_event_loop
|
18
|
+
@exit = true
|
19
|
+
end
|
20
|
+
|
21
|
+
while !@exit
|
22
|
+
begin
|
23
|
+
EventMachine.run do
|
24
|
+
transmission = Configuration.new(YAML.load_file(CONFIG))
|
25
|
+
transmission.each do |client|
|
26
|
+
EM.add_periodic_timer(client.interval) do
|
27
|
+
client.report
|
28
|
+
end
|
29
|
+
end
|
30
|
+
EM.add_periodic_timer(2) do
|
31
|
+
transmission.each do |client|
|
32
|
+
client.session_stats
|
33
|
+
end
|
34
|
+
end
|
35
|
+
EventMachine::start_server "127.0.0.1", 2456, TransmissionServer do |server|
|
36
|
+
server.connectors = transmission
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Exception => e
|
40
|
+
puts "Error: #{e.message}"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Transmission
|
2
|
+
RPC_PATH = 'transmission/rpc'
|
3
|
+
|
4
|
+
class Client
|
5
|
+
SESSION_STAT_ARGS = %w(activeTorrentCount downloadSpeed pausedTorrentCount torrentCount uploadSpeed cumulative-stats current-stats)
|
6
|
+
TORRENT_ARGS = %w(downloadDir hashString id isFinished name percentDone status totalSize error errorString rateDownload rateUpload)
|
7
|
+
CHECK_WAIT = 1
|
8
|
+
CHECK = 2
|
9
|
+
DOWNLOAD = 4
|
10
|
+
SEED = 8
|
11
|
+
STOPPED = 16
|
12
|
+
STATUS = {
|
13
|
+
1 => :check_wait,
|
14
|
+
2 => :check,
|
15
|
+
4 => :download,
|
16
|
+
8 => :seed,
|
17
|
+
16 => :stopped
|
18
|
+
}
|
19
|
+
|
20
|
+
def initialize(host = '127.0.0.1', port = 9091, username = nil, password = nil)
|
21
|
+
@header = username.nil? ? {} : {'Authorization' => Base64.encode64("#{username}:#{password}")}
|
22
|
+
@uri = URI.parse("http://#{host}:#{port}/#{RPC_PATH}")
|
23
|
+
new_connection
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_connection
|
27
|
+
@connection = Net::HTTP.start(@uri.host, @uri.port)
|
28
|
+
end
|
29
|
+
|
30
|
+
def session_stats(args = {})
|
31
|
+
request('session-stats', args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_bt_magnet(hash)
|
35
|
+
hash = "magnet:?xt=urn:btih:#{hash}"
|
36
|
+
request('torrent-add', {:filename => hash})
|
37
|
+
end
|
38
|
+
|
39
|
+
def rem_bt_magnet(hash)
|
40
|
+
request('torrent-remove', {:ids => hash.to_a, 'delete-local-data' => true})
|
41
|
+
end
|
42
|
+
|
43
|
+
def pause_magnet(hash)
|
44
|
+
request('torrent-stop', {:ids => hash.to_a})
|
45
|
+
end
|
46
|
+
|
47
|
+
def unpause_magnet(hash)
|
48
|
+
request('torrent-start', {:ids => hash.to_a})
|
49
|
+
end
|
50
|
+
|
51
|
+
def get_info(hash = nil)
|
52
|
+
args = hash.nil? ? {} : {:ids => hash.to_a}
|
53
|
+
args = {:fields => TORRENT_ARGS}.merge(args)
|
54
|
+
request('torrent-get', args)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def request(method, args)
|
59
|
+
post_data = build_json method, args
|
60
|
+
begin
|
61
|
+
result = @connection.post2(@uri.path, post_data, @header)
|
62
|
+
rescue
|
63
|
+
new_connection
|
64
|
+
return request method, args
|
65
|
+
end
|
66
|
+
case result
|
67
|
+
when Net::HTTPSuccess
|
68
|
+
JSON.parse(result.read_body)['arguments']
|
69
|
+
when Net::HTTPConflict
|
70
|
+
@header = @header.merge("x-transmission-session-id" => result.header["x-transmission-session-id"])
|
71
|
+
request(method, args)
|
72
|
+
when Net::HTTPBadResponse
|
73
|
+
request(method, args)
|
74
|
+
else
|
75
|
+
raise Exception
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def build_json(method,attributes = {})
|
80
|
+
if attributes.length == 0
|
81
|
+
{'method' => method}.to_json
|
82
|
+
else
|
83
|
+
{'method' => method, 'arguments' => attributes }.to_json
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
class Configuration
|
2
|
+
include Enumerable
|
3
|
+
|
4
|
+
## def initialize(args)
|
5
|
+
## args - array of hashes:
|
6
|
+
# args = [
|
7
|
+
# {
|
8
|
+
# :host => '127.0.0.1',
|
9
|
+
# :port => 9091,
|
10
|
+
# :down => true
|
11
|
+
# },
|
12
|
+
# {
|
13
|
+
# :host => '127.0.0.1',
|
14
|
+
# :port => 9092,
|
15
|
+
# :up => true
|
16
|
+
# },
|
17
|
+
# {
|
18
|
+
# :host => '192.168.100.199',
|
19
|
+
# :port => 9091,
|
20
|
+
# :username => 'username',
|
21
|
+
# :password => 'password',
|
22
|
+
# :down => true,
|
23
|
+
# :up => true
|
24
|
+
# }
|
25
|
+
# ]
|
26
|
+
def initialize(args = [])
|
27
|
+
@clients = []
|
28
|
+
@downs = []
|
29
|
+
@ups = []
|
30
|
+
args.each do |arg|
|
31
|
+
client = Client.new(arg)
|
32
|
+
@clients << client
|
33
|
+
@downs << client if arg.key?(:down) && arg[:down]
|
34
|
+
@ups << client if arg.key?(:up) && arg[:up]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def each
|
39
|
+
@clients.each{|i| yield i}
|
40
|
+
end
|
41
|
+
|
42
|
+
def each_ups
|
43
|
+
@ups.each{|i| yield i}
|
44
|
+
end
|
45
|
+
|
46
|
+
def each_downs
|
47
|
+
@downs.each{|i| yield i}
|
48
|
+
end
|
49
|
+
|
50
|
+
class Client
|
51
|
+
# HOST = 'http://127.0.0.1:3000'
|
52
|
+
HOST = 'http://peerlize.hitlan.ru'
|
53
|
+
FIELDS = ['downloadDir', 'error', 'errorString', 'eta', 'hashString', 'id', 'name', 'peersConnected', 'peersKnown', 'peersSendingToUs', 'percentDone', 'rateDownload', 'rateUpload', 'recheckProgress', 'startDate', 'status', 'totalSize', 'torrentFile']
|
54
|
+
attr_reader :interval, :host, :port, :transmission
|
55
|
+
attr_accessor :peer_port, :download_dir
|
56
|
+
def initialize(args)
|
57
|
+
@host = args.delete(:host) || '127.0.0.1'
|
58
|
+
@port = args.delete(:port) || 9091
|
59
|
+
@username = args[:username]
|
60
|
+
@password = args[:password]
|
61
|
+
@interval = args.delete(:interval) || 5
|
62
|
+
@up = args.delete(:up) || false
|
63
|
+
@down = args.delete(:down) || false
|
64
|
+
@transmission = Transmission::Client.new(@host, @port, @username, @password)
|
65
|
+
@transmission.session do |session|
|
66
|
+
self.peer_port = session.peer_port
|
67
|
+
self.download_dir = session.download_dir
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def report
|
72
|
+
@transmission.torrents(FIELDS) do |torrents|
|
73
|
+
result = {:client => options}
|
74
|
+
torrents.each do |torrent|
|
75
|
+
result[torrent.hashString.to_sym] = torrent.attributes
|
76
|
+
end
|
77
|
+
EM::HttpRequest.new("#{HOST}/transmission/").post :body => {:torrents => result.to_json}
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def session_stats
|
82
|
+
@transmission.session_stat do |ss|
|
83
|
+
result = ss.attributes.merge(:client => options)
|
84
|
+
EM::HttpRequest.new("#{HOST}/transmission/stat").post :body => {:session_stat => result.to_json}
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def up?
|
89
|
+
@up
|
90
|
+
end
|
91
|
+
|
92
|
+
def down?
|
93
|
+
@down
|
94
|
+
end
|
95
|
+
|
96
|
+
def options
|
97
|
+
@options ||= {
|
98
|
+
:port => peer_port,
|
99
|
+
:up => up?,
|
100
|
+
:down => down?,
|
101
|
+
:download_dir => download_dir,
|
102
|
+
:host => @host
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TransmissionServer
|
2
|
+
attr_accessor :connectors
|
3
|
+
|
4
|
+
def receive_data data
|
5
|
+
query = JSON.parse(data)
|
6
|
+
case query['command']
|
7
|
+
when 'add'
|
8
|
+
respond = 'Add: ' + query['uri']
|
9
|
+
target = query['client']
|
10
|
+
## Add magnet link to download client
|
11
|
+
session = @connectors.find{|client| client.host == target['host'] and client.peer_port == target['port']}
|
12
|
+
if session
|
13
|
+
session.transmission.add_torrent_by_file(query['uri'])
|
14
|
+
session.transmission.add_tracker(query['hash'], 'http://retracker.local/announce') if query['hash']
|
15
|
+
end
|
16
|
+
when 'move'
|
17
|
+
respond = 'move'
|
18
|
+
## Move torrent from download to upload client
|
19
|
+
else
|
20
|
+
respond = 'Illegal operation'
|
21
|
+
end
|
22
|
+
puts respond
|
23
|
+
send_data respond
|
24
|
+
close_connection_after_writing
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'transmission-connect'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
data/test/test_client.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestClient < Test::Unit::TestCase
|
4
|
+
context "a transmission client" do
|
5
|
+
setup do
|
6
|
+
@uri = URI.parse("http://127.0.0.1:9091/transmission/rpc")
|
7
|
+
@connect = Transmission::Client.new
|
8
|
+
@hash = '562e7e6eb0852a652f329f5e8518385c5762fa84'
|
9
|
+
@hash = @hash.upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
should "have connection" do
|
13
|
+
assert_instance_of Transmission::Client, @connect
|
14
|
+
end
|
15
|
+
|
16
|
+
should "get common info" do
|
17
|
+
assert_instance_of Hash, @connect.session_stats
|
18
|
+
end
|
19
|
+
|
20
|
+
should "get all torrents info" do
|
21
|
+
result = @connect.get_info
|
22
|
+
assert_instance_of Hash, result
|
23
|
+
assert_not_nil result['torrents']
|
24
|
+
assert_instance_of Array, result['torrents']
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with torrent' do
|
28
|
+
setup do
|
29
|
+
@arg_count = Transmission::Client::TORRENT_ARGS.count
|
30
|
+
end
|
31
|
+
|
32
|
+
should "add magnet link to downloads" do
|
33
|
+
@count = @connect.session_stats["torrentCount"]
|
34
|
+
result = @connect.add_bt_magnet(@hash)
|
35
|
+
count = @connect.session_stats["torrentCount"]
|
36
|
+
assert_equal @count + 1, count
|
37
|
+
assert_equal @hash.upcase, result['torrent-added']['hashString'].upcase
|
38
|
+
@connect.rem_bt_magnet(@hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'get info about all' do
|
42
|
+
@count = @connect.session_stats["torrentCount"]
|
43
|
+
result = @connect.get_info
|
44
|
+
assert_instance_of Hash, result
|
45
|
+
assert_equal @count, result['torrents'].count
|
46
|
+
result['torrents'].each do |torrent|
|
47
|
+
assert_equal @arg_count, torrent.keys.count
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
should "remove by magnet link" do
|
52
|
+
@connect.add_bt_magnet(@hash)
|
53
|
+
@count = @connect.session_stats["torrentCount"]
|
54
|
+
result = @connect.rem_bt_magnet(@hash)
|
55
|
+
assert_equal @count - 1, @connect.session_stats["torrentCount"]
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'get info by hash' do
|
59
|
+
@connect.add_bt_magnet(@hash)
|
60
|
+
result = @connect.get_info(@hash)
|
61
|
+
assert_instance_of Hash, result
|
62
|
+
assert_equal 1, result['torrents'].count
|
63
|
+
assert_equal @arg_count, result['torrents'].first.keys.count
|
64
|
+
@connect.rem_bt_magnet(@hash)
|
65
|
+
end
|
66
|
+
|
67
|
+
should 'pause torrent' do
|
68
|
+
@connect.add_bt_magnet(@hash)
|
69
|
+
@connect.pause_magnet(@hash)
|
70
|
+
sleep 1
|
71
|
+
result = @connect.get_info(@hash)
|
72
|
+
assert_equal Transmission::Client::STOPPED, result['torrents'].first['status']
|
73
|
+
@connect.rem_bt_magnet(@hash)
|
74
|
+
end
|
75
|
+
|
76
|
+
should 'unpause torrent' do
|
77
|
+
@connect.add_bt_magnet(@hash)
|
78
|
+
@connect.pause_magnet(@hash)
|
79
|
+
sleep 1
|
80
|
+
@connect.unpause_magnet(@hash)
|
81
|
+
sleep 4
|
82
|
+
result = @connect.get_info(@hash)
|
83
|
+
assert_not_equal Transmission::Client::STOPPED, result['torrents'].first['status']
|
84
|
+
@connect.rem_bt_magnet(@hash)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{transmission-conn}
|
8
|
+
s.version = "0.3.4"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ritik Malhotra"]
|
12
|
+
s.date = %q{2013-06-10}
|
13
|
+
s.description = %q{Simple connector to transmission bittorrent client by HTTP-RPC}
|
14
|
+
s.email = %q{ritikmalhotra@gmail.com}
|
15
|
+
s.executables = ["transmission.rb"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/transmission.rb",
|
29
|
+
"config/transmission.yml",
|
30
|
+
"lib/transmission-connect.rb",
|
31
|
+
"lib/transmission-connect/client.rb",
|
32
|
+
"lib/transmission-connect/configuration.rb",
|
33
|
+
"lib/transmission-connect/server.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_client.rb",
|
36
|
+
"test/test_transmission-connect.rb",
|
37
|
+
"transmission-conn.gemspec"
|
38
|
+
]
|
39
|
+
s.homepage = %q{https://github.com/ritikm/transmission-connect}
|
40
|
+
s.licenses = ["MIT"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.7.2}
|
43
|
+
s.summary = %q{Simple connector to transmission bittorrent client}
|
44
|
+
s.test_files = [
|
45
|
+
"test/helper.rb",
|
46
|
+
"test/test_client.rb",
|
47
|
+
"test/test_transmission-connect.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<transmission-client>, [">= 0.0.5"])
|
56
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
59
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<json>, [">= 0"])
|
62
|
+
s.add_dependency(%q<transmission-client>, [">= 0.0.5"])
|
63
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<json>, [">= 0"])
|
70
|
+
s.add_dependency(%q<transmission-client>, [">= 0.0.5"])
|
71
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
72
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
73
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
74
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transmission-conn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ritik Malhotra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: transmission-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: shoulda
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.5.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.5.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rcov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Simple connector to transmission bittorrent client by HTTP-RPC
|
98
|
+
email: ritikmalhotra@gmail.com
|
99
|
+
executables:
|
100
|
+
- transmission.rb
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.rdoc
|
105
|
+
files:
|
106
|
+
- .document
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.rdoc
|
111
|
+
- Rakefile
|
112
|
+
- VERSION
|
113
|
+
- bin/transmission.rb
|
114
|
+
- config/transmission.yml
|
115
|
+
- lib/transmission-connect.rb
|
116
|
+
- lib/transmission-connect/client.rb
|
117
|
+
- lib/transmission-connect/configuration.rb
|
118
|
+
- lib/transmission-connect/server.rb
|
119
|
+
- test/helper.rb
|
120
|
+
- test/test_client.rb
|
121
|
+
- test/test_transmission-connect.rb
|
122
|
+
- transmission-conn.gemspec
|
123
|
+
homepage: https://github.com/ritikm/transmission-connect
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.0.3
|
144
|
+
signing_key:
|
145
|
+
specification_version: 3
|
146
|
+
summary: Simple connector to transmission bittorrent client
|
147
|
+
test_files:
|
148
|
+
- test/helper.rb
|
149
|
+
- test/test_client.rb
|
150
|
+
- test/test_transmission-connect.rb
|