p3-transmission 0.0.15

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1d1ab4abe67868f0b5b59fe4c61414efbba6fd51
4
+ data.tar.gz: 644aa09bdc06eaa35b067805aa66286a7e7019bb
5
+ SHA512:
6
+ metadata.gz: cdb1e2f08417ce3892442bea49c9edf21a09501545d4e1c64976e6ada7bb670c49c51e18194c8efd3d4b1d16131d3501a04a9b2de07e13dd9459471d607dc43d
7
+ data.tar.gz: 7affdfac440b4691fe4a31ef248c6eb3f02dee8daf300d45a22cc1c544e37524fcaf1b58d36a2616e9775fbb1776e35a1215f12238c16c6967bb8939a31c06d7
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rvmrc
@@ -0,0 +1 @@
1
+ 2.0.0-p247
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3-p286@transmission_api
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in p3-transmission.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Fernando Guillen
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.
@@ -0,0 +1,35 @@
1
+ # p3-transmission
2
+
3
+ Control Transmission with this API.
4
+
5
+ ## Installation
6
+
7
+ $ gem install p3-transmission
8
+
9
+ ## Usage
10
+
11
+ transmission =
12
+ P3::Transmission::Client.new(
13
+ :username => "username",
14
+ :password => "password",
15
+ :url => "http://127.0.0.1:9091/transmission/rpc"
16
+ )
17
+
18
+ torrents = transmission.all
19
+ torrent = transmission.find(id)
20
+ torrent = transmission.create("http://torrent.com/nice_pic.torrent")
21
+ transmission.remove(id)
22
+
23
+ ## Transmission Api Doc
24
+
25
+ * https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt
26
+
27
+ Supported Transmission Api Version: 2.40
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am "Added some feature"`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require_relative "p3-transmission/version"
2
+ require_relative "p3-transmission/client"
3
+ require_relative "p3-transmission/exception"
4
+
5
+ require "httparty"
6
+ require "json"
7
+
8
+ module P3
9
+ module Transmission
10
+ end
11
+ end
@@ -0,0 +1,233 @@
1
+ module P3
2
+ module Transmission
3
+ class Client
4
+ attr_accessor :session_id
5
+ attr_accessor :url
6
+ attr_accessor :basic_auth
7
+ attr_accessor :fields
8
+ attr_accessor :debug_mode
9
+
10
+ TORRENT_FIELDS = [
11
+ "id",
12
+ "name",
13
+ "totalSize",
14
+ "addedDate",
15
+ "isFinished",
16
+ "rateDownload",
17
+ "rateUpload",
18
+ "percentDone",
19
+ "files",
20
+ "comment",
21
+ "description",
22
+ "downloadDir",
23
+ "doneDate",
24
+ "eta",
25
+ "hashString",
26
+ "leechers",
27
+ "leftUntilDone",
28
+ "name",
29
+ "rateDownload",
30
+ "seeders",
31
+ "seedRatioLimit",
32
+ "sizeWhenDone",
33
+ "status",
34
+ "torrentFile",
35
+ "trackers",
36
+ "uploadLimit",
37
+ "uploadLimited",
38
+ "uploadRatio"
39
+ ]
40
+
41
+ def initialize(opts)
42
+ @url = opts[:url] || "http://#{opts[:host]}:#{opts[:port]}/transmission/rpc"
43
+ @fields = opts[:fields] || TORRENT_FIELDS
44
+ @basic_auth = { :username => opts[:username], :password => opts[:password] } if opts[:username]
45
+ @session_id = "NOT-INITIALIZED"
46
+ @debug_mode = opts[:debug_mode] || false
47
+ end
48
+
49
+ def all
50
+ log "get_torrents"
51
+
52
+ response =
53
+ post(
54
+ :method => "torrent-get",
55
+ :arguments => {
56
+ :fields => fields
57
+ }
58
+ )
59
+
60
+ response["arguments"]["torrents"]
61
+ end
62
+
63
+ def find(id)
64
+ log "get_torrent: #{id}"
65
+
66
+ response =
67
+ post(
68
+ :method => "torrent-get",
69
+ :arguments => {
70
+ :fields => fields,
71
+ :ids => [id]
72
+ }
73
+ )
74
+
75
+ response["arguments"]["torrents"].first
76
+ end
77
+
78
+ def resume(id)
79
+ log "resume_torrent: #{id}"
80
+
81
+ response =
82
+ post(
83
+ :method => "torrent-start",
84
+ :arguments => {
85
+ :ids => [id]
86
+ }
87
+ )
88
+ end
89
+
90
+ def resume_all()
91
+ log "resume_all_torrents"
92
+
93
+ response =
94
+ post(
95
+ :method => "torrent-start",
96
+ )
97
+ end
98
+
99
+ def pause(id)
100
+ log "pause_torrent: #{id}"
101
+
102
+ response =
103
+ post(
104
+ :method => "torrent-stop",
105
+ :arguments => {
106
+ :ids => [id]
107
+ }
108
+ )
109
+ end
110
+
111
+ def pause_all()
112
+ log "pause_all_torrents"
113
+
114
+ response =
115
+ post(
116
+ :method => "torrent-stop",
117
+ )
118
+ end
119
+
120
+ def create(filename)
121
+ log "add_torrent: #{filename}"
122
+
123
+ response =
124
+ post(
125
+ :method => "torrent-add",
126
+ :arguments => {
127
+ :filename => filename
128
+ }
129
+ )
130
+
131
+ response["arguments"]["torrent-added"]
132
+ end
133
+
134
+ #remove the torrent but **keep** the file
135
+ def remove(id)
136
+ log "remove_torrent: #{id}"
137
+
138
+ response =
139
+ post(
140
+ :method => "torrent-remove",
141
+ :arguments => {
142
+ :ids => [id],
143
+ :"delete-local-data" => false
144
+ }
145
+ )
146
+
147
+ response
148
+ end
149
+
150
+ #remove the torrent and **delete** the file
151
+ def destroy(id)
152
+ log "remove_torrent: #{id}"
153
+
154
+ response =
155
+ post(
156
+ :method => "torrent-remove",
157
+ :arguments => {
158
+ :ids => [id],
159
+ :"delete-local-data" => true
160
+ }
161
+ )
162
+
163
+ response
164
+ end
165
+
166
+ def post(opts)
167
+ response_parsed = JSON::parse( http_post(opts).body )
168
+
169
+ if response_parsed["result"] != "success"
170
+ raise Transmission::Exception, response_parsed["result"]
171
+ end
172
+
173
+ response_parsed
174
+ end
175
+
176
+ def http_post(opts)
177
+ post_options = {
178
+ :body => opts.to_json,
179
+ :headers => { "x-transmission-session-id" => session_id }
180
+ }
181
+ post_options.merge!( :basic_auth => basic_auth ) if basic_auth
182
+
183
+ log "url: #{url}"
184
+ log "post_body:"
185
+ log JSON.parse(post_options[:body]).to_yaml
186
+ log "------------------"
187
+
188
+ response = HTTParty.post( url, post_options )
189
+
190
+ log_response response
191
+
192
+ # retry connection if session_id incorrect
193
+ if( response.code == 409 )
194
+ log "changing session_id"
195
+ @session_id = response.headers["x-transmission-session-id"]
196
+ response = http_post(opts)
197
+ end
198
+
199
+ response
200
+ end
201
+
202
+ def log(message)
203
+ Kernel.puts "[P3::Transmission #{Time.now.strftime( "%F %T" )}] #{message}" if debug_mode
204
+ end
205
+
206
+ def log_response(response)
207
+ body = nil
208
+ begin
209
+ body = JSON.parse(response.body).to_yaml
210
+ rescue
211
+ body = response.body
212
+ end
213
+
214
+ headers = response.headers.to_yaml
215
+
216
+ log "response.code: #{response.code}"
217
+ log "response.message: #{response.message}"
218
+
219
+ log "response.body_raw:"
220
+ log response.body
221
+ log "-----------------"
222
+
223
+ log "response.body:"
224
+ log body
225
+ log "-----------------"
226
+
227
+ log "response.headers:"
228
+ log headers
229
+ log "------------------"
230
+ end
231
+ end
232
+ end
233
+ end
@@ -0,0 +1,6 @@
1
+ module P3
2
+ module Transmission
3
+ class Exception < Exception
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module P3
2
+ module Transmission
3
+ VERSION = "0.0.15"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/p3-transmission/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Fernando Guillen", "Poul Hornsleth"]
6
+ gem.email = ["fguillen.mail@gmail.com"]
7
+ gem.description = "Transmission RPC API"
8
+ gem.summary = "Control Trasmission with this API"
9
+ gem.homepage = "https://github.com/poulh/p3-transmission"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "p3-transmission"
15
+ gem.require_paths = ["lib"]
16
+ gem.licenses = "MIT"
17
+ gem.version = P3::Transmission::VERSION
18
+
19
+ gem.add_dependency "httparty", "~> 0.13.7"
20
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: p3-transmission
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.15
5
+ platform: ruby
6
+ authors:
7
+ - Fernando Guillen
8
+ - Poul Hornsleth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.13.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.13.7
28
+ description: Transmission RPC API
29
+ email:
30
+ - fguillen.mail@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - .ruby-version
37
+ - .rvmrc.example
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - lib/p3-transmission.rb
42
+ - lib/p3-transmission/client.rb
43
+ - lib/p3-transmission/exception.rb
44
+ - lib/p3-transmission/version.rb
45
+ - p3-transmission.gemspec
46
+ homepage: https://github.com/poulh/p3-transmission
47
+ licenses:
48
+ - MIT
49
+ metadata: {}
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 2.0.14.1
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Control Trasmission with this API
70
+ test_files: []