Module: Rocksky
- Defined in:
- lib/rocksky.rb,
lib/rocksky/native.rb,
lib/rocksky/version.rb
Defined Under Namespace
Modules: Native Classes: Agent, Error
Constant Summary collapse
- VERSION =
"0.4.0"
Class Method Summary collapse
- .global_stats(base: nil) ⇒ Object
-
.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_tracks(limit: 50, offset: 0, base: nil) ⇒ Object
-
.unwrap(ptr) ⇒ Object
Parse a
{"ok"|"error"}envelope, raising Error on failure.
Class Method Details
.global_stats(base: nil) ⇒ Object
81 82 83 |
# File 'lib/rocksky.rb', line 81 def self.global_stats(base: nil) unwrap(C.rocksky_global_stats(base.to_s)) end |
.profile(actor, base: nil) ⇒ Object
---- reads (unauthenticated; base: overrides the AppView URL) ----
69 70 71 |
# File 'lib/rocksky.rb', line 69 def self.profile(actor, base: nil) unwrap(C.rocksky_profile(base.to_s, actor)) end |
.scrobbles(actor, limit: 50, offset: 0, base: nil) ⇒ Object
73 74 75 |
# File 'lib/rocksky.rb', line 73 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.
86 87 88 |
# File 'lib/rocksky.rb', line 86 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.
50 51 52 53 54 55 56 57 |
# File 'lib/rocksky.rb', line 50 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_tracks(limit: 50, offset: 0, base: nil) ⇒ Object
77 78 79 |
# File 'lib/rocksky.rb', line 77 def self.top_tracks(limit: 50, offset: 0, base: nil) unwrap(C.rocksky_top_tracks(base.to_s, limit, offset)) end |
.unwrap(ptr) ⇒ Object
Parse a {"ok"|"error"} envelope, raising Error on failure.
60 61 62 63 64 65 |
# File 'lib/rocksky.rb', line 60 def self.unwrap(ptr) parsed = JSON.parse(take_string(ptr)) raise Error, parsed["error"] if parsed.key?("error") parsed["ok"] end |