trans-api 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4750d6488dcb9805c0bbd635509b4cc2b82f664e
4
- data.tar.gz: 112eebe82c5696c795c38d311047cb6bc154d396
3
+ metadata.gz: 1d01cbf84b3889d9915b90cafc5d77f2616568f3
4
+ data.tar.gz: 82999c9a1f31862aedfb2e7f08202bb6bf916502
5
5
  SHA512:
6
- metadata.gz: 2d6928aee4bdebfe1272677a7b88dbe56df591922aeaf38d175d5c109fbd8b149a7519259d8322e202223319601a61a0d82d73084becf8126019b45af12acea5
7
- data.tar.gz: 6baef1393173ee402a8487bf7656702c399d39f0b490047ad306a4807546c28561ef23810ab49bd90316ffbe6bafb3132cd12eac69b787d6766ec3ade5b00a21
6
+ metadata.gz: f9e138a46699147e1afbf586d1fdc78a467f3e5c7ddcbbbf8421d6151b0e36bed7754a2c990ae16ec61b996dc972f2b41cdda694bff36db2d1ed501f05baef8d
7
+ data.tar.gz: 648590c449721d663b85003c779f83abbcdde2b1c72dc606b5875bcc02282cb3715aeb66126cdcb128349e541d17859a5b4aeea987123f89de3331af9072b849
data/.gitignore CHANGED
@@ -17,4 +17,6 @@ capybara-*.html
17
17
  rerun.txt
18
18
  pickle-email-*.html
