Class: Hallon::AlbumBrowse

Inherits:
Base
  • Object
show all
Extended by:
Observable::AlbumBrowse
Includes:
Loadable
Defined in:
lib/hallon/album_browse.rb

Overview

AlbumBrowse objects are for retrieving additional data from an album that cannot otherwise be acquired. This includes tracks, reviews, copyright information.

Defined Under Namespace

Classes: Copyrights, Tracks

Instance Attribute Summary

Attributes inherited from Base

#pointer

Instance Method Summary collapse

Methods included from Observable::AlbumBrowse

extended, initialize_callbacks, load_callback

Methods included from Loadable

#load

Methods inherited from Base

#==, from, from_link, #is_linkable?, #session, to_link, #to_pointer, #to_s

Constructor Details

#initialize(album) ⇒ AlbumBrowse

Note:

Also Hallon::Album#browse to browse an Album.

Creates an AlbumBrowse instance from an Album or an Album pointer.

Raises:

  • (FFI::NullPointerError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/hallon/album_browse.rb', line 35

def initialize(album)
  pointer = album
  pointer = pointer.pointer if pointer.respond_to?(:pointer)

  unless pointer.is_a?(Spotify::Album)
    given = pointer.respond_to?(:type) ? pointer.type : pointer.inspect
    raise TypeError, "expected album pointer, was given #{given}"
  end

  subscribe_for_callbacks do |callback|
    @pointer = Spotify.albumbrowse_create(session.pointer, pointer, callback, nil)
  end

  raise FFI::NullPointerError, "album browsing failed" if @pointer.null?
end

Instance Method Details

#albumAlbum?



74
75
76
77
# File 'lib/hallon/album_browse.rb', line 74

def album
  album = Spotify.albumbrowse_album(pointer)
  Album.from(album)
end

#artistArtist?



68
69
70
71
# File 'lib/hallon/album_browse.rb', line 68

def artist
  artist = Spotify.albumbrowse_artist(pointer)
  Artist.from(artist)
end

#copyrightsCopyrights



88
89
90
# File 'lib/hallon/album_browse.rb', line 88

def copyrights
  Copyrights.new(self)
end

#loaded?Boolean



52
53
54
# File 'lib/hallon/album_browse.rb', line 52

def loaded?
  Spotify.albumbrowse_is_loaded(pointer)
end

#request_durationRational

Note:

If the object is not loaded, the result is undefined.

Returns time it took for the albumbrowse request to complete (in seconds).



81
82
83
84
85
# File 'lib/hallon/album_browse.rb', line 81

def request_duration
  duration = Spotify.albumbrowse_backend_request_duration(pointer)
  duration = 0 if duration < 0
  Rational(duration, 1000)
end

#reviewString



63
64
65
# File 'lib/hallon/album_browse.rb', line 63

def review
  Spotify.albumbrowse_review(pointer)
end

#statusSymbol

Returns album browser error status.

See Also:

  • Error.explain


58
59
60
# File 'lib/hallon/album_browse.rb', line 58

def status
  Spotify.albumbrowse_error(pointer)
end

#tracksTracks



93
94
95
# File 'lib/hallon/album_browse.rb', line 93

def tracks
  Tracks.new(self)
end