sabnzbd 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +1 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/fixtures/vcr_cassettes/invalid_key.yml +30 -0
- data/fixtures/vcr_cassettes/paused.yml +59 -0
- data/fixtures/vcr_cassettes/simple_queue.yml +59 -0
- data/fixtures/vcr_cassettes/slots.yml +31 -0
- data/fixtures/vcr_cassettes/valid_key.yml +58 -0
- data/lib/sabnzbd.rb +49 -0
- data/lib/sabnzbd/slot.rb +14 -0
- data/spec/sabnzbd_spec.rb +98 -0
- data/spec/spec_helper.rb +20 -0
- metadata +213 -0
data/.autotest
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "autotest/growl"
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.3.2)
|
5
|
+
autotest-growl (0.2.16)
|
6
|
+
crack (0.3.1)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
git (1.2.5)
|
9
|
+
httparty (0.9.0)
|
10
|
+
multi_json (~> 1.0)
|
11
|
+
multi_xml
|
12
|
+
jeweler (1.8.4)
|
13
|
+
bundler (~> 1.0)
|
14
|
+
git (>= 1.2.5)
|
15
|
+
rake
|
16
|
+
rdoc
|
17
|
+
json (1.7.5)
|
18
|
+
multi_json (1.5.0)
|
19
|
+
multi_xml (0.5.1)
|
20
|
+
rake (10.0.3)
|
21
|
+
rdoc (3.12)
|
22
|
+
json (~> 1.4)
|
23
|
+
rspec (2.8.0)
|
24
|
+
rspec-core (~> 2.8.0)
|
25
|
+
rspec-expectations (~> 2.8.0)
|
26
|
+
rspec-mocks (~> 2.8.0)
|
27
|
+
rspec-core (2.8.0)
|
28
|
+
rspec-expectations (2.8.0)
|
29
|
+
diff-lcs (~> 1.1.2)
|
30
|
+
rspec-mocks (2.8.0)
|
31
|
+
vcr (2.3.0)
|
32
|
+
webmock (1.8.11)
|
33
|
+
addressable (>= 2.2.7)
|
34
|
+
crack (>= 0.1.7)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
autotest-growl
|
41
|
+
bundler
|
42
|
+
httparty
|
43
|
+
jeweler (~> 1.8.4)
|
44
|
+
rdoc (~> 3.12)
|
45
|
+
rspec (~> 2.8.0)
|
46
|
+
vcr
|
47
|
+
webmock (~> 1.8.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Daniel Zwijnenburg
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= sabnzbd
|
2
|
+
|
3
|
+
Ruby wrapper for the Sabnzbd api.
|
4
|
+
|
5
|
+
== Contributing to sabnzbd
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2012 Daniel Zwijnenburg. See LICENSE.txt for
|
18
|
+
further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "sabnzbd"
|
18
|
+
gem.homepage = "http://github.com/DanielZwijnenburg/sabnzbd"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Ruby wrapper for the sabnzbd api.}
|
21
|
+
gem.description = %Q{Ruby wrapper for the sabnzbd api. This gem can be used to gather status and download information from your sabnzb instance.}
|
22
|
+
gem.email = "daniel@danielz.nl"
|
23
|
+
gem.authors = ["Daniel Zwijnenburg"]
|
24
|
+
gem.add_dependency 'httparty'
|
25
|
+
# dependencies defined in Gemfile
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rdoc/task'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "sabnzbd #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:8080/api?apikey=invalid&mode=qstatus&output=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 19 Dec 2012 10:28:24 GMT
|
17
|
+
Content-Length:
|
18
|
+
- '44'
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Pragma:
|
22
|
+
- no-cache
|
23
|
+
Server:
|
24
|
+
- CherryPy/3.2.0
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"status":false,"error":"API Key Incorrect"}'
|
28
|
+
http_version:
|
29
|
+
recorded_at: Wed, 19 Dec 2012 10:28:24 GMT
|
30
|
+
recorded_with: VCR 2.3.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 19 Dec 2012 12:12:31 GMT
|
17
|
+
Content-Length:
|
18
|
+
- '425'
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Pragma:
|
22
|
+
- no-cache
|
23
|
+
Server:
|
24
|
+
- CherryPy/3.2.0
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"have_warnings":"7","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22281.559650,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22281.559650,"diskspace2":70.695053,"diskspace1":70.695053,"speed":"0
|
28
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
29
|
+
http_version:
|
30
|
+
recorded_at: Wed, 19 Dec 2012 12:12:31 GMT
|
31
|
+
- request:
|
32
|
+
method: get
|
33
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ''
|
37
|
+
headers: {}
|
38
|
+
response:
|
39
|
+
status:
|
40
|
+
code: 200
|
41
|
+
message: OK
|
42
|
+
headers:
|
43
|
+
Date:
|
44
|
+
- Wed, 19 Dec 2012 13:00:12 GMT
|
45
|
+
Content-Length:
|
46
|
+
- '44'
|
47
|
+
Content-Type:
|
48
|
+
- application/json;charset=UTF-8
|
49
|
+
Pragma:
|
50
|
+
- no-cache
|
51
|
+
Server:
|
52
|
+
- CherryPy/3.2.0
|
53
|
+
body:
|
54
|
+
encoding: US-ASCII
|
55
|
+
string: ! '{"have_warnings":"7","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22281.559650,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22281.559650,"diskspace2":70.695053,"diskspace1":70.695053,"speed":"0
|
56
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
57
|
+
http_version:
|
58
|
+
recorded_at: Wed, 19 Dec 2012 13:00:12 GMT
|
59
|
+
recorded_with: VCR 2.3.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 19 Dec 2012 10:23:37 GMT
|
17
|
+
Content-Length:
|
18
|
+
- '425'
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Pragma:
|
22
|
+
- no-cache
|
23
|
+
Server:
|
24
|
+
- CherryPy/3.2.0
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"have_warnings":"1","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22281.559650,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22281.559650,"diskspace2":70.699986,"diskspace1":70.699986,"speed":"0
|
28
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
29
|
+
http_version:
|
30
|
+
recorded_at: Wed, 19 Dec 2012 10:23:37 GMT
|
31
|
+
- request:
|
32
|
+
method: get
|
33
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ''
|
37
|
+
headers: {}
|
38
|
+
response:
|
39
|
+
status:
|
40
|
+
code: 200
|
41
|
+
message: OK
|
42
|
+
headers:
|
43
|
+
Date:
|
44
|
+
- Wed, 19 Dec 2012 10:34:06 GMT
|
45
|
+
Content-Length:
|
46
|
+
- '425'
|
47
|
+
Content-Type:
|
48
|
+
- application/json;charset=UTF-8
|
49
|
+
Pragma:
|
50
|
+
- no-cache
|
51
|
+
Server:
|
52
|
+
- CherryPy/3.2.0
|
53
|
+
body:
|
54
|
+
encoding: US-ASCII
|
55
|
+
string: ! '{"have_warnings":"7","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22281.559650,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22281.559650,"diskspace2":70.698376,"diskspace1":70.698376,"speed":"0
|
56
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
57
|
+
http_version:
|
58
|
+
recorded_at: Wed, 19 Dec 2012 10:34:06 GMT
|
59
|
+
recorded_with: VCR 2.3.0
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 19 Dec 2012 12:58:36 GMT
|
17
|
+
Content-Length:
|
18
|
+
- '425'
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Pragma:
|
22
|
+
- no-cache
|
23
|
+
Server:
|
24
|
+
- CherryPy/3.2.0
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"have_warnings":"9","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22061.784398,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22061.784398,"diskspace2":70.632774,"diskspace1":70.632774,"speed":"0
|
28
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
29
|
+
http_version:
|
30
|
+
recorded_at: Wed, 19 Dec 2012 12:58:36 GMT
|
31
|
+
recorded_with: VCR 2.3.0
|
@@ -0,0 +1,58 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Wed, 19 Dec 2012 12:12:31 GMT
|
17
|
+
Content-Length:
|
18
|
+
- '425'
|
19
|
+
Content-Type:
|
20
|
+
- application/json;charset=UTF-8
|
21
|
+
Pragma:
|
22
|
+
- no-cache
|
23
|
+
Server:
|
24
|
+
- CherryPy/3.2.0
|
25
|
+
body:
|
26
|
+
encoding: US-ASCII
|
27
|
+
string: ! '{"have_warnings":"7","jobs":[{"timeleft":"0:00:00","mb":23749.483629,"msgid":"","filename":"a_big_legal_file","mbleft":22281.559650,"id":"SABnzbd_nzo_k92LC_"}],"noofslots":1,"paused":true,"pause_int":"0","mbleft":22281.559650,"diskspace2":70.695053,"diskspace1":70.695053,"speed":"0
|
28
|
+
","timeleft":"0:00:00","mb":23749.483629,"state":"PAUSED","loadavg":"","kbpersec":0.000000}'
|
29
|
+
http_version:
|
30
|
+
recorded_at: Wed, 19 Dec 2012 12:12:31 GMT
|
31
|
+
- request:
|
32
|
+
method: get
|
33
|
+
uri: http://localhost:8080/api?apikey=valid_key&mode=qstatus&output=json
|
34
|
+
body:
|
35
|
+
encoding: US-ASCII
|
36
|
+
string: ''
|
37
|
+
headers: {}
|
38
|
+
response:
|
39
|
+
status:
|
40
|
+
code: 200
|
41
|
+
message: OK
|
42
|
+
headers:
|
43
|
+
Date:
|
44
|
+
- Wed, 19 Dec 2012 12:49:20 GMT
|
45
|
+
Content-Length:
|
46
|
+
- '44'
|
47
|
+
Content-Type:
|
48
|
+
- application/json;charset=UTF-8
|
49
|
+
Pragma:
|
50
|
+
- no-cache
|
51
|
+
Server:
|
52
|
+
- CherryPy/3.2.0
|
53
|
+
body:
|
54
|
+
encoding: US-ASCII
|
55
|
+
string: ! '{"status":false,"error":"API Key Incorrect"}'
|
56
|
+
http_version:
|
57
|
+
recorded_at: Wed, 19 Dec 2012 12:49:20 GMT
|
58
|
+
recorded_with: VCR 2.3.0
|
data/lib/sabnzbd.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'sabnzbd/slot'
|
3
|
+
|
4
|
+
class Sabnzbd
|
5
|
+
attr_accessor :api_key, :base_uri
|
6
|
+
attr_reader :slots
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
def initialize(args={})
|
10
|
+
@api_key = args[:api_key] || (raise ApiKeyMissing.new, "Api key missing")
|
11
|
+
@base_uri = args[:base_uri] || "localhost:8080"
|
12
|
+
self.class.base_uri @base_uri
|
13
|
+
end
|
14
|
+
|
15
|
+
def simple_queue
|
16
|
+
make_request
|
17
|
+
end
|
18
|
+
|
19
|
+
def paused?
|
20
|
+
make_request["paused"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def slots
|
24
|
+
@slots ||= initialize_slots
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def make_request(url = "/api?mode=qstatus&output=json&apikey=#{@api_key}")
|
30
|
+
verify_response( self.class.get(url).parsed_response )
|
31
|
+
end
|
32
|
+
|
33
|
+
def verify_response response
|
34
|
+
raise ApiKeyInvalid.new, "Api key invalid #{@api_key}" if response["status"] == false && response["error"]
|
35
|
+
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize_slots
|
40
|
+
jobs = make_request["jobs"]
|
41
|
+
|
42
|
+
jobs.each.inject([]) do |arr, job|
|
43
|
+
arr << Sabnzbd::Slot.new(job)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class ApiKeyMissing < Exception;end
|
49
|
+
class ApiKeyInvalid < Exception;end
|
data/lib/sabnzbd/slot.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Sabnzbd
|
2
|
+
class Slot
|
3
|
+
attr_accessor :time_left, :mb, :msgid, :filename, :mb_left, :id
|
4
|
+
|
5
|
+
def initialize(args={})
|
6
|
+
@time_left = args["timeleft"] || Time.now
|
7
|
+
@mb = args["mb"] || 0.00
|
8
|
+
@msgid = args["msgid"] || nil
|
9
|
+
@filename = args["filename"] || "No filename"
|
10
|
+
@mb_left = args["mbleft"] || 0.00
|
11
|
+
@id = args["id"] || "-"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
Base_uri = nil
|
3
|
+
|
4
|
+
describe "Sabnzbd" do
|
5
|
+
describe "Creation of valid Sabnzbd instance" do
|
6
|
+
before do
|
7
|
+
VCR.insert_cassette 'valid key'
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:sabnzbd) {Sabnzbd.new({api_key: "valid_key"})}
|
11
|
+
it "creates a valid instance of Sabnzb" do
|
12
|
+
sabnzbd.should be_an_instance_of(Sabnzbd)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "Defaults the base_uri to localhost:8080" do
|
16
|
+
sabnzbd.base_uri.should == "localhost:8080"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "Allows the base_uri to be overwritten to localhost:8081" do
|
20
|
+
Sabnzbd.new({api_key: "valid_key", base_uri: "localhost:8081"}).base_uri.should == "localhost:8081"
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
VCR.eject_cassette
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Raising of errors" do
|
29
|
+
it "should raise error if api key is missing" do
|
30
|
+
expect { Sabnzbd.new() }.to raise_error(ApiKeyMissing)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "GET API without valid key" do
|
35
|
+
let(:sabnzbd) {Sabnzbd.new({base_uri: Base_uri, api_key: "invalid"})}
|
36
|
+
before do
|
37
|
+
VCR.insert_cassette 'invalid key'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should raise an error" do
|
41
|
+
expect {sabnzbd.simple_queue}.to raise_error(ApiKeyInvalid)
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
VCR.eject_cassette
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "GET statusses output" do
|
50
|
+
let(:sabnzbd) {Sabnzbd.new({base_uri: Base_uri, api_key: "valid_key"})}
|
51
|
+
before do
|
52
|
+
VCR.insert_cassette 'paused', :record => :new_episodes
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should be paused" do
|
56
|
+
sabnzbd.paused?.should eq true
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should have 1 slot" do
|
60
|
+
sabnzbd.slots.size.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
after do
|
64
|
+
VCR.eject_cassette
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "GET simple Queue output" do
|
69
|
+
let(:sabnzbd) {Sabnzbd.new({base_uri: Base_uri, api_key: "valid_key"})}
|
70
|
+
before do
|
71
|
+
VCR.insert_cassette 'simple queue', :record => :new_episodes
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get the simple queue" do
|
75
|
+
sabnzbd.simple_queue.should be_an_instance_of(Hash)
|
76
|
+
end
|
77
|
+
|
78
|
+
after do
|
79
|
+
VCR.eject_cassette
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "GET slots output" do
|
84
|
+
let(:sabnzbd) {Sabnzbd.new({base_uri: Base_uri, api_key: "valid_key"})}
|
85
|
+
before do
|
86
|
+
VCR.insert_cassette 'slots', :record => :new_episodes
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have 1 slot that is downloading a_big_legal_file" do
|
90
|
+
sabnzbd.slots.first.filename.should == "a_big_legal_file"
|
91
|
+
end
|
92
|
+
|
93
|
+
after do
|
94
|
+
VCR.eject_cassette
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'sabnzbd'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'vcr'
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.extend VCR::RSpec::Macros
|
13
|
+
end
|
14
|
+
|
15
|
+
VCR.configure do |c|
|
16
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
17
|
+
c.hook_into :webmock
|
18
|
+
c.ignore_localhost = false
|
19
|
+
c.default_cassette_options = { :record => :none }
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sabnzbd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Daniel Zwijnenburg
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.8.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: webmock
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 1.8.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.8.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: vcr
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: autotest-growl
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: httparty
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
type: :runtime
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
description: Ruby wrapper for the sabnzbd api. This gem can be used to gather status
|
159
|
+
and download information from your sabnzb instance.
|
160
|
+
email: daniel@danielz.nl
|
161
|
+
executables: []
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files:
|
164
|
+
- LICENSE.txt
|
165
|
+
- README.rdoc
|
166
|
+
files:
|
167
|
+
- .autotest
|
168
|
+
- .document
|
169
|
+
- .rspec
|
170
|
+
- Gemfile
|
171
|
+
- Gemfile.lock
|
172
|
+
- LICENSE.txt
|
173
|
+
- README.rdoc
|
174
|
+
- Rakefile
|
175
|
+
- VERSION
|
176
|
+
- fixtures/vcr_cassettes/invalid_key.yml
|
177
|
+
- fixtures/vcr_cassettes/paused.yml
|
178
|
+
- fixtures/vcr_cassettes/simple_queue.yml
|
179
|
+
- fixtures/vcr_cassettes/slots.yml
|
180
|
+
- fixtures/vcr_cassettes/valid_key.yml
|
181
|
+
- lib/sabnzbd.rb
|
182
|
+
- lib/sabnzbd/slot.rb
|
183
|
+
- spec/sabnzbd_spec.rb
|
184
|
+
- spec/spec_helper.rb
|
185
|
+
homepage: http://github.com/DanielZwijnenburg/sabnzbd
|
186
|
+
licenses:
|
187
|
+
- MIT
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
segments:
|
199
|
+
- 0
|
200
|
+
hash: -3423079978625530037
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
|
+
none: false
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
requirements: []
|
208
|
+
rubyforge_project:
|
209
|
+
rubygems_version: 1.8.24
|
210
|
+
signing_key:
|
211
|
+
specification_version: 3
|
212
|
+
summary: Ruby wrapper for the sabnzbd api.
|
213
|
+
test_files: []
|