lib/sabnzbd.rb in sabnzbd-0.1.1 vs lib/sabnzbd.rb in sabnzbd-0.2.0

- old
+ new

@@ -1,35 +1,41 @@ require 'httparty' require 'sabnzbd/slot' +require 'sabnzbd/utils' class Sabnzbd attr_accessor :api_key, :base_uri - attr_reader :slots + attr_reader :slots, :utils include HTTParty def initialize(args={}) @api_key = args[:api_key] || (raise ApiKeyMissing.new, "Api key missing") @base_uri = args[:base_uri] || "localhost:8080" self.class.base_uri @base_uri + @utils = Sabnzbd::Utils.new(self) end - def simple_queue + def advanced_queue make_request end def paused? make_request["queue"]["paused"] end - def slots - @slots ||= initialize_slots + def speed + make_request["queue"]["speed"].strip end - private + def slots(refresh=false) + refresh ? @slots = initialize_slots : @slots ||= initialize_slots + end def make_request(url = "/api?mode=queue&start=START&limit=LIMIT&output=json&apikey=#{@api_key}") verify_response( self.class.get(url).parsed_response ) end + + private def verify_response response raise ApiKeyInvalid.new, "Api key invalid #{@api_key}" if response["status"] == false && response["error"] response \ No newline at end of file