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.



160
161
162
# File 'lib/rocksky.rb', line 160

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:



153
154
155
156
157
158
# File 'lib/rocksky.rb', line 153

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.



208
209
210
211
212
213
# File 'lib/rocksky.rb', line 208

def close
  return if @ptr.null?

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

#follow(did) ⇒ Object



195
196
197
# File 'lib/rocksky.rb', line 195

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.



187
188
189
# File 'lib/rocksky.rb', line 187

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

#like(uri, cid) ⇒ Object



191
192
193
# File 'lib/rocksky.rb', line 191

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

#refresh_sessionObject



203
204
205
# File 'lib/rocksky.rb', line 203

def refresh_session
  Rocksky.unwrap(C.rocksky_agent_refresh_session(@ptr))
end

#scrobble(track) ⇒ Object

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



165
166
167
# File 'lib/rocksky.rb', line 165

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


176
177
178
# File 'lib/rocksky.rb', line 176

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

#shout(subject_uri, subject_cid, message) ⇒ Object



199
200
201
# File 'lib/rocksky.rb', line 199

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



182
183
184
# File 'lib/rocksky.rb', line 182

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