Module: Rocksky
- Defined in:
- lib/rocksky.rb,
lib/rocksky/native.rb,
lib/rocksky/library.rb,
lib/rocksky/version.rb
Defined Under Namespace
Modules: Native Classes: Agent, Error, Library
Constant Summary collapse
- VERSION =
"0.7.0"
Class Method Summary collapse
-
.get(nsid, params = {}, base: nil, token: nil) ⇒ Object
Universal read escape hatch — call any app.rocksky.* query by nsid.
- .global_stats(base: nil) ⇒ Object
-
.library(token, base: nil) ⇒ Object
Build an authenticated app.rocksky.library.* (uploaded-music) client.
-
.match_song(title, artist, mb_id: nil, isrc: nil, base: nil) ⇒ Object
Resolve full canonical metadata for a bare title + artist (matchSong).
-
.profile(actor, base: nil) ⇒ Object
---- reads (unauthenticated; base: overrides the AppView URL) ----.
- .scrobbles(actor, limit: 50, offset: 0, base: nil) ⇒ Object
-
.song_hash(title, artist, album) ⇒ Object
Identity hash — identical across every Rocksky SDK.
-
.take_string(ptr) ⇒ Object
Copy an owned C string into a Ruby string and free the original.
-
.top_artists_interval(limit: 50, offset: 0, interval: :all, base: nil) ⇒ Object
Top artists chart over a typed date window (see .top_tracks_interval).
- .top_tracks(limit: 50, offset: 0, base: nil) ⇒ Object
-
.top_tracks_interval(limit: 50, offset: 0, interval: :all, base: nil) ⇒ Object
Top tracks chart over a typed date window.
-
.unwrap(ptr) ⇒ Object
Parse a
{"ok"|"error"}envelope, raising Error on failure.
Class Method Details
.get(nsid, params = {}, base: nil, token: nil) ⇒ Object
Universal read escape hatch — call any app.rocksky.* query by nsid. params
is a hash of string params; the whole read-query catalog is reachable here.
Rocksky.get("app.rocksky.album.getAlbum", { uri: uri })
Rocksky.get("app.rocksky.charts.getScrobblesChart", { did: did })
token, when given, is sent as an Authorization: Bearer header — needed for
auth-gated queries.
101 102 103 |
# File 'lib/rocksky.rb', line 101 def self.get(nsid, params = {}, base: nil, token: nil) unwrap(C.rocksky_get(base.to_s, nsid, JSON.generate(params), token.to_s)) end |
.global_stats(base: nil) ⇒ Object
90 91 92 |
# File 'lib/rocksky.rb', line 90 def self.global_stats(base: nil) unwrap(C.rocksky_global_stats(base.to_s)) end |
.library(token, base: nil) ⇒ Object
Build an authenticated app.rocksky.library.* (uploaded-music) client. The token is required — every library method is auth-gated.
lib = Rocksky.library(token)
lib.get_song(song_id)
221 222 223 |
# File 'lib/rocksky.rb', line 221 def self.library(token, base: nil) Library.new(token, base: base) end |
.match_song(title, artist, mb_id: nil, isrc: nil, base: nil) ⇒ Object
Resolve full canonical metadata for a bare title + artist (matchSong).
106 107 108 |
# File 'lib/rocksky.rb', line 106 def self.match_song(title, artist, mb_id: nil, isrc: nil, base: nil) unwrap(C.rocksky_match_song(base.to_s, title, artist, mb_id.to_s, isrc.to_s)) end |
.profile(actor, base: nil) ⇒ Object
---- reads (unauthenticated; base: overrides the AppView URL) ----
78 79 80 |
# File 'lib/rocksky.rb', line 78 def self.profile(actor, base: nil) unwrap(C.rocksky_profile(base.to_s, actor)) end |
.scrobbles(actor, limit: 50, offset: 0, base: nil) ⇒ Object
82 83 84 |
# File 'lib/rocksky.rb', line 82 def self.scrobbles(actor, limit: 50, offset: 0, base: nil) unwrap(C.rocksky_scrobbles(base.to_s, actor, limit, offset)) end |
.song_hash(title, artist, album) ⇒ Object
Identity hash — identical across every Rocksky SDK.
142 143 144 |
# File 'lib/rocksky.rb', line 142 def self.song_hash(title, artist, album) take_string(C.rocksky_song_hash(title, artist, album)) end |
.take_string(ptr) ⇒ Object
Copy an owned C string into a Ruby string and free the original.
59 60 61 62 63 64 65 66 |
# File 'lib/rocksky.rb', line 59 def self.take_string(ptr) return nil if ptr.nil? || ptr.null? len = STRLEN.call(ptr) str = ptr[0, len].force_encoding("UTF-8") C.rocksky_string_free(ptr) str end |
.top_artists_interval(limit: 50, offset: 0, interval: :all, base: nil) ⇒ Object
Top artists chart over a typed date window (see .top_tracks_interval).
121 122 123 124 |
# File 'lib/rocksky.rb', line 121 def self.top_artists_interval(limit: 50, offset: 0, interval: :all, base: nil) unit, n, s, e = interval_parts(interval) unwrap(C.rocksky_top_artists_interval(base.to_s, limit, offset, unit, n, s, e)) end |
.top_tracks(limit: 50, offset: 0, base: nil) ⇒ Object
86 87 88 |
# File 'lib/rocksky.rb', line 86 def self.top_tracks(limit: 50, offset: 0, base: nil) unwrap(C.rocksky_top_tracks(base.to_s, limit, offset)) end |
.top_tracks_interval(limit: 50, offset: 0, interval: :all, base: nil) ⇒ Object
Top tracks chart over a typed date window. interval is :all, or a pair
like [:days, 7] / [:weeks, 4] / [:months, 1] / [:years, 1], or
[:range, start_rfc3339, end_rfc3339].
Rocksky.top_tracks_interval(limit: 10, interval: [:days, 7])
115 116 117 118 |
# File 'lib/rocksky.rb', line 115 def self.top_tracks_interval(limit: 50, offset: 0, interval: :all, base: nil) unit, n, s, e = interval_parts(interval) unwrap(C.rocksky_top_tracks_interval(base.to_s, limit, offset, unit, n, s, e)) end |
.unwrap(ptr) ⇒ Object
Parse a {"ok"|"error"} envelope, raising Error on failure.
69 70 71 72 73 74 |
# File 'lib/rocksky.rb', line 69 def self.unwrap(ptr) parsed = JSON.parse(take_string(ptr)) raise Error, parsed["error"] if parsed.key?("error") parsed["ok"] end |