Class: Rocksky::Agent

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(ptr) ⇒ Agent

Returns a new instance of Agent.



276
277
278
# File 'lib/rocksky.rb', line 276

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).

Raises:



269
270
271
272
273
274
# File 'lib/rocksky.rb', line 269

def self.(session_path, identifier, password, appview: nil, dedup_path: nil)
  ptr = C.(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

#closeObject

Release the native handle. The agent is unusable afterwards.



342
343
344
345
346
347
# File 'lib/rocksky.rb', line 342

def close
  return if @ptr.null?

  C.rocksky_agent_free(@ptr)
  @ptr = Fiddle::Pointer.new(0)
end

#follow(did) ⇒ Object



311
312
313
# File 'lib/rocksky.rb', line 311

def follow(did)
  Rocksky.unwrap(C.rocksky_agent_follow(@ptr, did))
end

#hydrate_from_jetstreamObject

Keep the local dedup index hydrated from Jetstream in the background.



303
304
305
# File 'lib/rocksky.rb', line 303

def hydrate_from_jetstream
  Rocksky.unwrap(C.rocksky_agent_hydrate_from_jetstream(@ptr))
end

#like(uri, cid) ⇒ Object



307
308
309
# File 'lib/rocksky.rb', line 307

def like(uri, cid)
  Rocksky.unwrap(C.rocksky_agent_like(@ptr, uri, cid))
end

#refresh_sessionObject



337
338
339
# File 'lib/rocksky.rb', line 337

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+).



330
331
332
333
334
335
# File 'lib/rocksky.rb', line 330

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,
                   message.to_s, gif ? JSON.generate(gif) : ""
                 ))
end

#scrobble(track) ⇒ Object

Scrobble a play; fans out to artist/album/song/scrobble. Returns the URIs.



281
282
283
# File 'lib/rocksky.rb', line 281

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")


292
293
294
# File 'lib/rocksky.rb', line 292

def scrobble_match(input)
  Rocksky.unwrap(C.rocksky_agent_scrobble_match(@ptr, JSON.generate(input)))
end

#shout(subject_uri, subject_cid, message) ⇒ Object



315
316
317
# File 'lib/rocksky.rb', line 315

def shout(subject_uri, subject_cid, message)
  Rocksky.unwrap(C.rocksky_agent_shout(@ptr, subject_uri, subject_cid, message))
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").



322
323
324
325
326
# File 'lib/rocksky.rb', line 322

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, message.to_s, gif ? JSON.generate(gif) : ""
                 ))
end

#sync_repoObject

Download the caller's repo and (re)build the local dedup index (needs a dedup_path at login). Returns the per-collection counts.



298
299
300
# File 'lib/rocksky.rb', line 298

def sync_repo
  Rocksky.unwrap(C.rocksky_agent_sync_repo(@ptr))
end