Class: SabnzbdPlusModelApi::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/sabnzbd_plus/model/api/api.rb

Overview

The SABnzbd+ API

Instance Method Summary (collapse)

Constructor Details

- (Api) initialize(caller = SabnzbdPlusModelApiCaller::HttpJson.new)

Set-up the Caller to use. Defaults to the HttpJson Caller

Parameters:



12
13
14
# File 'lib/sabnzbd_plus/model/api/api.rb', line 12

def initialize(caller = SabnzbdPlusModelApiCaller::HttpJson.new)
  @caller = caller
end

Instance Method Details

- (Hash<String, String>, ...) addid(options = {})

pp, script, cat and priority are all optional. This example will retrieve the newzbin post "33333" and instert it at low priority in the queue, assigned with a categoriy of "Example", to execute "customscript.cmd" once

finished, and with the unpacking option 3 (Repair, Unpack and Delete)

Added in 0.3 Priority added in 0.5

Examples:

Full

addid({:name=>333333, :pp=> 3, :script=>"customscript.cmd", :cat=>"Example", :priority=>-1})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :name (String)
  • :pp (String)
  • :script (String)
  • :cat (String)
  • :priority (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


476
477
478
# File 'lib/sabnzbd_plus/model/api/api.rb', line 476

def addid(options = {})
  return @caller.call("addid", options)
end

- (Hash<String, String>, ...) addlocalfile(options = {})

Allows uploading of nzb/rar/zip/gz files by simply providing a local path (has to be accessable by the machine running SABnzbd

Added in 0.3 Priority added in 0.5

Examples:

Example

addlocalfile({:name=>"full/local/path/to/file.ext", :pp=> 1, :script=>"script.cmd", :priority=>-1})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :name (String)
  • :pp (String)
  • :script (String)
  • :cat (String)
  • :priority (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


497
498
499
# File 'lib/sabnzbd_plus/model/api/api.rb', line 497

def addlocalfile(options = {})
  return @caller.call("addlocalfile", options)
end

- (Hash<String, String>, ...) addurl(options = {})

pp, script, cat and priority are all optional. This example adds the nzb into the queue marked as low priority, assigned with a categoriy of "Example", to execute "customscript.cmd" once finished, and with the unpacking option 3 (Repair, Unpack and Delete)

Allows full newzbin and nzbmatrix links (no need to parse out the ID).

Added in 0.3 Priority added in 0.5

Examples:

Shortest

addurl({:name => "http://www.example.com/example.nzb", :nzbname=> "NiceName" })

Full

addurl({:name=>"http://www.example.com/example.nzb", :pp=> 3, :script=>"customscript.cmd", :cat=>"Example", :priority=>-1, :nzbname=>"NiceName"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :name (String)
  • :nzbname (String)
  • :pp (String)
  • :script (String)
  • :cat (String)
  • :priority (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


453
454
455
# File 'lib/sabnzbd_plus/model/api/api.rb', line 453

def addurl(options = {})
  return @caller.call("addurl", options)
end

- (Hash<String, String>, ...) change_cat(options = {})

Added in 0.4

Examples:

Example

change_cat({:value=>"SABnzbd_nzo_zt2syz", :value2=> "Example"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)
  • :value2 (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


525
526
527
# File 'lib/sabnzbd_plus/model/api/api.rb', line 525

def change_cat(options = {})
  return @caller.call("change_cat", options)
end

- (Hash<String, String>, ...) change_opts(options = {})

Change value2 to control what post-processing option to use

Added in 0.5

Skip: 0 Repair: 1 Repair/Unpack: 2 Repair/Unpack/Delete: 3

Examples:

Example

change_opts({:value=>"SABnzbd_nzo_zt2syz", :value2=> 0})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)
  • :value2 (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


546
547
548
# File 'lib/sabnzbd_plus/model/api/api.rb', line 546

def change_opts(options = {})
  return @caller.call("change_opts", options)
end

- (Hash<String, String>, ...) change_script(options = {})

Added in 0.4

Examples:

Example

change_script({:value=>"SABnzbd_nzo_zt2syz", :value2=> "examplescript.cmd"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)
  • :value2 (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


511
512
513
# File 'lib/sabnzbd_plus/model/api/api.rb', line 511

def change_script(options = {})
  return @caller.call("change_script", options)
end

- (Hash<String, String>, ...) config(options = {})

Pauses for a set amount of time (value is the time in minutes to pause the queue)

Added in 0.5

Returns the new API Key

Examples:

Temporary Pause

config({:name => "set_pause", :value => 60})

Set Download Speed limit

config({:name => "speedlimit", :value => 400})

Regenerate new API Key

config({:name => "set_apikey"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :name (String)
  • :value (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


405
406
407
# File 'lib/sabnzbd_plus/model/api/api.rb', line 405

def config(options = {})
  return @caller.call("config", options)
end

- (Hash<String, String>, ...) get_cats

Current categories

Added in 0.4

Examples:

Example Return Data

{"categories"=>["None","Video"]}

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


323
324
325
# File 'lib/sabnzbd_plus/model/api/api.rb', line 323

def get_cats
  return @caller.call("get_cats", {})
end

- (Hash<String, String>, ...) get_files(options = {})

Retrieve Contents of Queue item

Added in 0.5

Examples:

Example

get_files({:value=>"SABnzbd_nzo_zt2syz"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


561
562
563
# File 'lib/sabnzbd_plus/model/api/api.rb', line 561

def get_files(options = {})
  return @caller.call("get_files", options)
end

- (Hash<String, String>, ...) get_scripts

Return Scripts

Added in 0.4

Examples:

Example Return Data

{"scripts":["None","examplescript.cmd"]}

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


334
335
336
# File 'lib/sabnzbd_plus/model/api/api.rb', line 334

def get_scripts
  return @caller.call("get_scripts", {})
end

- (Hash<String, String>, ...) history(params = {})

A verbose output that as well as reporting items in the queue, will report on finished items being processed (verify/repaired/extracted) and other details such as categories, scripts.

Added in 0.5

Added in 0.3

Examples:

Listing history

history()

Deleting a single item

history({:name => "delete", :value => "SABnzbd_nzo_zt2syz"})

Deleting multiple items

history({:name => "delete", :value => "SABnzbd_nzo_zt2syz,SABnzbd_nzo_df2hyd,SABnzbd_nzo_op3shf"})

Deleting all items

history({:name => "delete", :value => "all"})

Retry a single item

history({:name => "retry", :value => "SABnzbd_nzo_zt2syz"})

Example Return Data

{
    "total_size" =>  40.30 GB,       **Since 0.5.2
    "month_size" =>  20.23 GB,      **Since 0.5.2
    "week_size" =>  5.12 GB,         **Since 0.5.2
    "cache_limit" => "-1",
    "paused" => true,
    "new_rel_url" => "",
    "restart_req" => false,
    "slots" => [
    {
        "action_line" => "",
        "show_details" => "True",
        "script_log" => "",
        "meta" => nil,
        "fail_message" => "",
        "loaded" => false,
        "id" => 605,
        "size" => "778.1 MB",
        "category" => "Apps",
        "pp" => "D",
        "completeness" => 0,
        "script" => "",
        "nzb_name" => "Ubuntu.nzb",
        "download_time" => 567,
        "storage" => "X:\\Apps\\Ubuntu",
        "status" => "Completed",
        "script_line" => "",
        "completed" => 1236646078,
        "nzo_id" => "SABnzbd_nzo_ipet0h",
        "downloaded" => 815878352,
        "report" => "000000",
        "path" => "Ubuntu",
        "postproc_time" => 368,
        "name" => "Ubuntu",
        "url" => "https://newzbin.com/browse/post/000000/",
        "bytes" => 815878352,
        "url_info" => "http://google.com",
        "stage_log" => [
            {"name" => "download","actions" => ["Downloaded in 9 minutes 27 seconds at an average of 1404kB/s"]},
            {"name" => "repair","actions" => ["[ubuntu] Repaired in 4 minutes 24 seconds","[ubuntu.sample] Quick Check OK"]},
            {"name" => "unpack","actions" => ["[ubuntu] Unpacked 1 file/folder in 36 seconds"]}
        ]
    }],
    "helpuri" => "http://wiki.sabnzbd.org/",
    "uptime" => "12m",
    "version" => "trunk",
    "diskspacetotal2" => "503.32",
    "color_scheme" => "",
    "darwin" => false,
    "nt" => true,
    "status" => "Paused",
    "last_warning" => "",
    "have_warnings" => "0",
    "cache_art" => "0",
    "finishaction" => null,
    "noofslots" => 516,
    "cache_size" => "0",
    "new_release" => "",
    "pause_int" => "0",
    "mbleft" => "785.89",
    "diskspace2" => "25.08",
    "diskspace1" => "25.08",
    "diskspacetotal1" => "503.32",
    "timeleft" => "0:00:00",
    "mb" => "785.89",
    "eta" => "unknown",
    "nzb_quota" => "",
    "loadavg" => "",
    "kbpersec" => "0.00",
    "speedlimit" => "0",
    "webdir" => "path\\to\\templates"
}

Parameters:

  • params (Hash) (defaults to: {})

    the options to create a make the call with.

Options Hash (params):

  • :name (String)
  • :value (String)
  • :start (String)
  • :limit (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


281
282
283
# File 'lib/sabnzbd_plus/model/api/api.rb', line 281

def history(params = {})
  return @caller.call("history", params)
end

- (Hash<String, String>, ...) pause

Pauses the whole queue (do not confuse this will pausing an individual download, this is a global pause)

Added in 0.3

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


381
382
383
# File 'lib/sabnzbd_plus/model/api/api.rb', line 381

def pause
  return @caller.call("pause", {})
end

- (Hash<String, String>, ...) qstatus

Depreciated now by the advanced queue output, this is the old api that just provides limited details on the current queue and state of sabnzbd

Added in 0.3

Examples:

Example Return Data

{
    "timeleft" => "0:00:00",
    "mb" => 854.697841,
    "noofslots" => 1,
    "paused" => true,
    "mbleft" => 854.697841,
    "diskspace2" => 21.980682,
    "diskspace1" => 21.980682,
    "kbpersec" => 0.000000,
    "jobs" => [
        {"msgid" => "3066202",
        "filename" =>
        "Ubuntu 8.04 (Hardy Heron) - Desktop CD x64",
        "mbleft" => 854.697841,"id" => "SABnzbd_nzo_zt2syz",
        "mb" => 854.697841}
    ]
}

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


41
42
43
# File 'lib/sabnzbd_plus/model/api/api.rb', line 41

def qstatus
  return @caller.call("qstatus", {})
end

- (Hash<String, String>, ...) queue(options = {})

A verbose output that as well as reporting items in the queue, will report on finished items being processed (verify/repaired/extracted) and other details such as categories, scripts.

Added in 0.5

Added in 0.3

Added in 0.5

Low Priority: -1 Normal Priority: 0 High Priority: 1 Will return the new position in the queue if successful.

Changes the name of an item in the queue. The name is used for the final foldername, and input for any post-processing sorting, if used.

Added in 0.5

prefix script_ to the script name to execute

Added in 0.4

Examples:

Listing history

queue()

Deleting a single item

queue({:name => "delete", :value => "SABnzbd_nzo_zt2syz"})

Deleting multiple items

queue({:name => "delete", :value => "SABnzbd_nzo_zt2syz,SABnzbd_nzo_df2hyd,SABnzbd_nzo_op3shf"})

Deleting all items

queue({:name => "delete", :value => "all"})

Change Priority

queue({:name => "priority", :value => "SABnzbd_nzo_zt2syz", :value2 => 0})

Change item name

queue({:name => "rename", :value => "SABnzbd_nzo_zt2syz", :value2 => "THENEWNAME"})

Pause individual download

queue({:name => "pause", :value => "SABnzbd_nzo_zt2syz"})

Resume individual download

queue({:name => "resume", :value => "SABnzbd_nzo_zt2syz"})

Action on queue complete

queue({:name => "change_complete_action", :value => "hybernate_pc"})

Script action on queue complete

queue({:name => "change_complete_action", :value => "script_examplescript.cmd"})

Example Return Data

{
    "cache_limit" => "-1",
    "categories" => [
            "None",
            "apps",
            "books",
            "consoles",
            "emulation",
            "games",
            "misc",
            "movies",
            "music",
            "pda",
            "resources",
            "tv"
            ],
    "scripts" => [
            "None"
            ],
    "paused" => true,
    "new_rel_url" => "",
    "restart_req" => false,
    "slots" => [
        {
        "status" => "Queued",
        "index" => 0,
        "eta" => "unknown",
        "timeleft" => "0:00:00",
        "avg_age" => "43d",
        "script" => "None",
        "msgid" => "4295398",
        "verbosity" => "",
        "mb" => "785.89",
        "filename" => "Ubuntu v.8.10",
        "priority" => "Normal",
        "cat" => "Apps",
        "mbleft" => "785.89",
        "percentage" => "0",
        "nzo_id" => "SABnzbd_nzo_wgmb1m",
        "unpackopts" => "3",
        "size" => "785.9 MB"
        }],
    "helpuri" => "http://wiki.sabnzbd.org/",
    "uptime" => "6m",
    "refresh_rate" => "",
    "isverbose" => false,
    "start" => 0,
    "version" => "trunk",
    "diskspacetotal2" => "503.32",
    "color_scheme" => "",
    "darwin" => false,
    "nt" => true,
    "status" => "Paused",
    "last_warning" => "",
    "have_warnings" => "0",
    "cache_art" => "0",
    "finishaction" => null,
    "noofslots" => 1,
    "cache_size" => "0",
    "finish" => 0,
    "new_release" => "",
    "pause_int" => "0"
    ,"mbleft" => "785.89",
    "diskspace2" => "25.08",
    "diskspace1" => "25.08",
    "diskspacetotal1" => "503.32",
    "timeleft" => "0:00:00",
    "mb" => "785.89",
    "newzbinDetails" => true,
    "eta" => "unknown",
    "nzb_quota" => "",
    "loadavg" => "",
    "limit" => 0,
    "kbpersec" => "0.00",
    "speedlimit" => "0",
    "webdir" => "path\\to\\templates",
    "queue_details" => "0"
}

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :name (String)
  • :value (String)
  • :value2 (String)
  • :start (String)
  • :limit (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


178
179
180
# File 'lib/sabnzbd_plus/model/api/api.rb', line 178

def queue(options = {})
  return @caller.call("queue", options)
end

- (Hash<String, String>, ...) restart

Restart SABnzbd

Added in 0.5

Examples:

Example Return Data

"ok
"

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


346
347
348
# File 'lib/sabnzbd_plus/model/api/api.rb', line 346

def restart
  return @caller.call("restart", {})
end

- (Hash<String, String>, ...) resume

Resumes the whole queue (do not confuse this will resuming an individual download, this is a global resume)Resumes the whole queue (do not confuse this will resuming an individual download, this is a global resume)

Added in 0.3

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


416
417
418
# File 'lib/sabnzbd_plus/model/api/api.rb', line 416

def resume
  return @caller.call("resume", {})
end

- (Hash<String, String>, ...) retry(options = {})

Added in 0.6.0 Retry a single item

Examples:

Example

retry({:value=>"SABnzbd_nzo_zt2syz"})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


575
576
577
# File 'lib/sabnzbd_plus/model/api/api.rb', line 575

def retry(options = {})
  return @caller.call("retry", options)
end

- (Hash<String, String>, ...) shutdown

Shuts down SABnzbd.

Added in 0.3

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


425
426
427
# File 'lib/sabnzbd_plus/model/api/api.rb', line 425

def shutdown
  return @caller.call("shutdown", {})
end

- (Hash<String, String>, ...) switch(options = {})

Moving two items

0.5 - Will return the new position and priority (space separated, can be -1 if error occurs) "value" is the item you want to move, "value2" is the name of the item where you want to put value one above, shifting value2 down.

"value2" is the position in the queue where you wish to move the object. 0 is the top of the queue, 1 is the second item, etc..

Examples:

Swapping two items

switch({:value => "SABnzbd_nzo_zt2syz",:value2 => "SABnzbd_nzo_df2hyd"})

Moving to a specific location in the queue.

switch({:value => "SABnzbd_nzo_zt2syz",:value2 => 0})

Parameters:

  • options (Hash) (defaults to: {})

    the options to make the call with.

Options Hash (options):

  • :value (String)
  • :value2 (String)

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


371
372
373
# File 'lib/sabnzbd_plus/model/api/api.rb', line 371

def switch(options = {})
  return @caller.call("switch", options)
end

- (Hash<String, String>, ...) version

Get the version

Added in 0.4

Examples:

Example Return Data

{"version" => "0.4.6"}

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


292
293
294
# File 'lib/sabnzbd_plus/model/api/api.rb', line 292

def version
  return @caller.call("version", {})
end

- (Hash<String, String>, ...) warnings

Current warnings

Added in 0.4

Examples:

Example Return Data

{
   "warnings" => [
       "2008-12-26 19:53:42,567\nWARNING\n[decoder] Badly formed yEnc article in <Article: article=, bytes=, partnum=, art_id=>",
       "2008-12-26 19:54:45,861\nWARNING\n[assembler] <Article: article=, bytes=, partnum=, art_id=> missing",
       "2008-12-26 20:44:28,336\nWARNING\n[decoder] CRC Error in <Article: article=, bytes=, partnum=, art_id=> (4134546D -> A8F07173)",
       "2008-12-27 01:13:37,349\nWARNING\n[downloader] Thread 3@news.powerusenet.com:119: timed out",
       "2008-12-27 01:13:38,365\nWARNING\n[downloader] Thread 2@news.powerusenet.com:119: timed out",
       "2008-12-27 01:45:34,041\nWARNING\n[downloader] Thread 1@news.powerusenet.com:119: timed out"
   ]
}

Returns:

  • (Hash<String, String>, Hash<String, Boolean>, Hash<String, Integer>, Hash<String, Hash>)


312
313
314
# File 'lib/sabnzbd_plus/model/api/api.rb', line 312

def warnings
  return @caller.call("warnings", {})
end