Class: Rocksky::Agent
- Inherits:
-
Object
- Object
- Rocksky::Agent
- Defined in:
- lib/rocksky.rb
Overview
---- authenticated agent ----
Records are passed as Hashes with camelCase keys (title, artist, album, albumArtist, durationMs, …), matching the wire record shape.
Class Method Summary collapse
-
.login(session_path, identifier, password, appview: nil, dedup_path: nil) ⇒ Object
dedup_pathenables the local dedup index (needed for #sync_repo / #hydrate_from_jetstream).
Instance Method Summary collapse
-
#close ⇒ Object
Release the native handle.
- #follow(did) ⇒ Object
-
#hydrate_from_jetstream ⇒ Object
Keep the local dedup index hydrated from Jetstream in the background.
-
#initialize(ptr) ⇒ Agent
constructor
A new instance of Agent.
- #like(uri, cid) ⇒ Object
- #refresh_session ⇒ Object
-
#reply_shout_with_gif(subject_uri, subject_cid, parent_uri, parent_cid, message: nil, gif: nil) ⇒ Object
Reply to a shout with an optional GIF/sticker/clip attachment.
-
#scrobble(track) ⇒ Object
Scrobble a play; fans out to artist/album/song/scrobble.
-
#scrobble_match(input) ⇒ Object
Scrobble from just a title + artist (album optional, plus optional mb_id / isrc anchors): resolve full metadata via matchSong, then fan out.
- #shout(subject_uri, subject_cid, message) ⇒ Object
-
#shout_with_gif(subject_uri, subject_cid, message: nil, gif: nil) ⇒ Object
Post a shout with an optional GIF/sticker/clip attachment.
-
#sync_repo ⇒ Object
Download the caller's repo and (re)build the local dedup index (needs a dedup_path at login).
Constructor Details
#initialize(ptr) ⇒ Agent
Returns a new instance of Agent.
220 221 222 |
# File 'lib/rocksky.rb', line 220 def initialize(ptr) @ptr = ptr end |
Class Method Details
.login(session_path, identifier, password, appview: nil, dedup_path: nil) ⇒ Object
dedup_path enables the local dedup index (needed for #sync_repo /
#hydrate_from_jetstream).
213 214 215 216 217 218 |
# File 'lib/rocksky.rb', line 213 def self.login(session_path, identifier, password, appview: nil, dedup_path: nil) ptr = C.rocksky_agent_login(session_path, identifier, password, appview.to_s, dedup_path.to_s) raise Error, (Rocksky.take_string(C.rocksky_last_error()) || "login failed") if ptr.null? new(ptr) end |
Instance Method Details
#close ⇒ Object
Release the native handle. The agent is unusable afterwards.
286 287 288 289 290 291 |
# File 'lib/rocksky.rb', line 286 def close return if @ptr.null? C.rocksky_agent_free(@ptr) @ptr = Fiddle::Pointer.new(0) end |
#follow(did) ⇒ Object
255 256 257 |
# File 'lib/rocksky.rb', line 255 def follow(did) Rocksky.unwrap(C.rocksky_agent_follow(@ptr, did)) end |
#hydrate_from_jetstream ⇒ Object
Keep the local dedup index hydrated from Jetstream in the background.
247 248 249 |
# File 'lib/rocksky.rb', line 247 def hydrate_from_jetstream Rocksky.unwrap(C.rocksky_agent_hydrate_from_jetstream(@ptr)) end |
#like(uri, cid) ⇒ Object
251 252 253 |
# File 'lib/rocksky.rb', line 251 def like(uri, cid) Rocksky.unwrap(C.rocksky_agent_like(@ptr, uri, cid)) end |
#refresh_session ⇒ Object
281 282 283 |
# File 'lib/rocksky.rb', line 281 def refresh_session Rocksky.unwrap(C.rocksky_agent_refresh_session(@ptr)) end |
#reply_shout_with_gif(subject_uri, subject_cid, parent_uri, parent_cid, message: nil, gif: nil) ⇒ Object
Reply to a shout with an optional GIF/sticker/clip attachment. Semantics match #shout_with_gif, plus a parent strong-ref (+parent_uri+/+parent_cid+).
274 275 276 277 278 279 |
# File 'lib/rocksky.rb', line 274 def reply_shout_with_gif(subject_uri, subject_cid, parent_uri, parent_cid, message: nil, gif: nil) Rocksky.unwrap(C.rocksky_agent_reply_shout_with_gif( @ptr, subject_uri, subject_cid, parent_uri, parent_cid, .to_s, gif ? JSON.generate(gif) : "" )) end |
#scrobble(track) ⇒ Object
Scrobble a play; fans out to artist/album/song/scrobble. Returns the URIs.
225 226 227 |
# File 'lib/rocksky.rb', line 225 def scrobble(track) Rocksky.unwrap(C.rocksky_agent_scrobble(@ptr, JSON.generate(track))) end |
#scrobble_match(input) ⇒ Object
Scrobble from just a title + artist (album optional, plus optional mb_id /
isrc anchors): resolve full metadata via matchSong, then fan out.
Scrobble from just a title + artist. input is a Hash with camelCase keys:
required "title"/"artist"; optional "album", "mbId", "isrc" (match anchors),
and "timestamp" (scrobbled-at Unix seconds, default now).
agent.scrobble_match("title" => "Chaser", "artist" => "Calibro 35")
236 237 238 |
# File 'lib/rocksky.rb', line 236 def scrobble_match(input) Rocksky.unwrap(C.rocksky_agent_scrobble_match(@ptr, JSON.generate(input))) end |
#shout(subject_uri, subject_cid, message) ⇒ Object
259 260 261 |
# File 'lib/rocksky.rb', line 259 def shout(subject_uri, subject_cid, ) Rocksky.unwrap(C.rocksky_agent_shout(@ptr, subject_uri, subject_cid, )) end |
#shout_with_gif(subject_uri, subject_cid, message: nil, gif: nil) ⇒ Object
Post a shout with an optional GIF/sticker/clip attachment. Pass at least
one of message / gif. gif is a Hash with camelCase keys ("url"
required, plus "previewUrl", "alt", "width", "height").
266 267 268 269 270 |
# File 'lib/rocksky.rb', line 266 def shout_with_gif(subject_uri, subject_cid, message: nil, gif: nil) Rocksky.unwrap(C.rocksky_agent_shout_with_gif( @ptr, subject_uri, subject_cid, .to_s, gif ? JSON.generate(gif) : "" )) end |