trans-api 0.0.1
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 +15 -0
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +334 -0
- data/Rakefile +1 -0
- data/examples/basic_setup.rb +78 -0
- data/examples/torrents/debian-6.0.6-amd64-CD-10.iso.torrent +0 -0
- data/lib/trans-api/client.rb +30 -0
- data/lib/trans-api/connect.rb +331 -0
- data/lib/trans-api/file.rb +56 -0
- data/lib/trans-api/session.rb +83 -0
- data/lib/trans-api/torrent.rb +292 -0
- data/lib/trans-api/version.rb +5 -0
- data/lib/trans-api.rb +12 -0
- data/test/test_helper.rb +8 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-1.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-2.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-3.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-4.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-5.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-6.iso.torrent +0 -0
- data/test/unit/torrents/debian-6.0.6-amd64-CD-7.iso.torrent +0 -0
- data/test/unit/trans_connect.rb +459 -0
- data/test/unit/trans_session_object.rb +82 -0
- data/test/unit/trans_torrent_object.rb +354 -0
- data/trans-api.gemspec +24 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWZiMWExZjAyYjVmNDFiZDY1NTFiMzdlMDM1OGQyNGZkZjQyNTdmYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YmIyZjRkNTM3MWQ3Y2U1MDNjZTQ5Y2I5NWQ0ZTBkZDAyMDk0NjE5Yg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MmRkYTc1ODczMDFlYzJiMGY1ODBlYTk1NjI1MzUwMmRlMGJmNmY5MDQwMzM1
|
10
|
+
ZDI3ZGEwYzg5MjgzMTVlZWQxYWUzNTQ0ZmZjNzg3N2MwOTE1MzE3NTQ0YTA4
|
11
|
+
MzU3NzQ2ZGE1YzQ0ZTkzNDM4NjYzZjk3YWZjY2FiZGIxNWVkZTg=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTJhZTgyZTIwZjBkZGEzZjBkNjc0NzRmYzAzYmEyMWE2ZTQxY2JiMjVjN2Ex
|
14
|
+
OTk1NjRkMzY1YmFiZjJiNmJlMmJmODRiNGVjMmVhZDNmZTg5ODk2ZGEyOTg1
|
15
|
+
ZjE3N2ZlMzRmNDgxM2QwZGRiN2ZiZWNiNzllZGVjMmIwZGM1NDM=
|
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.rbc
|
2
|
+
*.sassc
|
3
|
+
*.swp
|
4
|
+
*.DS_Store
|
5
|
+
.sass-cache
|
6
|
+
capybara-*.html
|
7
|
+
.rspec
|
8
|
+
/.bundle
|
9
|
+
/vendor/bundle
|
10
|
+
/log/*
|
11
|
+
/tmp/*
|
12
|
+
/db/*.sqlite3
|
13
|
+
/public/system/*
|
14
|
+
/coverage/
|
15
|
+
/spec/tmp/*
|
16
|
+
**.orig
|
17
|
+
rerun.txt
|
18
|
+
pickle-email-*.html
|
19
|
+
/pkg/*
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Dennis Blommesteijn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,334 @@
|
|
1
|
+
# Trans::Api
|
2
|
+
|
3
|
+
Trans::Api is an ruby implementation for Transmission RPC. Based on RPC spec 13328
|
4
|
+
https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt
|
5
|
+
|
6
|
+
It required for the Transmission RPC to run the 'remote access':
|
7
|
+
|
8
|
+
OSX:
|
9
|
+
|
10
|
+
Transmission > Preferences > Remote (tab) > Enable remote access
|
11
|
+
|
12
|
+
|
13
|
+
### Platforms
|
14
|
+
|
15
|
+
This gem is (build and) tested with:
|
16
|
+
|
17
|
+
OSX Lion, Mountain Lion
|
18
|
+
|
19
|
+
Ruby 1.9.3
|
20
|
+
|
21
|
+
Rails: 3.2.8, 3.2.9
|
22
|
+
|
23
|
+
Transmission 2.73 (13589)
|
24
|
+
|
25
|
+
|
26
|
+
### Roadmap
|
27
|
+
|
28
|
+
* Version (0.0.1) (current)
|
29
|
+
|
30
|
+
Initial project import.
|
31
|
+
|
32
|
+
* Version (0.0.2)
|
33
|
+
|
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
|
41
|
+
|
42
|
+
|
43
|
+
### Known Issues
|
44
|
+
|
45
|
+
The Transmission RPC call 'torrent-remove' (implemented as torrent.delete! and Torrent::delete_all!) will crash the daemon! This is NOT a known Transmission issue.
|
46
|
+
|
47
|
+
|
48
|
+
## Installation
|
49
|
+
|
50
|
+
Add this line to your application's Gemfile:
|
51
|
+
|
52
|
+
gem 'trans-api', git: "git://github.com/dblommesteijn/trans-api.git"
|
53
|
+
|
54
|
+
And then execute:
|
55
|
+
|
56
|
+
$ bundle
|
57
|
+
|
58
|
+
Or install it yourself as:
|
59
|
+
|
60
|
+
$ gem install trans-api
|
61
|
+
|
62
|
+
|
63
|
+
## Setup
|
64
|
+
|
65
|
+
Define a configuration for your connection (initialize script)
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
|
69
|
+
```
|
70
|
+
|
71
|
+
Setup default configuration (initialize script)
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
Trans::Api::Client.config = CONFIG
|
75
|
+
```
|
76
|
+
|
77
|
+
Define default torrent fields (bulk requests)
|
78
|
+
NOTE: connection is slow when running many torrents with a large amount of fields (transmission rpc issue).
|
79
|
+
On requesting an additional info field from the torrent object, a new call is made to the RPC (and stored
|
80
|
+
withing the object).
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
Trans::Api::Torrent.default_fields = [ :id, :status, :name ]
|
84
|
+
```
|
85
|
+
|
86
|
+
Example
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
Trans::Api::Torrent.default_fields = [ :id, :status, :name ]
|
90
|
+
# loads the torrent object of id 1 with fields: :id, :status, :name
|
91
|
+
id = 1
|
92
|
+
torrent = Trans::Api::Torrent.find id
|
93
|
+
# calls the rpc to receive files from the defined torrent
|
94
|
+
torrent.files
|
95
|
+
```
|
96
|
+
|
97
|
+
## Examples
|
98
|
+
|
99
|
+
Check the examples/ folder or Unit tests: test/unit/trans_ (session/torrent) _object.rb
|
100
|
+
|
101
|
+
|
102
|
+
## Usage
|
103
|
+
|
104
|
+
Trans api can be used in two ways:
|
105
|
+
|
106
|
+
|
107
|
+
1. Connect (raw class)
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
tc = Trans::Api::Connect.new CONFIG
|
111
|
+
torrents = tc.torrent_get([:id, :name, :status])
|
112
|
+
```
|
113
|
+
|
114
|
+
2. Mapped objects (torrent, file, session classes)
|
115
|
+
|
116
|
+
examples below.
|
117
|
+
|
118
|
+
|
119
|
+
### Requesting Torrent Info
|
120
|
+
|
121
|
+
Get all registered torrents
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
Trans::Api::Torrent.all
|
125
|
+
```
|
126
|
+
|
127
|
+
Get a specific torrent by transmission id
|
128
|
+
NOTE: transmission assigns random ids to torrents on daemon start
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
id = 1
|
132
|
+
Trans::Api::Torrent.find id
|
133
|
+
```
|
134
|
+
|
135
|
+
### Torrent static calls
|
136
|
+
|
137
|
+
Start all (start all transfers)
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
Trans::Api::Torrent.start_all
|
141
|
+
```
|
142
|
+
|
143
|
+
Stop all (stop all transfers)
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
Trans::Api::Torrent.stop_all
|
147
|
+
```
|
148
|
+
|
149
|
+
Delete all (tranmission daemon will crash on rapid call)
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
torrents = Trans::Api::Torrent.all
|
153
|
+
# assign explicit torrent objects for removal
|
154
|
+
Trans::Api::Torrent.delete_all torrents
|
155
|
+
```
|
156
|
+
|
157
|
+
Add torrent file
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
options = {paused: true}
|
161
|
+
Trans::Api::Torrent.add_file filename, options
|
162
|
+
```
|
163
|
+
|
164
|
+
Get all fields
|
165
|
+
```ruby
|
166
|
+
Trans::Api::Torrent.ACCESSOR_FIELDS
|
167
|
+
```
|
168
|
+
|
169
|
+
Get all Mutable fields
|
170
|
+
```ruby
|
171
|
+
Trans::Api::Torrent.MUTATOR_FIELDS
|
172
|
+
```
|
173
|
+
|
174
|
+
|
175
|
+
### Torrent instance actions
|
176
|
+
|
177
|
+
Get a torrent object
|
178
|
+
|
179
|
+
```ruby
|
180
|
+
id = 1
|
181
|
+
torrent = Trans::Api::Torrent.find id
|
182
|
+
```
|
183
|
+
|
184
|
+
Save (store changed values)
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
torrent.save!
|
188
|
+
```
|
189
|
+
|
190
|
+
Start (activate torrent for transfer)
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
torrent.start!
|
194
|
+
```
|
195
|
+
|
196
|
+
Start Now (not sure what's the difference to start!, it's a different API call)
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
torrent.start_now!
|
200
|
+
```
|
201
|
+
|
202
|
+
Reset (reload all torrent fields, including later requested ones)
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
torrent.reset!
|
206
|
+
```
|
207
|
+
|
208
|
+
Stop (stop torrent transfer)
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
torrent.stop!
|
212
|
+
```
|
213
|
+
|
214
|
+
File Objects (returns a list of Trans::Api::File objects)
|
215
|
+
|
216
|
+
```ruby
|
217
|
+
torrent.files_objects
|
218
|
+
```
|
219
|
+
|
220
|
+
Status names (get the status name of the torrent)
|
221
|
+
|
222
|
+
```ruby
|
223
|
+
torrent.status_name
|
224
|
+
```
|
225
|
+
|
226
|
+
Verify (recheck downloaded files)
|
227
|
+
|
228
|
+
```ruby
|
229
|
+
torrent.verify!
|
230
|
+
```
|
231
|
+
|
232
|
+
Reannounce Torrent
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
torrent.reannounce!
|
236
|
+
```
|
237
|
+
|
238
|
+
Delete (tranmission daemon will crash on rapid call)
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
options = {delete_local_data: true}
|
242
|
+
torrent.delete! options
|
243
|
+
```
|
244
|
+
|
245
|
+
Waitfor (automatic delayed responce after/before chained method is called)
|
246
|
+
|
247
|
+
Blocking busy waiting for lambda to return true
|
248
|
+
|
249
|
+
```ruby
|
250
|
+
# waitfor status name not equals stopped after calling start!
|
251
|
+
optional = :after
|
252
|
+
torrent.waitfor( lambda{|t| t.status_name != :stopped}, optional ).start!
|
253
|
+
# waitfor status name equals stopped after calling stop!
|
254
|
+
torrent.waitfor( lambda{|t| t.status_name == :stopped}, optional ).stop!
|
255
|
+
# NOTE: waitfor can be used for blocking without a chained method (optional = :before only)
|
256
|
+
```
|
257
|
+
|
258
|
+
NOTE: defined torrent accessor fields are defined as instance methods to the Torrent object
|
259
|
+
|
260
|
+
|
261
|
+
### Session Info
|
262
|
+
|
263
|
+
Get session object (singleton)
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
session = Trans::Api::Session.instance
|
267
|
+
```
|
268
|
+
|
269
|
+
Get available fields (returns symbols of get/set fields)
|
270
|
+
|
271
|
+
```ruby
|
272
|
+
session.fields
|
273
|
+
```
|
274
|
+
|
275
|
+
Get all fields and values
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
session.fields_and_values
|
279
|
+
```
|
280
|
+
|
281
|
+
Reset (reload object, request information and not saving changes)
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
session.reset!
|
285
|
+
```
|
286
|
+
|
287
|
+
NOTE: defined session fields are defined as instance methods to the Session object
|
288
|
+
|
289
|
+
|
290
|
+
### File Info
|
291
|
+
|
292
|
+
Getting files from a torrent (file cannot be used standalone, it's an helper class)
|
293
|
+
|
294
|
+
```ruby
|
295
|
+
id = 1
|
296
|
+
torrent = Trans::Api::Torrent.find id
|
297
|
+
files = torrent.files_objects
|
298
|
+
files.each do |file|
|
299
|
+
# manipulate file here!
|
300
|
+
end
|
301
|
+
```
|
302
|
+
|
303
|
+
File name
|
304
|
+
|
305
|
+
```ruby
|
306
|
+
file.name
|
307
|
+
```
|
308
|
+
|
309
|
+
File mark unwant (mark for ignore, not download)
|
310
|
+
|
311
|
+
```ruby
|
312
|
+
file.unwant
|
313
|
+
```
|
314
|
+
|
315
|
+
File mark want (mark for download)
|
316
|
+
|
317
|
+
```ruby
|
318
|
+
file.want
|
319
|
+
```
|
320
|
+
|
321
|
+
File wanted? (marked for download)
|
322
|
+
|
323
|
+
```ruby
|
324
|
+
file.wanted?
|
325
|
+
```
|
326
|
+
|
327
|
+
File stats
|
328
|
+
|
329
|
+
```ruby
|
330
|
+
file.stat
|
331
|
+
```
|
332
|
+
|
333
|
+
NOTE: changed preferences (want, unwant) set options on the linked Torrent object, after saving torrent (torrent.save!) file mutations are stored.
|
334
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,78 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# setup
|
4
|
+
require 'rubygems'
|
5
|
+
require "bundler/setup"
|
6
|
+
require 'trans-api'
|
7
|
+
|
8
|
+
|
9
|
+
class BasicSetup
|
10
|
+
|
11
|
+
include Trans::Api
|
12
|
+
|
13
|
+
CONFIG = { host: "localhost", port: 9091, user: "admin", pass: "admin", path: "/transmission/rpc" }
|
14
|
+
FIELDS = [ :id, :status, :name ]
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
|
18
|
+
# connection information (rpc location)
|
19
|
+
Client.config = CONFIG
|
20
|
+
|
21
|
+
# default loading torrent fields
|
22
|
+
Torrent.default_fields = FIELDS
|
23
|
+
|
24
|
+
#TODO: add a section for session here!!
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def add_torrent
|
30
|
+
|
31
|
+
# selecting a file to add (debian demo file)
|
32
|
+
file = ::File.expand_path(::File.dirname(__FILE__) + "/torrents/debian-6.0.6-amd64-CD-10.iso.torrent")
|
33
|
+
|
34
|
+
# adding a torrent using static call on Torrent object (paused transfer)
|
35
|
+
@torrent = Torrent.add_file file, paused: true
|
36
|
+
# return variable is an instance of the torrent file
|
37
|
+
# an exception can be raised on invalid request
|
38
|
+
|
39
|
+
# NOTE: we will store it for later use (removing this torrent, not the whole list)
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_torrent
|
44
|
+
|
45
|
+
#TODO: remove torrent here!
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
def iterating_torrents
|
50
|
+
|
51
|
+
torrents = Torrent.all
|
52
|
+
|
53
|
+
torrents.each do |torrent|
|
54
|
+
|
55
|
+
puts "#{torrent.name} -> #{torrent.status_name}"
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
# initiate BasicSetup object, and run its methods
|
66
|
+
begin
|
67
|
+
|
68
|
+
bs = BasicSetup.new
|
69
|
+
bs.add_torrent
|
70
|
+
bs.iterating_torrents
|
71
|
+
|
72
|
+
rescue Exception => e
|
73
|
+
puts e
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
Binary file
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Trans
|
2
|
+
module Api
|
3
|
+
|
4
|
+
class Client
|
5
|
+
DEFAULT = {scheme: "http", host: "localhost", port: 9091, path: "/transmission/rpc", user: "admin", pass: "admin"}
|
6
|
+
|
7
|
+
# construct
|
8
|
+
|
9
|
+
def initialize(options={})
|
10
|
+
args = @@config
|
11
|
+
args.merge!(options)
|
12
|
+
@conn = Connect.new args
|
13
|
+
end
|
14
|
+
|
15
|
+
def connect
|
16
|
+
@conn
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def config=(config = {})
|
21
|
+
@@config = config
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|