Transmission::RPC::Client
A client for the Transmission BitTorrent RPC API.
Speaks both Transmission dialects (see {Protocol}): the JSON-RPC 2.0
modern protocol of 4.1.0+ and the classic protocol understood by every
version (the only one 4.0.x speaks). The public API is snake_case
throughout regardless of dialect; classic translation happens internally
via {ClassicCodec}.
By default the client auto-detects the daemon's dialect on its first call
(probing once and caching the result). Pass protocol: to force one.
Built on json-rpc: a
{SessionTransport} handles the X-Transmission-Session-Id CSRF dance
(shared by both dialects), and a JSON::RPC::Client handles the modern
envelope.
client = Transmission::RPC::Client.new(
"http://nas.local:9091/transmission/rpc",
username: "admin", password: "secret")
client.torrent_get.each do |torrent|
puts "#{torrent.name}: #{torrent.state}"
end
Constants
A sensible default set of fields to request from torrent_get. Covers
everything in the {Torrent} struct's commonly used attributes.
The default RPC endpoint exposed by a stock Transmission daemon.
Constructors
Builds a client speaking to url, optionally with HTTP Basic auth.
protocol selects the dialect; the default {Protocol::Auto} probes the
daemon on first use.
Builds a client over an existing JSON-RPC client. Useful for injecting a custom or stubbed transport.
Instance methods
Reports free and total space for the filesystem containing path.
Retrieves bandwidth group settings. Pass name (a string or array of
strings) to fetch specific groups; omit for all. Returned as raw
JSON::Any.
Updates a bandwidth group's settings, creating it if necessary.
Tests whether the peer port is reachable. ip_protocol may be "ipv4"
or "ipv6".
The configured protocol mode. {Protocol::Auto} resolves to {Protocol::Modern} or {Protocol::Classic} on the first call.
The dialect resolved by auto-detection, or nil until the first call
under {Protocol::Auto}. When protocol is forced this mirrors it.
Retrieves session settings. Pass fields to fetch a subset; omit for
all settings. Returned as raw JSON::Any given the large, evolving set
of session fields.
Updates session settings. Pass any mutable setting as a keyword
argument, e.g. session_set(speed_limit_down: 100, speed_limit_down_enabled: true).
Adds a torrent from a .torrent file path/URL (filename) or from
base64-encoded torrent contents (metainfo). Exactly one is required.
Returns the added (or, if already present, duplicate) torrent.
Retrieves torrents, parsed into {Torrent} structs.
ids: a single id/hash, an array of them, ornilfor all torrents.fields: the fields to fetch (defaults to {DEFAULT_FIELDS}).recently_active: true: fetch only recently active torrents.table: true: request the compact"table"response format (arrays instead of per-field objects) — a smaller payload for large result sets. The rows are reassembled into {Torrent}s transparently.
Like {#torrent_get} but returns the raw JSON::Any result, for fields
not covered by the {Torrent} struct. With table: true the torrents
member is in Transmission's table layout (a header row followed by value
rows).
Asks the given torrents to re-announce to their trackers immediately.
Removes the given torrents, optionally deleting their downloaded data.
Renames a file or directory within a single torrent. path is the
current path within the torrent; name is the new name.
Sets properties on the given torrents. Pass any mutable field as a
keyword argument, e.g.
torrent_set(ids, labels: ["a"], upload_limit: 50, upload_limited: true).
Moves the given torrents' data to location. With move: true the
files are moved; with move: false Transmission searches location for
already-present files.
Starts the given torrents (all torrents when ids is nil). With
now: true, bypasses the download queue (torrent_start_now).