transmission-rpc-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -143,4 +143,86 @@ describe Transmission::Model::Torrent do
143
143
 
144
144
  end
145
145
 
146
+ describe '#method_missing' do
147
+ let(:torrent) { Transmission::Model::Torrent.new({'id' => 1, 'name' => 'some name', 'some-key' => 'some-value'}, nil) }
148
+
149
+ before :each do
150
+ stub_const("Transmission::Fields::TorrentGet::ATTRIBUTES", [{field: 'id'}, {field: 'name'}, {field: 'some-key'}])
151
+ stub_const("Transmission::Arguments::TorrentSet::ATTRIBUTES", [{field: 'name'}])
152
+ end
153
+
154
+ describe 'with existing attributes' do
155
+ it 'should return the correct values' do
156
+ expect(torrent.id).to eq(1)
157
+ expect(torrent.name).to eq('some name')
158
+ expect(torrent.some_key).to eq('some-value')
159
+ end
160
+
161
+ it 'should set the correct values' do
162
+ torrent.name = 'ok'
163
+ expect(torrent.name).to eq('ok')
164
+ end
165
+ end
166
+
167
+ describe 'with none existing attributes' do
168
+ it 'should raise error' do
169
+ expect {
170
+ torrent.i_dont_exist
171
+ }.to raise_error(NoMethodError)
172
+ end
173
+
174
+ it 'should raise error' do
175
+ expect {
176
+ torrent.i_dont_exist = 'some value'
177
+ }.to raise_error(NoMethodError)
178
+ end
179
+ end
180
+ end
181
+
182
+ describe '#save!' do
183
+ let(:rpc) {Transmission::RPC.new}
184
+
185
+ before :each do
186
+ stub_const("Transmission::Arguments::TorrentSet::ATTRIBUTES", [{field: 'name'}, {field: 'ids'}])
187
+ stub_get_torrent({ids: [1]}, [{id: 1, name: 'test', comment: 'comment'}])
188
+ stub_rpc_request
189
+ .with(body: torrent_set_body({name: 'new value', ids: [1]}))
190
+ .to_return(successful_response)
191
+ end
192
+
193
+ it 'should send the right parameters' do
194
+ torrent = Transmission::Model::Torrent.find 1, connector: rpc
195
+ torrent.name = 'new value'
196
+ torrent.save!
197
+ end
198
+ end
199
+
200
+ [
201
+ {method: 'start!', rpc_method: 'torrent-start'},
202
+ {method: 'start_now!', rpc_method: 'torrent-start-now'},
203
+ {method: 'stop!', rpc_method: 'torrent-stop'},
204
+ {method: 'verify!', rpc_method: 'torrent-verify'},
205
+ {method: 're_announce!', rpc_method: 'torrent-reannounce'},
206
+ {method: 'move_up!', rpc_method: 'queue-move-up'},
207
+ {method: 'move_down!', rpc_method: 'queue-move-down'},
208
+ {method: 'move_top!', rpc_method: 'queue-move-top'},
209
+ {method: 'move_bottom!', rpc_method: 'queue-move-bottom'}
210
+ ].each do |object|
211
+ describe "##{object[:method]}" do
212
+ let(:rpc) {Transmission::RPC.new}
213
+
214
+ before :each do
215
+ stub_get_torrent({ids: [1]}, [{id: 1}])
216
+ stub_rpc_request
217
+ .with(body: torrent_method_body(object[:rpc_method], {ids: [1]}))
218
+ .to_return(successful_response)
219
+ end
220
+
221
+ it "should #{object[:method]} torrent" do
222
+ torrent = Transmission::Model::Torrent.find 1, connector: rpc
223
+ torrent.send object[:method].to_sym
224
+ end
225
+ end
226
+ end
227
+
146
228
  end
@@ -39,12 +39,13 @@ describe Transmission::RPC::Connector do
39
39
  @connector = Transmission::RPC::Connector.new
40
40
  stub_rpc_request
41
41
  .to_return(conflict_response({headers: {'x-transmission-session-id' => 'abc'}}))
