transmission-rpc-ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +37 -0
- data/LICENSE +19 -0
- data/README.md +78 -0
- data/Rakefile +3 -0
- data/lib/transmission.rb +8 -0
- data/lib/transmission/arguments.rb +27 -0
- data/lib/transmission/arguments/session_get.rb +63 -0
- data/lib/transmission/arguments/session_set.rb +58 -0
- data/lib/transmission/arguments/session_stats.rb +17 -0
- data/lib/transmission/arguments/torrent_add.rb +22 -0
- data/lib/transmission/arguments/torrent_get.rb +78 -0
- data/lib/transmission/arguments/torrent_set.rb +34 -0
- data/lib/transmission/config.rb +18 -0
- data/lib/transmission/model.rb +8 -0
- data/lib/transmission/model/session.rb +35 -0
- data/lib/transmission/model/torrent.rb +97 -0
- data/lib/transmission/rpc.rb +108 -0
- data/lib/transmission/rpc/connector.rb +69 -0
- data/spec/helpers/stubs.rb +60 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/transmission/arguments_spec.rb +34 -0
- data/spec/transmission/model/torrent_spec.rb +146 -0
- data/spec/transmission/rpc/connector_spec.rb +81 -0
- data/spec/transmission/rpc_spec.rb +41 -0
- data/transmission-rpc-ruby.gemspec +17 -0
- metadata +128 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
describe Transmission::Arguments do
|
2
|
+
|
3
|
+
[
|
4
|
+
{className: Transmission::Arguments::SessionGet, arguments: ['alt-speed-down']},
|
5
|
+
{className: Transmission::Arguments::SessionSet, arguments: ['alt-speed-down']},
|
6
|
+
{className: Transmission::Arguments::SessionStats, arguments: ['activeTorrentCount']},
|
7
|
+
{className: Transmission::Arguments::TorrentAdd, arguments: ['cookies']},
|
8
|
+
{className: Transmission::Arguments::TorrentGet, arguments: ['id']},
|
9
|
+
{className: Transmission::Arguments::TorrentSet, arguments: ['bandwidthPriority']}
|
10
|
+
].each do |klass|
|
11
|
+
|
12
|
+
describe "#{klass[:className]}" do
|
13
|
+
describe '#new' do
|
14
|
+
it 'should create an instance with correct arguments' do
|
15
|
+
instance = klass[:className].new
|
16
|
+
expect(instance.arguments.size).to eq(klass[:className]::ATTRIBUTES.size)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should create an instance with given arguments' do
|
20
|
+
instance = klass[:className].new klass[:arguments]
|
21
|
+
expect(instance.arguments.size).to eq(1)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should raise an error if invalid arguments is given' do
|
25
|
+
expect {
|
26
|
+
klass[:className].new ['i-dont-exist']
|
27
|
+
}.to raise_error(Transmission::Arguments::InvalidArgument)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
describe Transmission::Model::Torrent do
|
2
|
+
|
3
|
+
describe '.all' do
|
4
|
+
|
5
|
+
describe 'with configuration' do
|
6
|
+
before :each do
|
7
|
+
Transmission::Config.set
|
8
|
+
stub_get_torrent({}, [{id: 1}])
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return an array of Torrent models' do
|
12
|
+
torrents = Transmission::Model::Torrent.all
|
13
|
+
expect(torrents).to be_an(Array)
|
14
|
+
expect(torrents.first).to be_a(Transmission::Model::Torrent)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'with connector' do
|
19
|
+
before :each do
|
20
|
+
@rpc = Transmission::RPC.new
|
21
|
+
stub_rpc_request
|
22
|
+
.with(body: torrent_get_body)
|
23
|
+
.to_return(successful_response({arguments: {torrents: [{id: 1}]}}))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return an array of Torrent models' do
|
27
|
+
torrents = Transmission::Model::Torrent.all connector: @rpc
|
28
|
+
expect(torrents).to be_an(Array)
|
29
|
+
expect(torrents.first).to be_a(Transmission::Model::Torrent)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.find' do
|
36
|
+
|
37
|
+
describe 'with configuration' do
|
38
|
+
before :each do
|
39
|
+
Transmission::Config.set
|
40
|
+
stub_get_torrent({ids: [1]}, [{id: 1}])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should return a Torrent instance' do
|
44
|
+
torrent = Transmission::Model::Torrent.find 1
|
45
|
+
expect(torrent).to be_a(Transmission::Model::Torrent)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'with connector' do
|
50
|
+
before :each do
|
51
|
+
@rpc = Transmission::RPC.new
|
52
|
+
stub_get_torrent({ids: [1]}, [{id: 1}])
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should return a Torrent instance' do
|
56
|
+
torrent = Transmission::Model::Torrent.find 1, connector: @rpc
|
57
|
+
expect(torrent).to be_a(Transmission::Model::Torrent)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'with invalid id' do
|
62
|
+
before :each do
|
63
|
+
@rpc = Transmission::RPC.new
|
64
|
+
stub_get_torrent({ids: [1]}, [])
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should raise error' do
|
68
|
+
expect {
|
69
|
+
Transmission::Model::Torrent.find 1, connector: @rpc
|
70
|
+
}.to raise_error(Transmission::Model::Torrent::TorrentNotFoundError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.add' do
|
77
|
+
|
78
|
+
describe 'with configuration' do
|
79
|
+
before :each do
|
80
|
+
Transmission::Config.set
|
81
|
+
stub_rpc_request
|
82
|
+
.with(body: torrent_add_body({filename: 'torrent_file'}))
|
83
|
+
.to_return(successful_response({arguments: {'torrent-added' => {id: 1}}}))
|
84
|
+
stub_get_torrent({ids: [1]}, [{id: 1}])
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should return a Torrent instance' do
|
88
|
+
torrent = Transmission::Model::Torrent.add arguments: {filename: 'torrent_file'}
|
89
|
+
expect(torrent).to be_a(Transmission::Model::Torrent)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'when torrent is a duplicate' do
|
94
|
+
before :each do
|
95
|
+
Transmission::Config.set
|
96
|
+
stub_rpc_request
|
97
|
+
.with(body: torrent_add_body({filename: 'torrent_file'}))
|
98
|
+
.to_return(unsuccessful_response({result: 'duplicate torrent'}))
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should raise error' do
|
102
|
+
expect {
|
103
|
+
Transmission::Model::Torrent.add arguments: {filename: 'torrent_file'}
|
104
|
+
}.to raise_error(Transmission::RPC::Connector::ConnectionError)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
describe '#delete!' do
|
111
|
+
|
112
|
+
describe 'with configuration' do
|
113
|
+
before :each do
|
114
|
+
Transmission::Config.set
|
115
|
+
stub_get_torrent({ids: [1]}, [{id: 1}])
|
116
|
+
stub_rpc_request
|
117
|
+
.with(body: torrent_remove_body({:ids => [1], 'delete-local-data' => false}))
|
118
|
+
.to_return(successful_response({arguments: {torrents: [{id: 1}]}}))
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should remove the torrent file' do
|
122
|
+
torrent = Transmission::Model::Torrent.find 1
|
123
|
+
torrent.delete!
|
124
|
+
expect(torrent.deleted).to eq(true)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe 'with connector' do
|
129
|
+
before :each do
|
130
|
+
@rpc = Transmission::RPC.new
|
131
|
+
stub_get_torrent({ids: [1]}, [{id: 1}])
|
132
|
+
stub_rpc_request
|
133
|
+
.with(body: torrent_remove_body({:ids => [1], 'delete-local-data' => false}))
|
134
|
+
.to_return(successful_response({arguments: {torrents: [{id: 1}]}}))
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should remove the torrent file' do
|
138
|
+
torrent = Transmission::Model::Torrent.find 1, :connector => @rpc
|
139
|
+
torrent.delete!
|
140
|
+
expect(torrent.deleted).to eq(true)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
describe Transmission::RPC::Connector do
|
2
|
+
|
3
|
+
describe '#new' do
|
4
|
+
|
5
|
+
describe 'without parameters' do
|
6
|
+
before :each do
|
7
|
+
@connector = Transmission::RPC::Connector.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should create an RPC object with default values' do
|
11
|
+
expect(@connector.host).to eq('localhost')
|
12
|
+
expect(@connector.port).to eq(9091)
|
13
|
+
expect(@connector.ssl).to eq(false)
|
14
|
+
expect(@connector.path).to eq('/transmission/rpc')
|
15
|
+
expect(@connector.credentials).to eq(nil)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'with parameters' do
|
20
|
+
before :each do
|
21
|
+
@connector = Transmission::RPC::Connector.new host: 'some.host', port: 8888, ssl: true, path: '/path', credentials: {username: 'a', password: 'b'}
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should create an RPC object with given parameters' do
|
25
|
+
expect(@connector.host).to eq('some.host')
|
26
|
+
expect(@connector.port).to eq(8888)
|
27
|
+
expect(@connector.ssl).to eq(true)
|
28
|
+
expect(@connector.path).to eq('/path')
|
29
|
+
expect(@connector.credentials).to eq({username: 'a', password: 'b'})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#post' do
|
36
|
+
|
37
|
+
describe 'when session ID has not been acquired yet' do
|
38
|
+
before :each do
|
39
|
+
@connector = Transmission::RPC::Connector.new
|
40
|
+
stub_rpc_request
|
41
|
+
.to_return(conflict_response({headers: {'x-transmission-session-id' => 'abc'}}))
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should save the transmission session ID' do
|
45
|
+
expect {
|
46
|
+
@connector.post
|
47
|
+
}.to raise_error(Transmission::RPC::Connector::InvalidSessionError)
|
48
|
+
expect(@connector.session_id).to eq('abc')
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'when session ID has been acquired' do
|
53
|
+
before :each do
|
54
|
+
@connector = Transmission::RPC::Connector.new
|
55
|
+
stub_rpc_request
|
56
|
+
.to_return(successful_response)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should respond successfully' do
|
60
|
+
@connector.post
|
61
|
+
expect(@connector.response.status).to eq(200)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'when basic auth is required but no credentials provided' do
|
66
|
+
before :each do
|
67
|
+
@connector = Transmission::RPC::Connector.new
|
68
|
+
stub_rpc_request
|
69
|
+
.to_return(unauthorized_response)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should raise auth error' do
|
73
|
+
expect {
|
74
|
+
@connector.post
|
75
|
+
}.to raise_error(Transmission::RPC::Connector::AuthError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
describe Transmission::RPC do
|
2
|
+
|
3
|
+
describe '#get_session' do
|
4
|
+
|
5
|
+
describe 'with fields' do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
@rpc = Transmission::RPC.new
|
9
|
+
fields = Transmission::Arguments::SessionGet.new(['version']).to_arguments
|
10
|
+
stub_rpc_request
|
11
|
+
.with({body: session_get_body({fields: fields})})
|
12
|
+
.to_return(successful_response)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should send the proper arguments' do
|
16
|
+
@rpc.get_session fields: ['version']
|
17
|
+
expect(@rpc.connector.response.status).to eq(200)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'without fields' do
|
23
|
+
|
24
|
+
before :each do
|
25
|
+
@rpc = Transmission::RPC.new
|
26
|
+
fields = Transmission::Arguments::SessionGet.new.to_arguments
|
27
|
+
stub_rpc_request
|
28
|
+
.with({body: session_get_body({fields: fields})})
|
29
|
+
.to_return(successful_response)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should send the proper arguments' do
|
33
|
+
@rpc.get_session
|
34
|
+
expect(@rpc.connector.response.status).to eq(200)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'transmission-rpc-ruby'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.date = '2015-03-27'
|
5
|
+
s.summary = "Transmission RPC wrapper in Ruby"
|
6
|
+
s.description = "A new transmission RPC wrapper for Ruby. All object oriented for controlling remote transmission daemons."
|
7
|
+
s.authors = ["Max Hoffmann"]
|
8
|
+
s.email = 'tsov@me.com'
|
9
|
+
s.files = `git ls-files`.split($/)
|
10
|
+
s.homepage = 'https://github.com/transmission-rails/transmission-rpc-ruby'
|
11
|
+
s.license = 'MIT'
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.add_dependency "faraday", "~> 0.9"
|
14
|
+
s.add_development_dependency "rake", "~> 10.4"
|
15
|
+
s.add_development_dependency "rspec", "~> 3.2"
|
16
|
+
s.add_development_dependency "webmock", "~> 1.20"
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transmission-rpc-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Hoffmann
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.20'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.20'
|
69
|
+
description: A new transmission RPC wrapper for Ruby. All object oriented for controlling
|
70
|
+
remote transmission daemons.
|
71
|
+
email: tsov@me.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- Gemfile.lock
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/transmission.rb
|
84
|
+
- lib/transmission/arguments.rb
|
85
|
+
- lib/transmission/arguments/session_get.rb
|
86
|
+
- lib/transmission/arguments/session_set.rb
|
87
|
+
- lib/transmission/arguments/session_stats.rb
|
88
|
+
- lib/transmission/arguments/torrent_add.rb
|
89
|
+
- lib/transmission/arguments/torrent_get.rb
|
90
|
+
- lib/transmission/arguments/torrent_set.rb
|
91
|
+
- lib/transmission/config.rb
|
92
|
+
- lib/transmission/model.rb
|
93
|
+
- lib/transmission/model/session.rb
|
94
|
+
- lib/transmission/model/torrent.rb
|
95
|
+
- lib/transmission/rpc.rb
|
96
|
+
- lib/transmission/rpc/connector.rb
|
97
|
+
- spec/helpers/stubs.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/transmission/arguments_spec.rb
|
100
|
+
- spec/transmission/model/torrent_spec.rb
|
101
|
+
- spec/transmission/rpc/connector_spec.rb
|
102
|
+
- spec/transmission/rpc_spec.rb
|
103
|
+
- transmission-rpc-ruby.gemspec
|
104
|
+
homepage: https://github.com/transmission-rails/transmission-rpc-ruby
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Transmission RPC wrapper in Ruby
|
128
|
+
test_files: []
|