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.



102
103
104
# File 'lib/rocksky.rb', line 102

def initialize(ptr)
  @ptr = ptr
end

Class Method Details

.login(session_path, identifier, password, appview: nil) ⇒ Object

Raises:



95
96
97
98
99
100
# File 'lib/rocksky.rb', line 95

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



128
129
130
131
132
133
# File 'lib/rocksky.rb', line 128

def close
  return if @ptr.null?

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

#follow(did) ⇒ Object



115
116
117
# File 'lib/rocksky.rb', line 115

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

#like(uri, cid) ⇒ Object



111
112
113
# File 'lib/rocksky.rb', line 111

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

#refresh_sessionObject



123
124
125
# File 'lib/rocksky.rb', line 123

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.



107
108
109
# File 'lib/rocksky.rb', line 107

def scrobble(track)
  Rocksky.unwrap(C.rocksky_agent_scrobble(@ptr, JSON.generate(track)))
end

#shout(subject_uri, subject_cid, message) ⇒ Object



119
120
121
# File 'lib/rocksky.rb', line 119

def shout(subject_uri, subject_cid, message)
  Rocksky.unwrap(C.rocksky_agent_shout(@ptr, subject_uri, subject_cid, message))
end