42
+ stub_rpc_request
43
+ .with(headers: {'x-transmission-session-id' => 'abc'})
44
+ .to_return(successful_response)
42
45
  end
43
46
 
44
47
  it 'should save the transmission session ID' do
45
- expect {
46
- @connector.post
47
- }.to raise_error(Transmission::RPC::Connector::InvalidSessionError)
48
+ @connector.post
48
49
  expect(@connector.session_id).to eq('abc')
49
50
  end
50
51
  end
@@ -1,29 +1,26 @@
1
1
  describe Transmission::RPC do
2
2
 
3
3
  describe '#get_session' do
4
-
5
4
  describe 'with fields' do
6
-
7
5
  before :each do
8
6
  @rpc = Transmission::RPC.new
9
- fields = Transmission::Arguments::SessionGet.new(['version']).to_arguments
7
+ fields = Transmission::Fields::SessionGet.new(['version']).to_fields
10
8
  stub_rpc_request
11
9
  .with({body: session_get_body({fields: fields})})
12
10
  .to_return(successful_response)
13
11
  end
14
12
 
15
13
  it 'should send the proper arguments' do
16
- @rpc.get_session fields: ['version']
14
+ @rpc.get_session ['version']
17
15
  expect(@rpc.connector.response.status).to eq(200)
18
16
  end
19
17
 
20
18
  end
21
19
 
22
20
  describe 'without fields' do
23
-
24
21
  before :each do
25
22
  @rpc = Transmission::RPC.new
26
- fields = Transmission::Arguments::SessionGet.new.to_arguments
23
+ fields = Transmission::Fields::SessionGet.new.to_fields
27
24
  stub_rpc_request
28
25
  .with({body: session_get_body({fields: fields})})
29
26
  .to_return(successful_response)
@@ -33,9 +30,7 @@ describe Transmission::RPC do
33
30
  @rpc.get_session
34
31
  expect(@rpc.connector.response.status).to eq(200)
35
32
  end
36
-
37
33
  end
38
-
39
34
  end
40
35
 
41
36
  end
@@ -0,0 +1,70 @@
1
+ describe Transmission::Utils do
2
+ let(:utils) {
3
+ Class.new do
4
+ include Transmission::Utils
5
+ end
6
+ }
7
+
8
+ subject { utils.new }
9
+
10
+ describe '.is_valid_key?' do
11
+ describe 'with dashes' do
12
+ let(:arguments) {[{field: 'test-me'}]}
13
+
14
+ it 'should find valid key' do
15
+ expect(subject.is_valid_key?('test_me', arguments)).to eq(true)
16
+ end
17
+ end
18
+
19
+ describe 'with camelcase' do
20
+ let(:arguments) {[{field: 'testMe'}]}
21
+
22
+ it 'should find valid key' do
23
+ expect(subject.is_valid_key?('test_me', arguments)).to eq(true)
24
+ end
25
+ end
26
+
27
+ describe 'with invalid key' do
28
+ let(:arguments) {[{field: 'testMe'}]}
29
+
30
+ it 'should not find any key' do
31
+ expect(subject.is_valid_key?('i_dont_exit', arguments)).to eq(false)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '.option_keys' do
37
+ it 'should return the right option keys' do
38
+ options = subject.option_keys('test_me')
39
+ expect(options.include?('testMe')).to eq(true)
40
+ expect(options.include?('test-me')).to eq(true)
41
+ end
42
+ end
43
+
44
+ describe '.option_key' do
45
+ describe 'with dashes' do
46
+ let(:arguments) {[{field: 'test-me'}]}
47
+
48
+ it 'should return the correct key' do
49
+ expect(subject.option_key('test_me', arguments)).to eq('test-me')
50
+ end
51
+ end
52
+
53
+ describe 'with camelcase' do
54
+ let(:arguments) {[{field: 'testMe'}]}
55
+
56
+ it 'should return the correct key' do
57
+ expect(subject.option_key('test_me', arguments)).to eq('testMe')
58
+ end
59
+ end
60
+
61
+ describe 'with invalid key' do
62
+ let(:arguments) {[{field: 'testMe'}]}
63
+
64
+ it 'should return nil' do
65
+ expect(subject.option_key('i_dont_exit', arguments)).to eq(nil)
66
+ end
67
+ end
68
+ end
69
+
70
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'transmission-rpc-ruby'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.date = '2015-03-27'
5
5
  s.summary = "Transmission RPC wrapper in Ruby"
