Permalink
Browse files

Add example app, refactor

  • Loading branch information...
1 parent 7f59552 commit db0eef3884182736b559fba659356c7b468e7a2f @Sutto committed Jan 8, 2009
Showing with 66 additions and 10 deletions.
  1. +1 −0 Rakefile
  2. +29 −0 SABnzbd.gemspec
  3. +20 −0 example/simple.rb
  4. +8 −5 lib/SABnzbd.rb
  5. +8 −5 lib/sabnzbd.rb
View
@@ -12,6 +12,7 @@ begin
s.homepage = "http://github.com/Sutto/SABnzbd"
s.description = "Ruby interface to the SABnzbd usenet client"
s.authors = ["Darcy Laycock"]
+ s.add_dependency 'httparty'
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
View
@@ -0,0 +1,29 @@
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{SABnzbd}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Darcy Laycock"]
+ s.date = %q{2009-01-08}
+ s.description = %q{Ruby interface to the SABnzbd usenet client}
+ s.email = %q{sutto@sutto.net}
+ s.homepage = %q{http://github.com/Sutto/SABnzbd}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.1}
+ s.summary = %q{Ruby interface to the SABnzbd usenet client}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 2
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
+ else
+ s.add_dependency(%q<httparty>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<httparty>, [">= 0"])
+ end
+end
View
@@ -0,0 +1,20 @@
+require 'rubygems'
+require 'pathname'
+require Pathname.new(__FILE__).dirname.parent.join('lib', 'sabnzbd')
+
+sab = SABnzbd.new(ENV['SAB_UN'] || "", ENV['SAB_PW'] || "") # If set, provide username and password
+
+status = sab.status
+
+puts "******************"
+puts "* SABnzbd Status *"
+puts "******************"
+
+print status.paused? ? "Currently paused" : "Currently running"
+puts " with #{status.queue_size} items in queue"
+puts ""
+puts "Queue Contents:"
+status.jobs.each_with_index do |job, idx|
+ percent = "%.2f%%" % [(1.0 - job.left / job.total)]
+ puts "#{idx + 1}) #{job.filename} - Total size is #{"%.2f" % [job.total]}MB - #{percent} done"
+end
View
@@ -4,9 +4,9 @@
class SABnzbd
class Job
- attr_accessor :id, :left, :done, :msgid, :filename
- def initialize(id, left, done, msgid, filename)
- self.id, self.left, self.done, self.msgid, self.filename = id, left, done, msgid, filename
+ attr_accessor :id, :left, :total, :msgid, :filename
+ def initialize(id, left, total, msgid, filename)
+ self.id, self.left, self.total, self.msgid, self.filename = id, left, total, msgid, filename
end
end
@@ -57,12 +57,15 @@ def parse_time(hash)
include HTTParty
base_uri 'localhost:8080'
- def initialize(username, password)
+ def initialize(username = '', password = '')
login(username, password)
end
def login(username, password)
- self.class.default_params :ma_username => username, :ma_password => password
+ opts = {}
+ opts[:ma_username] = username unless username.blank?
+ opts[:ma_password] = password unless password.blank?
+ self.class.default_params(opts)
end
def status
View
@@ -4,9 +4,9 @@
class SABnzbd
class Job
- attr_accessor :id, :left, :done, :msgid, :filename
- def initialize(id, left, done, msgid, filename)
- self.id, self.left, self.done, self.msgid, self.filename = id, left, done, msgid, filename
+ attr_accessor :id, :left, :total, :msgid, :filename
+ def initialize(id, left, total, msgid, filename)
+ self.id, self.left, self.total, self.msgid, self.filename = id, left, total, msgid, filename
end
end
@@ -57,12 +57,15 @@ def parse_time(hash)
include HTTParty
base_uri 'localhost:8080'
- def initialize(username, password)
+ def initialize(username = '', password = '')
login(username, password)
end
def login(username, password)
- self.class.default_params :ma_username => username, :ma_password => password
+ opts = {}
+ opts[:ma_username] = username unless username.blank?
+ opts[:ma_password] = password unless password.blank?
+ self.class.default_params(opts)
end
def status

0 comments on commit db0eef3

Please sign in to comment.