transmissionr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1a773a770f20da65adea95c7e77eaa21f230d98b
4
+ data.tar.gz: 41fc6ec9b4b1b5f9311148f0c4c6187630023548
5
+ SHA512:
6
+ metadata.gz: 4f2d0c84b7d867807a9f3a511bf9675c33ca7608e7ce70ca71328d2b2242be3e9691126d8022768bc7caaf087bd6fac4419bddb6fdf20bef0dac63b5985cb24b
7
+ data.tar.gz: b58ef30bbba8520a23ac7e12b14842ad733af209ff478f265c4465879dc7b0f27344c96e862c51ce8742982996750b371e5158abdd07b04e02cbb9efe591b696
data/.gitignore ADDED
@@ -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
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in transmissionr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Joe Lanford
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,29 @@
1
+ # Transmissionr
2
+
3
+ Ruby client for Transmission RPC
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'transmissionr'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install transmissionr
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ require "httparty"
2
+ require "json"
3
+ require "mash"
4
+
5
+ require "transmissionr/version"
6
+ require "transmissionr/client"
7
+
8
+ require "transmissionr/base_method"
9
+ require "transmissionr/torrent_get"
10
+ require "transmissionr/torrent_set"
11
+ require "transmissionr/torrent_add"
12
+ require "transmissionr/torrent_remove"
13
+ require "transmissionr/torrent_stop"
14
+ require "transmissionr/torrent_start"
15
+ require "transmissionr/torrent_start_now"
16
+ require "transmissionr/torrent_verify"
17
+ require "transmissionr/torrent_reannounce"
18
+
19
+ module Transmissionr
20
+ end
@@ -0,0 +1,21 @@
1
+ module Transmission
2
+ class BaseMethod
3
+ def initialize( client )
4
+ @client = client
5
+ end
6
+
7
+ def request
8
+ request = {
9
+ method: @method,
10
+ arguments: @arguments
11
+ }
12
+ response = @client.class.post(@client.base_uri, basic_auth: @client.auth, headers: @client.headers, body: request.to_json )
13
+ if response.code == 409
14
+ @client.headers["x-transmission-session-id"] = response.headers["x-transmission-session-id"]
15
+ response = @client.class.post(@client.base_uri, basic_auth: @client.auth, headers: @client.headers, body: request.to_json )
16
+ end
17
+ raise ResponseError.new(response) if response.code != 200
18
+ Mash.new(response)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,53 @@
1
+ module Transmission
2
+ class Client
3
+ include HTTParty
4
+
5
+ attr_reader :base_uri, :auth, :headers
6
+
7
+ def initialize( host = "localhost", port = 9091, username = nil, password = nil )
8
+ @base_uri = "http://#{host}:#{port}/transmission/rpc"
9
+ @auth = { username: username, password: password }
10
+ @headers = { "x-transmission-session-id" => "" }
11
+ end
12
+
13
+ def session_id
14
+ @headers["x-transmission-session-id"]
15
+ end
16
+
17
+ def torrent_start( ids = nil )
18
+ TorrentStart.new( self, ids ).request
19
+ end
20
+
21
+ def torrent_start_now( ids = nil )
22
+ TorrentStartNow.new( self, ids ).request
23
+ end
24
+
25
+ def torrent_stop( ids = nil )
26
+ TorrentStop.new( self, ids ).request
27
+ end
28
+
29
+ def torrent_verify( ids = nil )
30
+ TorrentVerify.new( self, ids ).request
31
+ end
32
+
33
+ def torrent_reannounce( ids = nil )
34
+ TorrentReannounce.new( self, ids ).request
35
+ end
36
+
37
+ def torrent_set( arguments = {}, ids = nil )
38
+ TorrentSet.new( self, arguments, ids ).request
39
+ end
40
+
41
+ def torrent_get( fields = nil, ids = nil )
42
+ TorrentGet.new( self, fields, ids ).request
43
+ end
44
+
45
+ def torrent_add( arguments = {} )
46
+ TorrentAdd.new( self, arguments ).request
47
+ end
48
+
49
+ def torrent_remove( delete = false, ids = nil )
50
+ TorrentRemove.new( self, delete, ids ).request
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module Transmission
2
+ class TorrentAdd < BaseMethod
3
+ def initialize( client, arguments )
4
+ super(client)
5
+ @method = 'torrent-add'
6
+ @arguments = arguments
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,83 @@
1
+ module Transmission
2
+ class TorrentGet < BaseMethod
3
+ def initialize( client, fields = nil, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-get'
6
+ @arguments = {}
7
+
8
+ @arguments["fields"] = fields ? fields : @@fields
9
+ @arguments["ids"] = ids if ids != nil
10
+ end
11
+
12
+ @@fields = %w(
13
+ activityDate
14
+ addedDate
15
+ bandwidthPriority
16
+ comment
17
+ corruptEver
18
+ creator
19
+ dateCreated
20
+ desiredAvailable
21
+ doneDate
22
+ downloadDir
23
+ downloadedEver
24
+ downloadLimit
25
+ downloadLimited
26
+ error
27
+ errorString
28
+ eta
29
+ etaIdle
30
+ files
31
+ fileStats
32
+ hashString
33
+ haveUnchecked
34
+ haveValid
35
+ honorsSessionLimits
36
+ id
37
+ isFinished
38
+ isPrivate
39
+ isStalled
40
+ leftUntilDone
41
+ magnetLink
42
+ manualAnnounceTime
43
+ maxConnectedPeers
44
+ metadataPercentComplete
45
+ name
46
+ peer-limit
47
+ peers
48
+ peersConnected
49
+ peersFrom
50
+ peersGettingFromUs
51
+ peersSendingToUs
52
+ percentDone
53
+ pieces
54
+ pieceCount
55
+ pieceSize
56
+ priorities
57
+ queuePosition
58
+ rateDownload
59
+ rateUpload
60
+ recheckProgress
61
+ secondsDownloading
62
+ secondsSeeding
63
+ seedIdleLimit
64
+ seedIdleMode
65
+ seedRatioLimit
66
+ seedRatioMode
67
+ sizeWhenDone
68
+ startDate
69
+ status
70
+ trackers
71
+ trackerStats
72
+ totalSize
73
+ torrentFile
74
+ uploadedEver
75
+ uploadLimit
76
+ uploadLimited
77
+ uploadRatio
78
+ wanted
79
+ webseeds
80
+ webseedsSendingToUs
81
+ )
82
+ end
83
+ end
@@ -0,0 +1,10 @@
1
+ module Transmission
2
+ class TorrentReannounce < BaseMethod
3
+ def initialize( client, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-reannounce'
6
+ @arguments = {}
7
+ @arguments["ids"] = ids if ids != nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ module Transmission
2
+ class TorrentRemove < BaseMethod
3
+ def initialize( client, delete = false, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-remove'
6
+ @arguments = {
7
+ "delete-local-data" => delete
8
+ }
9
+ @arguments["ids"] = ids if ids != nil
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module Transmission
2
+ class TorrentSet < BaseMethod
3
+ def initialize( client, arguments = {}, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-set'
6
+ @arguments = arguments
7
+
8
+ @arguments["ids"] = ids if ids != nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module Transmission
2
+ class TorrentStart < BaseMethod
3
+ def initialize( client, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-start'
6
+ @arguments = {}
7
+ @arguments["ids"] = ids if ids != nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Transmission
2
+ class TorrentStartNow < BaseMethod
3
+ def initialize( client, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-start-now'
6
+ @arguments = {}
7
+ @arguments["ids"] = ids if ids != nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Transmission
2
+ class TorrentStop < BaseMethod
3
+ def initialize( client, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-stop'
6
+ @arguments = {}
7
+ @arguments["ids"] = ids if ids != nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Transmission
2
+ class TorrentVerify < BaseMethod
3
+ def initialize( client, ids = nil )
4
+ super(client)
5
+ @method = 'torrent-verify'
6
+ @arguments = {}
7
+ @arguments["ids"] = ids if ids != nil
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Transmissionr
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ root File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ add_filter "/spec/"
5
+ end
6
+
7
+ require 'transmissionr'
8
+
9
+ HOST = 'torrent'
10
+ PORT = 9091
11
+ USERNAME = 'torrent'
12
+ PASSWORD = 'torrent100'
13
+
14
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ # config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'default'
25
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transmission::Client do
4
+
5
+ before :all do
6
+ @t = Transmission::Client.new(HOST, PORT, USERNAME, PASSWORD)
7
+ @magnet_link = "magnet:?xt=urn:btih:F36C92A8F78A1AFF70A61A5F5BFE5E6757176133&dn=ubuntu+12+10+desktop+amd64&tr=udp%3A%2F%2Ffr33domtracker.h33t.com%3A3310%2Fannounce&tr=udp%3A%2F%2Fopen.demonii.com%3A1337"
8
+ @hashString = "F36C92A8F78A1AFF70A61A5F5BFE5E6757176133"
9
+ end
10
+
11
+ it 'should add torrent' do
12
+ response = @t.torrent_add( :filename => @magnet_link )
13
+ expect(response.result).to eql("success")
14
+ end
15
+
16
+ it 'should get torrents' do
17
+ response = @t.torrent_get( nil, @hashString )
18
+ expect(response.result).to eql("success")
19
+ expect(response.arguments.length).to eql(1)
20
+ end
21
+
22
+ it 'should stop torrent' do
23
+ response = @t.torrent_stop( @hashString )
24
+ expect(response.result).to eql("success")
25
+ end
26
+
27
+ it 'should start torrent not now' do
28
+ response = @t.torrent_start( @hashString )
29
+ expect(response.result).to eql("success")
30
+ end
31
+
32
+ it 'should start torrent now' do
33
+ response = @t.torrent_start_now( @hashString )
34
+ expect(response.result).to eql("success")
35
+ end
36
+
37
+ it 'should verify torrent' do
38
+ response = @t.torrent_verify( @hashString )
39
+ expect(response.result).to eql("success")
40
+ end
41
+
42
+ it 'should reannounce torrent' do
43
+ response = @t.torrent_reannounce( @hashString )
44
+ expect(response.result).to eql("success")
45
+ end
46
+
47
+ it 'should set torrent attributes' do
48
+ response = @t.torrent_set( { :downloadLimit => 10 }, @hashString )
49
+ expect(response.result).to eql("success")
50
+ end
51
+
52
+ it 'should remove torrent' do
53
+ response = @t.torrent_remove( true, @hashString )
54
+ expect(response.result).to eql("success")
55
+ end
56
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'transmissionr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "transmissionr"
8
+ spec.version = Transmissionr::VERSION
9
+ spec.authors = ["Joe Lanford"]
10
+ spec.email = ["joe.lanford@gmail.com"]
11
+ spec.description = %q{Ruby client for Transmission RPC}
12
+ spec.summary = %q{Ruby client for Transmission RPC}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transmissionr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe Lanford
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ description: Ruby client for Transmission RPC
56
+ email:
57
+ - joe.lanford@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/transmissionr.rb
68
+ - lib/transmissionr/base_method.rb
69
+ - lib/transmissionr/client.rb
70
+ - lib/transmissionr/torrent_add.rb
71
+ - lib/transmissionr/torrent_get.rb
72
+ - lib/transmissionr/torrent_reannounce.rb
73
+ - lib/transmissionr/torrent_remove.rb
74
+ - lib/transmissionr/torrent_set.rb
75
+ - lib/transmissionr/torrent_start.rb
76
+ - lib/transmissionr/torrent_start_now.rb
77
+ - lib/transmissionr/torrent_stop.rb
78
+ - lib/transmissionr/torrent_verify.rb
79
+ - lib/transmissionr/version.rb
80
+ - spec/spec_helper.rb
81
+ - spec/transmission_spec.rb
82
+ - transmissionr.gemspec
83
+ homepage: ''
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.1.1
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Ruby client for Transmission RPC
107
+ test_files:
108
+ - spec/spec_helper.rb
109
+ - spec/transmission_spec.rb