19
19
  /pkg/*
20
+ .vagrant/machines/*
20
21
 
22
+ .coveralls.yml
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.0
5
+ - jruby-19mode
6
+ - ruby-head
7
+ - jruby-head
8
+ jdk:
9
+ - oraclejdk7
10
+ before_install:
11
+ - gem update --system
12
+ - gem --version
@@ -0,0 +1,70 @@
1
+ {
2
+ "alt-speed-down": 50,
3
+ "alt-speed-enabled": false,
4
+ "alt-speed-time-begin": 540,
5
+ "alt-speed-time-day": 127,
6
+ "alt-speed-time-enabled": false,
7
+ "alt-speed-time-end": 1020,
8
+ "alt-speed-up": 50,
9
+ "bind-address-ipv4": "0.0.0.0",
10
+ "bind-address-ipv6": "::",
11
+ "blocklist-enabled": false,
12
+ "blocklist-url": "http://www.example.com/blocklist",
13
+ "cache-size-mb": 4,
14
+ "dht-enabled": true,
15
+ "download-dir": "/home/vagrant/downloads/",
16
+ "download-limit": 100,
17
+ "download-limit-enabled": 0,
18
+ "download-queue-enabled": true,
19
+ "download-queue-size": 5,
20
+ "encryption": 2,
21
+ "idle-seeding-limit": 30,
22
+ "idle-seeding-limit-enabled": false,
23
+ "incomplete-dir": "/root/Downloads",
24
+ "incomplete-dir-enabled": false,
25
+ "lpd-enabled": false,
26
+ "max-peers-global": 200,
27
+ "message-level": 2,
28
+ "peer-congestion-algorithm": "",
29
+ "peer-limit-global": 240,
30
+ "peer-limit-per-torrent": 60,
31
+ "peer-port": 51413,
32
+ "peer-port-random-high": 65535,
33
+ "peer-port-random-low": 49152,
34
+ "peer-port-random-on-start": false,
35
+ "peer-socket-tos": "default",
36
+ "pex-enabled": true,
37
+ "port-forwarding-enabled": false,
38
+ "preallocation": 1,
39
+ "prefetch-enabled": 1,
40
+ "queue-stalled-enabled": true,
41
+ "queue-stalled-minutes": 30,
42
+ "ratio-limit": 2,
43
+ "ratio-limit-enabled": false,
44
+ "rename-partial-files": true,
45
+ "rpc-authentication-required": true,
46
+ "rpc-bind-address": "0.0.0.0",
47
+ "rpc-enabled": true,
48
+ "rpc-password": "{f95980ad4f56d462b8c27311d7091373b3fdcbc8jwb6VOkY",
49
+ "rpc-port": 9091,
50
+ "rpc-url": "/transmission/",
51
+ "rpc-username": "admin",
52
+ "rpc-whitelist": "*",
53
+ "rpc-whitelist-enabled": true,
54
+ "scrape-paused-torrents-enabled": true,
55
+ "script-torrent-done-enabled": false,
56
+ "script-torrent-done-filename": "",
57
+ "seed-queue-enabled": false,
58
+ "seed-queue-size": 10,
59
+ "speed-limit-down": 100,
60
+ "speed-limit-down-enabled": false,
61
+ "speed-limit-up": 100,
62
+ "speed-limit-up-enabled": false,
63
+ "start-added-torrents": true,
64
+ "trash-original-torrent-files": false,
65
+ "umask": 18,
66
+ "upload-limit": 100,
67
+ "upload-limit-enabled": 0,
68
+ "upload-slots-per-torrent": 14,
69
+ "utp-enabled": true
70
+ }
@@ -0,0 +1,34 @@
1
+ echo "======================================================="
2
+ echo " Updating Apt... "
3
+ echo "======================================================="
4
+ sudo DEBIAN_FRONTEND=noninteractive apt-get -q -y -o Dpkg::Options::="--force-confdef" update
5
+
6
+ echo "======================================================="
7
+ echo " Installing Dependencies... "
8
+ echo "======================================================="
9
+ sudo DEBIAN_FRONTEND=noninteractive apt-get -q -y -o Dpkg::Options::="--force-confdef" install transmission-cli transmission-common transmission-daemon
10
+
11
+ echo "======================================================="
12
+ echo " Configuring... "
13
+ echo "======================================================="
14
+ # ruby /vagrant/.vagrant/bootstrap/testing.rb
15
+
16
+ # prepare paths
17
+ sudo mkdir -p /home/vagrant/downloads/
18
+ sudo chmod -R 777 /home/vagrant/downloads/
19
+ # register daemon
20
+ sudo update-rc.d transmission-daemon defaults
21
+ # push config and restart
22
+ sudo service transmission-daemon stop
23
+ sudo cp /vagrant/.vagrant/bootstrap/settings.json /var/lib/transmission-daemon/info/settings.json
24
+ sudo chown debian-transmission /var/lib/transmission-daemon/info/settings.json
25
+ sudo service transmission-daemon start
26
+
27
+ echo "======================================================="
28
+ echo " VM is up and running!"
29
+ echo " ---------------------"
30
+ echo " Running service at: http://localhost:19091 (tunneled)"
31
+ echo " - You can now start testing!"
32
+ echo " $ CONFIG=\"{\\\"host\\\":\\\"localhost\\\",\\\"port\\\":\\\"19091\\\",\\\"user\\\":\\\"admin\\\",\\\"pass\\\":\\\"adm1n\\\",\\\"path\\\":\\\"/transmission/rpc\\\"}\" ruby -I test test/unit/trans_connect.rb"
33
+ echo "======================================================="
34
+
data/Gemfile.lock CHANGED
@@ -1,26 +1,52 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trans-api (0.0.3)
4
+ trans-api (0.0.4)
5
5
  json (> 1.6.1)
6
6
  nokogiri (> 1.5.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
+ coveralls (0.7.1)
12
+ multi_json (~> 1.3)
13
+ rest-client
14
+ simplecov (>= 0.7)
15
+ term-ansicolor
16
+ thor
17
+ docile (1.1.5)
11
18
  json (1.8.1)
12
19
  json (1.8.1-java)
13
- mini_portile (0.5.2)
14
- nokogiri (1.6.1)
15
- mini_portile (~> 0.5.0)
16
- nokogiri (1.6.1-java)
17
- mini_portile (~> 0.5.0)
18
- test-unit (2.5.2)
20
+ mime-types (2.3)
21
+ mini_portile (0.6.0)
22
+ multi_json (1.10.1)
23
+ netrc (0.7.7)
24
+ nokogiri (1.6.3.1)
25
+ mini_portile (= 0.6.0)
26
+ nokogiri (1.6.3.1-java)
27
+ power_assert (0.1.3)
28
+ rake (10.3.2)
29
+ rest-client (1.7.2)
30
+ mime-types (>= 1.16, < 3.0)
31
+ netrc (~> 0.7)
32
+ simplecov (0.9.1)
33
+ docile (~> 1.1.0)
34
+ multi_json (~> 1.0)
35
+ simplecov-html (~> 0.8.0)
36
+ simplecov-html (0.8.0)
37
+ term-ansicolor (1.3.0)
38
+ tins (~> 1.0)
39
+ test-unit (3.0.1)
40
+ power_assert
41
+ thor (0.19.1)
42
+ tins (1.3.3)
19
43
 
20
44
  PLATFORMS
21
45
  java
22
46
  ruby
23
47
 
24
48
  DEPENDENCIES
25
- test-unit (> 2.0.0)
49
+ coveralls (> 0.7.0)
50
+ rake (> 10.0.0)
51
+ test-unit (> 3.0.0)
26
52
  trans-api!
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  Trans::Api is an ruby implementation for Transmission RPC (bittorrent client). Based on RPC spec 13328
4
4
  https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt
5
5
 
6
+ [![Build Status](https://travis-ci.org/dblommesteijn/trans-api.svg?branch=master)](https://travis-ci.org/dblommesteijn/trans-api) [![Coverage Status](https://coveralls.io/repos/dblommesteijn/trans-api/badge.png)](https://coveralls.io/r/dblommesteijn/trans-api) [![Code Climate](https://codeclimate.com/github/dblommesteijn/trans-api.png)](https://codeclimate.com/github/dblommesteijn/trans-api) [![Dependency Status](https://gemnasium.com/dblommesteijn/trans-api.svg)](https://gemnasium.com/dblommesteijn/trans-api)
7
+
6
8
  It required for the Transmission RPC to run the 'remote access':
7
9
 
8
10
  OSX:
@@ -14,55 +16,53 @@ OSX:
14
16
 
15
17
  This gem is (build and) tested with:
16
18
 
17
- OSX Lion, Mountain Lion, Mavericks
18
-
19
- Ruby 1.9.3, 2.1.0
20
-
21
- Rails: 3.2.8, 3.2.9, 4.0.3
22
-
23
- Transmission 2.73 (13589) - 2.82 (14160)
19
+ * OSX: Lion, Mountain Lion, Mavericks
20
+ * Ruby: 1.9.3, 2.1.0
21
+ * Rails: 3.2.8, 3.2.9, 4.0.3
22
+ * Transmission 2.73 (13589) - 2.82 (14160)
24
23
 
25
24
 
26
25
  ### Roadmap
27
26
 
28
27
  * Version (0.0.1)
29
28
 
30
- Initial project import.
29
+ * Initial project import.
31
30
 
32
31
  * Version (0.0.2)
33
32
 
34
- Session object include: 'blocklist', 'port-test'
35
-
36
- Torrent object include 'torrent-start-now', 'queue-move-top/up/down/bottom'
37
-
38
- Torrent object 'delete_all!' explicit torrent references
39
-
40
- Torrent object 'waitfor' helper to check for lambda after/before calling it's chained cousin
33
+ * Session object include: 'blocklist', 'port-test'
34
+ * Torrent object include 'torrent-start-now', 'queue-move-top/up/down/bottom'
35
+ * Torrent object 'delete_all!' explicit torrent references
36
+ * Torrent object 'waitfor' helper to check for lambda after/before calling it's chained cousin
41
37
 
42
38
  * Version (0.0.3)
43
39
 
44
- Querying name before add (duplicate detect), not hammering torrent-add (due to a transmission BUG)
45
-
46
- Added some File internal fields (total and completed transfer)
40
+ * Querying name before add (duplicate detect), not hammering torrent-add (due to a transmission BUG)
41
+ * Added some File internal fields (total and completed transfer)
47
42
 
48
43
  * Version (0.0.4)
49
44
 
50
- Added Session.alt_speed_time_day_options, returns a list of values to set `alt_speed_time_day`
45
+ * Added Session.alt_speed_time_day_options, returns a list of values to set `alt_speed_time_day`
46
+ * Added Session.reload!, that reconnects to the client (for example using alternate configs)
47
+ * Added Session.update_blocklist!, updating the current set blocklist
48
+
49
+ * Version (0.0.5)
51
50
 
52
- Added Session.reload!, that reconnects to the client (for example using alternate configs)
51
+ * Added Session.connected?, checks if there is a valid connection to the client
52
+ * Fixed Torrent.waitfor chained method arguements
53
+ * Added magnet support
53
54
 
54
- Added Session.update_blocklist!, updating the current set blocklist
55
+ * Version (0.0.6)
55
56
 
57
+ * TBA
56
58
 
57
- ### Changelog
59
+
60
+ ### Changelog (call changes)
58
61
 
59
62
  * Version (0.0.3)
60
-
61
- Torrent.add_metainfo(base64, filename, options={}) -> requires a filename parameter
62
63
 
63
- * Version (0.0.4)
64
+ * Torrent.add_metainfo(base64, filename, options={}) -> requires a filename parameter
64
65
 
65
- TBA
66
66
 
67
67
  ### Known Issues
68
68
 
@@ -70,6 +70,8 @@ The Transmission RPC call 'torrent-remove' (implemented as torrent.delete! and T
70
70
 
71
71
  Due to a Transmission bug (https://trac.transmissionbt.com/ticket/5614) duplicate torrents are accepted by the RPC call. The GUI will eventually crash the daemon, when interacting with these duplicate files (or instances). Torrent.add_file/ add_metainfo queries for duplicates to omit this bug.
72
72
 
73
+ On rapid RPC calls the client will ignore the request, and respond with successfull. For example rapid Torrent.delete! will respond with status successfull, but it remains active. You can use a blocked call via waitfor (chained) to make sure the action was completed.
74
+
73
75
 
74
76
  ## Installation
75
77
 
@@ -82,7 +84,7 @@ And then execute:
82
84
  $ bundle
83
85
 
84
86
 
85
- ## Setup
87
+ ## Configuration
86
88
 
87
89
  Define a configuration for your connection (initialize script)
88
90
 
@@ -116,10 +118,6 @@ torrent = Trans::Api::Torrent.find id
116
118
  torrent.files
117
119
  ```
118
120
 
119
- ## Examples
120
-
121
- Check the examples/ folder or Unit tests: test/unit/trans_ (session/torrent) _object.rb
122
-
123
121
 
124
122
  ## Usage
125
123
 
@@ -194,6 +192,13 @@ base64_file_contents = Base64.encode64 file.read
194
192
  Trans::Api::Torrent.add_metainfo base64_file_contents, file_name, options
195
193
  ```
196
194
 
195
+ Add magnet URI
196
+
197
+ ```ruby
198
+ magnet_link = "magnet:?xt=urn:btih:42ae58b8f59bd19fe97d6ca6fd884b2e9666a4d1&dn=debian-6.0.6-amd64-CD-2.iso&tr=http%3A%2F%2Fbttracker.debian.org%3A6969%2Fannounce"
199
+ torrent = Trans::Api::Torrent.add_magnet(magnet_link, paused: true)
200
+ ```
201
+
197
202
  Get all fields
198
203
  ```ruby
199
204
  Trans::Api::Torrent.ACCESSOR_FIELDS
@@ -271,8 +276,7 @@ torrent.reannounce!
271
276
  Delete (tranmission daemon will crash on rapid call)
272
277
 
273
278
  ```ruby
274
- options = {delete_local_data: true}
275
- torrent.delete! options
279
+ torrent.delete! {delete_local_data: true}
276
280
  ```
277
281
 
278
282
  Waitfor (automatic delayed responce after/before chained method is called)
@@ -283,9 +287,13 @@ Waitfor (automatic delayed responce after/before chained method is called)
283
287
  # waitfor status name not equals stopped after calling start!
284
288
  optional = :after
285
289
  torrent.waitfor( lambda{|t| t.status_name != :stopped}, optional ).start!
290
+
286
291
  # waitfor status name equals stopped after calling stop!
287
292
  torrent.waitfor( lambda{|t| t.status_name == :stopped}, optional ).stop!
288
293
  # NOTE: waitfor can be used for blocking without a chained method (optional = :before only)
294
+
295
+ # via the Torrent object `reset_exception` we can verify if the torrent is probably removed
296
+ torrent.waitfor(lambda{|t| t.last_error[:error] == "reset_exception"}).delete!(delete_local_data: true)
289
297
  ```
290
298
 
291
299
  NOTE: defined torrent accessor fields are defined as instance methods to the Torrent object
@@ -332,7 +340,7 @@ session.blocklist_url = "http://list.iblocklist.com/?list=bt_level3&fileformat=p
332
340
  session.blocklist_enable = true
333
341
  # save changes
334
342
  session.save!
335
- # force update
343
+ # force update
336
344
  begin
337
345
  session.update_blocklist!
338
346
  rescue Exception => e
@@ -350,10 +358,11 @@ Getting files from a torrent (file cannot be used standalone, it's an helper cla
350
358
  ```ruby
351
359
  id = 1
352
360
  torrent = Trans::Api::Torrent.find id
353
- files = torrent.files_objects
354
- files.each do |file|
355
- # manipulate file here!
361
+ torrent.files_objects.each do |file|
362
+ # manipulate or stat the file here! (unwant, want)
356
363
  end
364
+ # save the torrent (internal changes to files_objects are saved as well)
365
+ torrent.save!
357
366
  ```
358
367
 
359
368
  File name
@@ -380,7 +389,7 @@ File wanted? (marked for download)
380
389
  file.wanted?
381
390
  ```
382
391
 
383
- File stats
392
+ File stat
384
393
 
385
394
  ```ruby
386
395
  file.stat
@@ -390,4 +399,78 @@ NOTE: changed preferences (want, unwant) set options on the linked Torrent objec
390
399
 
391
400
 
392
401
 
402
+ ## Running Tests
403
+
404
+ Run the unittest embedded with the project from the commandline. Configure the CONFIG variable with an escaped json to provide configuration for your transmission client.
405
+
406
+ * WARNING: torrents and files will be destroyed by these tests *
407
+
408
+
409
+ ```bash
410
+ # example format: define CONFIG in escaped json
411
+ $ CONFIG="{\"host\":\"localhost\",\"port\":1234,\"user\":\"youruser\",\"pass\":\"yourpass\",\"path\":\"/transmission/rpc\"}"
412
+ ```
413
+
414
+ Run 'test/unit/trans_connect.rb' to test the intermediate layer between the RPC API and wrappers.
415
+
416
+ ```bash
417
+ $ CONFIG="{\"host\":\"localhost\",\"port\":1234,\"user\":\"youruser\",\"pass\":\"yourpass\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_connect.rb
418
+ ```
419
+
420
+ Run 'test/unit/trans_session_object.rb' to test the working of Trans::Api::Session.
421
+
422
+ ```bash
423
+ # run unit test session
424
+ $ CONFIG="{\"host\":\"localhost\",\"port\":1234,\"user\":\"youruser\",\"pass\":\"yourpass\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_session_object.rb
425
+ ```
426
+
427
+ Run 'test/unit/trans_torrent_object.rb' to test the working of Trans::Api::Torrent.
428
+
429
+ ```bash
430
+ # run unit test session
431
+ $ CONFIG="{\"host\":\"localhost\",\"port\":1234,\"user\":\"youruser\",\"pass\":\"yourpass\",\"path\":\"/transmission/rpc\"}" ruby -I test test/unit/trans_torrent_object.rb
432
+ ```
433
+
434
+ NOTE: test `test_torrent_rapid_delete` will fail because of an issue with rapid calling.
435
+
436
+
437
+ ### Vagrant
438
+
439
+ Besides running your existing client with Transmission you can test on an isolated virtual machine via Vagrant.
440
+
441
+ **Download Dependencies**
442
+
443
+ Download and follow the installation instructions.
444
+
445
+ * Vagrant: http://www.vagrantup.com/downloads.html
446
+ * VirtualBox: https://www.virtualbox.org/wiki/Downloads
447
+
448
+
449
+ ##### Boot the Test VM
450
+
451
+ Download and run the testing Debian Linux distribution with a test Transmission client.
452
+
453
+ ```bash
454
+ $ cd /location/of/trans-api
455
+ # download and start a testing box (will take some time)
456
+ $ vagrant up testing
457
+ ```
458
+
459
+ **Configure the CONFIG variable to target the VM**
460
+
461
+ ```bash
462
+ # use this CONFIG string to connect to the testing instance
463
+ $ CONFIG="{\"host\":\"localhost\",\"port\":19091,\"user\":\"admin\",\"pass\":\"adm1n\",\"path\":\"/transmission/rpc\"}"
464
+ # run tests like described above
465
+ ```
466
+
467
+ *NOTE: don't forget to HALT (and DESTROY) the VM when done!*
468
+
469
+ ```bash
470
+ # power down VM
471
+ $ vagrant halt testing
472
+ # power down and destroy files
473
+ $ vagrant destroy testing
474
+ ```
475
+
393
476
 
data/Rakefile CHANGED
@@ -1 +1,15 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ tfs = FileList['test/unit/*.rb']
7
+ t.test_files = tfs
8
+ t.verbose = true
9
+ end
10
+
11
+ require 'coveralls/rake/task'
12
+ Coveralls::RakeTask.new
13
+
14
+ task test_with_coveralls: ['test', 'coveralls:push']
15
+ task default: [:build, :install]
data/Vagrantfile ADDED
@@ -0,0 +1,18 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # vagrant config
5
+ Vagrant.configure("2") do |config|
6
+
7
+ # testing configuration
8
+ config.vm.define "testing" do |testing|
9
+ testing.vm.box = "chef/debian-7.4"
10
+ testing.vm.provision :shell, path: ".vagrant/bootstrap/testing.sh"
11
+ testing.vm.network :forwarded_port, guest: 9091, host: 19091
12
+ testing.vm.network :private_network, ip: "10.1.1.2"
13
+ testing.vm.provider :virtualbox do |vb|
14
+ vb.customize ["modifyvm", :id, "--memory", "256"]
15
+ end
16
+ end
17
+
18
+ end
@@ -2,12 +2,13 @@ module Trans
2
2
  module Api
3
3
 
4
4
  class Client
5
- DEFAULT = {scheme: "http", host: "localhost", port: 9091, path: "/transmission/rpc", user: "admin", pass: "admin"}
5
+ DEFAULT = {scheme: "http", host: "localhost", port: 9091, path: "/transmission/rpc", user: "admin", pass: "admin", timeout: 5}
6
6
 
7
7
  # construct
8
8
 
9
9
  def initialize(options={})
10
- args = @@config
10
+ # @@config ||= {}
11
+ args = @@config || {}
11
12
  args.merge!(options)
12
13
  @conn = Connect.new args
13
14
  end
@@ -19,6 +20,11 @@ module Trans
19
20
  class << self
20
21
  def config=(config = {})
21
22
  config[:port] = config[:port].to_i if config.include? :port
23
+ if config.include? :timeout
24
+ config[:timeout] = config[:timeout].to_i
25
+ else
26
+ config[:timeout] = DEFAULT[:timeout]
27
+ end
22
28
  @@config = config
23
29
  end
24
30
  end