6
6
  s.description = "A new transmission RPC wrapper for Ruby. All object oriented for controlling remote transmission daemons."
@@ -13,5 +13,5 @@ Gem::Specification.new do |s|
13
13
  s.add_dependency "faraday", "~> 0.9"
14
14
  s.add_development_dependency "rake", "~> 10.4"
15
15
  s.add_development_dependency "rspec", "~> 3.2"
16
- s.add_development_dependency "webmock", "~> 1.20"
16
+ s.add_development_dependency "webmock", "~> 1.21"
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transmission-rpc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Hoffmann
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.20'
61
+ version: '1.21'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.20'
68
+ version: '1.21'
69
69
  description: A new transmission RPC wrapper for Ruby. All object oriented for controlling
70
70
  remote transmission daemons.
71
71
  email: tsov@me.com
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - ".rspec"
78
+ - ".travis.yml"
78
79
  - Gemfile
79
80
  - Gemfile.lock
80
81
  - LICENSE
@@ -82,24 +83,30 @@ files:
82
83
  - Rakefile
83
84
  - lib/transmission.rb
84
85
  - lib/transmission/arguments.rb
85
- - lib/transmission/arguments/session_get.rb
86
86
  - lib/transmission/arguments/session_set.rb
87
- - lib/transmission/arguments/session_stats.rb
88
87
  - lib/transmission/arguments/torrent_add.rb
89
- - lib/transmission/arguments/torrent_get.rb
90
88
  - lib/transmission/arguments/torrent_set.rb
91
89
  - lib/transmission/config.rb
90
+ - lib/transmission/fields.rb
91
+ - lib/transmission/fields/session_get.rb
92
+ - lib/transmission/fields/session_stats.rb
93
+ - lib/transmission/fields/torrent_get.rb
92
94
  - lib/transmission/model.rb
93
95
  - lib/transmission/model/session.rb
96
+ - lib/transmission/model/session_stats.rb
94
97
  - lib/transmission/model/torrent.rb
95
98
  - lib/transmission/rpc.rb
96
99
  - lib/transmission/rpc/connector.rb
100
+ - lib/transmission/utils.rb
97
101
  - spec/helpers/stubs.rb
98
102
  - spec/spec_helper.rb
99
103
  - spec/transmission/arguments_spec.rb
104
+ - spec/transmission/fields_spec.rb
105
+ - spec/transmission/model/session_spec.rb
100
106
  - spec/transmission/model/torrent_spec.rb
101
107
  - spec/transmission/rpc/connector_spec.rb
102
108
  - spec/transmission/rpc_spec.rb
109
+ - spec/transmission/utils_spec.rb
103
110
  - transmission-rpc-ruby.gemspec
104
111
  homepage: https://github.com/transmission-rails/transmission-rpc-ruby
105
112
  licenses:
@@ -1,63 +0,0 @@
1
- module Transmission
2
- class Arguments
3
- class SessionGet < Transmission::Arguments
4
-
5
- ATTRIBUTES = [
6
- 'alt-speed-down',
7
- 'alt-speed-enabled',
8
- 'alt-speed-time-begin',
9
- 'alt-speed-time-enabled',
10
- 'alt-speed-time-end',
11
- 'alt-speed-time-day',
12
- 'alt-speed-up',
13
- 'blocklist-url',
14
- 'blocklist-update',
15
- 'blocklist-enabled',
16
- 'blocklist-size',
17
- 'cache-size-mb',
18
- 'config-dir',
19
- 'download-dir',
20
- 'download-queue-size',
21
- 'download-queue-enabled',
22
- 'dht-enabled',
23
- 'encryption',
24
- 'required',
25
- 'preferred',
26
- 'tolerated',
27
- 'idle-seeding-limit',
28
- 'idle-seeding-limit-enabled',
29
- 'incomplete-dir',
30
- 'incomplete-dir-enabled',
31
- 'lpd-enabled',
32
- 'peer-limit-global',
33
- 'peer-limit-per-torrent',
34
- 'pex-enabled',
35
- 'peer-port',
36
- 'peer-port-random-on-start',
37
- 'port-forwarding-enabled',
38
- 'queue-stalled-enabled',
39
- 'queue-stalled-minutes',
40
- 'rename-partial-files',
41
- 'rpc-version',
42
- 'rpc-version-minimum',
43
- 'script-torrent-done-filename',
44
- 'script-torrent-done-enabled',
45
- 'done',
46
- 'seedRatioLimit',
47
- 'seedRatioLimited',
48
- 'seed-queue-size',
49
- 'seed-queue-enabled',
50
- 'speed-limit-down',
51
- 'speed-limit-down-enabled',
52
- 'speed-limit-up',
53
- 'speed-limit-up-enabled',
54
- 'start-added-torrents',
55
- 'trash-original-torrent-files',
56
- 'units',
57
- 'utp-enabled',
58
- 'version'
59
- ]
60
-
61
- end
62
- end
63
- end
@@ -1,17 +0,0 @@
1
- module Transmission
2
- class Arguments
3
- class SessionStats < Transmission::Arguments
4
-
5
- ATTRIBUTES = [
6
- 'activeTorrentCount',
7
- 'downloadSpeed',
8
- 'pausedTorrentCount',
9
- 'torrentCount',
10
- 'uploadSpeed',
11
- 'cumulative-stats',
12
- 'current-stats'
13
- ]
14
-
15
- end
16
- end
17
- end
@@ -1,78 +0,0 @@
1
- module Transmission
2
- class Arguments
3
- class TorrentGet < Transmission::Arguments
4
-
5
- ATTRIBUTES = [
6
- 'id',
7
- 'activityDate',
8
- 'addedDate',
9
- 'bandwidthPriority',
10
- 'comment',
11
- 'corruptEver',
12
- 'creator',
13
- 'dateCreated',
14
- 'desiredAvailable',
15
- 'doneDate',
16
- 'downloadDir',
17
- 'downloadedEver',
18
- 'downloadLimit',
19
- 'downloadLimited',
20
- 'error',
21
- 'errorString',
22
- 'eta',
23
- 'etaIdle',
24
- 'files',
25
- 'fileStats',
26
- 'hashString',
27
- 'haveUnchecked',
28
- 'haveValid',
29
- 'honorsSessionLimits',
30
- 'isFinished',
31
- 'isPrivate',
32
- 'isStalled',
33
- 'leftUntilDone',
34
- 'magnetLink',
35
- 'manualAnnounceTime',
36
- 'maxConnectedPeers',
37
- 'metadataPercentComplete',
38
- 'name',
39
- 'peer-limit',
40
- 'peers',
41
- 'peersConnected',
42
- 'peersFrom',
43
- 'peersGettingFromUs',
44
- 'peersSendingToUs',
45
- 'percentDone',
46
- 'pieces',
47
- 'pieceCount',
48
- 'pieceSize',
49
- 'priorities',
50
- 'queuePosition',
51
- 'rateDownload',
52
- 'rateUpload',
53
- 'recheckProgress',
54
- 'secondsDownloading',
55
- 'secondsSeeding',
56
- 'seedIdleLimit',
57
- 'seedIdleMode',
58
- 'seedRatioLimit',
59
- 'seedRatioMode',
60
- 'sizeWhenDone',
61
- 'startDate',
62
- 'status',
63
- 'trackers',
64
- 'trackerStats',
65
- 'totalSize',
66
- 'torrentFile',
67
- 'uploadedEver',
68
- 'uploadLimit',
69
- 'uploadLimited',
70
- 'uploadRatio',
71
- 'wanted',
72
- 'webseeds',
73
- 'webseedsSendingToUs'
74
- ]
75
-
76
- end
77
- end
78
- end