transmission-rpc-ruby-ext 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/CHANGELOG.md +3 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +62 -0
  8. data/LICENSE +19 -0
  9. data/README.md +173 -0
  10. data/Rakefile +5 -0
  11. data/lib/transmission.rb +11 -0
  12. data/lib/transmission/arguments.rb +50 -0
  13. data/lib/transmission/arguments/location_set.rb +11 -0
  14. data/lib/transmission/arguments/session_set.rb +56 -0
  15. data/lib/transmission/arguments/torrent_add.rb +24 -0
  16. data/lib/transmission/arguments/torrent_set.rb +32 -0
  17. data/lib/transmission/config.rb +18 -0
  18. data/lib/transmission/extensions.rb +4 -0
  19. data/lib/transmission/extensions/torrent_actions.rb +15 -0
  20. data/lib/transmission/extensions/torrent_attributes.rb +103 -0
  21. data/lib/transmission/extensions/torrent_status.rb +42 -0
  22. data/lib/transmission/extensions/transmission.rb +82 -0
  23. data/lib/transmission/fields.rb +41 -0
  24. data/lib/transmission/fields/session_get.rb +61 -0
  25. data/lib/transmission/fields/session_stats.rb +15 -0
  26. data/lib/transmission/fields/torrent_get.rb +76 -0
  27. data/lib/transmission/model.rb +8 -0
  28. data/lib/transmission/model/session.rb +48 -0
  29. data/lib/transmission/model/session_stats.rb +28 -0
  30. data/lib/transmission/model/torrent.rb +152 -0
  31. data/lib/transmission/rpc.rb +116 -0
  32. data/lib/transmission/rpc/connector.rb +67 -0
  33. data/lib/transmission/utils.rb +24 -0
  34. data/spec/helpers/stubs.rb +82 -0
  35. data/spec/spec_helper.rb +13 -0
  36. data/spec/transmission/arguments_spec.rb +78 -0
  37. data/spec/transmission/fields_spec.rb +60 -0
  38. data/spec/transmission/model/session_spec.rb +85 -0
  39. data/spec/transmission/model/torrent_spec.rb +345 -0
  40. data/spec/transmission/rpc/connector_spec.rb +82 -0
  41. data/spec/transmission/rpc_spec.rb +33 -0
  42. data/spec/transmission/utils_spec.rb +69 -0
  43. data/transmission-rpc-ruby-ext.gemspec +17 -0
  44. metadata +141 -0
@@ -0,0 +1,82 @@
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
+ stub_rpc_request
43
+ .with(headers: {'x-transmission-session-id' => 'abc'})
44
+ .to_return(successful_response)
45
+ end
46
+
47
+ it 'should save the transmission session ID' do
48
+ @connector.post
49
+ expect(@connector.session_id).to eq('abc')
50
+ end
51
+ end
52
+
53
+ describe 'when session ID has been acquired' do
54
+ before :each do
55
+ @connector = Transmission::RPC::Connector.new
56
+ stub_rpc_request
57
+ .to_return(successful_response)
58
+ end
59
+
60
+ it 'should respond successfully' do
61
+ @connector.post
62
+ expect(@connector.response.status).to eq(200)
63
+ end
64
+ end
65
+
66
+ describe 'when basic auth is required but no credentials provided' do
67
+ before :each do
68
+ @connector = Transmission::RPC::Connector.new
69
+ stub_rpc_request
70
+ .to_return(unauthorized_response)
71
+ end
72
+
73
+ it 'should raise auth error' do
74
+ expect {
75
+ @connector.post
76
+ }.to raise_error(Transmission::RPC::Connector::AuthError)
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
@@ -0,0 +1,33 @@
1
+ describe Transmission::RPC do
2
+ describe '#get_session' do
3
+ describe 'with fields' do
4
+ before :each do
5
+ @rpc = Transmission::RPC.new
6
+ fields = Transmission::Fields::SessionGet.new(['version']).to_fields
7
+ stub_rpc_request
8
+ .with( body: session_get_body( fields: fields ))
9
+ .to_return(successful_response)
10
+ end
11
+
12
+ it 'should send the proper arguments' do
13
+ @rpc.get_session ['version']
14
+ expect(@rpc.connector.response.status).to eq(200)
15
+ end
16
+ end
17
+
18
+ describe 'without fields' do
19
+ before :each do
20
+ @rpc = Transmission::RPC.new
21
+ fields = Transmission::Fields::SessionGet.new.to_fields
22
+ stub_rpc_request
23
+ .with(body: session_get_body(fields: fields))
24
+ .to_return(successful_response)
25
+ end
26
+
27
+ it 'should send the proper arguments' do
28
+ @rpc.get_session
29
+ expect(@rpc.connector.response.status).to eq(200)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,69 @@
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
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'transmission-rpc-ruby-ext'
3
+ s.version = '0.1.0'
4
+ s.date = '2016-12-28'
5
+ s.summary = 'Extended version of transmission-rpc-ruby.'
6
+ s.description = 'A fork of transmission-rpc-ruby with some shortcut methods added.'
7
+ s.authors = ['Tommaso Barbato']
8
+ s.email = 'epistrephein@gmail.com'
9
+ s.files = `git ls-files`.split($/)
10
+ s.homepage = 'https://github.com/epistrephein/transmission-rpc-ruby-ext'
11
+ s.license = 'MIT'
12
+ s.require_paths = ['lib']
13
+ s.add_dependency 'faraday', '~> 0.10'
14
+ s.add_development_dependency 'rspec', '~> 3.5'
15
+ s.add_development_dependency 'webmock', '~> 2.3'
16
+ s.add_development_dependency 'rake', '~> 12.0'
17
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: transmission-rpc-ruby-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tommaso Barbato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-28 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.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ description: A fork of transmission-rpc-ruby with some shortcut methods added.
70
+ email: epistrephein@gmail.com
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/transmission.rb
85
+ - lib/transmission/arguments.rb
86
+ - lib/transmission/arguments/location_set.rb
87
+ - lib/transmission/arguments/session_set.rb
88
+ - lib/transmission/arguments/torrent_add.rb
89
+ - lib/transmission/arguments/torrent_set.rb
90
+ - lib/transmission/config.rb
91
+ - lib/transmission/extensions.rb
92
+ - lib/transmission/extensions/torrent_actions.rb
93
+ - lib/transmission/extensions/torrent_attributes.rb
94
+ - lib/transmission/extensions/torrent_status.rb
95
+ - lib/transmission/extensions/transmission.rb
96
+ - lib/transmission/fields.rb
97
+ - lib/transmission/fields/session_get.rb
98
+ - lib/transmission/fields/session_stats.rb
99
+ - lib/transmission/fields/torrent_get.rb
100
+ - lib/transmission/model.rb
101
+ - lib/transmission/model/session.rb
102
+ - lib/transmission/model/session_stats.rb
103
+ - lib/transmission/model/torrent.rb
104
+ - lib/transmission/rpc.rb
105
+ - lib/transmission/rpc/connector.rb
106
+ - lib/transmission/utils.rb
107
+ - spec/helpers/stubs.rb
108
+ - spec/spec_helper.rb
109
+ - spec/transmission/arguments_spec.rb
110
+ - spec/transmission/fields_spec.rb
111
+ - spec/transmission/model/session_spec.rb
112
+ - spec/transmission/model/torrent_spec.rb
113
+ - spec/transmission/rpc/connector_spec.rb
114
+ - spec/transmission/rpc_spec.rb
115
+ - spec/transmission/utils_spec.rb
116
+ - transmission-rpc-ruby-ext.gemspec
117
+ homepage: https://github.com/epistrephein/transmission-rpc-ruby-ext
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.6.8
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Extended version of transmission-rpc-ruby.
141
+ test_files: []