Class: Hallon::ArtistBrowse

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

Overview

An ArtistBrowse object is for retrieving details about a given artist, such as it’s tracks, albums, similar artists and more.

Defined Under Namespace

Classes: Albums, PortraitLinks, Portraits, SimilarArtists, TopHits, Tracks

Instance Attribute Summary

Attributes inherited from Base

#pointer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Observable::ArtistBrowse

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(artist, type = :full) ⇒ ArtistBrowse

Note:

Also use Hallon::Artist#browse to browse an Artist.

Creates an ArtistBrowse instance from an Artist or an Artist pointer.

Parameters:

  • artist (Artist, Spotify::Artist)
  • type (Symbol) (defaults to: :full)

    (see types)

Raises:

  • (FFI::NullPointerError)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hallon/artist_browse.rb', line 82

def initialize(artist, type = :full)
  pointer = artist
  pointer = pointer.pointer if pointer.respond_to?(:pointer)

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

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

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

Class Method Details

.typesArray<Symbol>

Returns artist browsing types for use in #initialize.

Returns:

  • (Array<Symbol>)

    artist browsing types for use in #initialize



73
74
75
# File 'lib/hallon/artist_browse.rb', line 73

def self.types
  Spotify.enum_type(:artistbrowse_type).symbols
end

Instance Method Details

#albumsAlbums

Returns artist authored albums.

Returns:

  • (Albums)

    artist authored albums.



144
145
146
# File 'lib/hallon/artist_browse.rb', line 144

def albums
  Albums.new(self)
end

#artistArtist?

Returns artist this browser is browsing.

Returns:

  • (Artist, nil)

    artist this browser is browsing.



110
111
112
113
# File 'lib/hallon/artist_browse.rb', line 110

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

#biographyString

Returns artist biography.

Returns:

  • (String)

    artist biography.



116
117
118
# File 'lib/hallon/artist_browse.rb', line 116

def biography
  Spotify.artistbrowse_biography(pointer)
end

#loaded?Boolean

Returns true if the artist browser is loaded.

Returns:

  • (Boolean)

    true if the artist browser is loaded.



99
100
101
# File 'lib/hallon/artist_browse.rb', line 99

def loaded?
  Spotify.artistbrowse_is_loaded(pointer)
end

Returns artist portraits as Links.

Returns:

  • (PortraitImages)

    artist portraits as Links.



134
135
136
# File 'lib/hallon/artist_browse.rb', line 134

def portrait_links
  PortraitLinks.new(self)
end

#portraitsPortraits

Returns artist portraits as Images.

Returns:



129
130
131
# File 'lib/hallon/artist_browse.rb', line 129

def portraits
  Portraits.new(self)
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).

Returns:

  • (Rational)

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



122
123
124
125
126
# File 'lib/hallon/artist_browse.rb', line 122

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

#similar_artistsSimilarArtists

Returns similar artists to this artist.

Returns:



149
150
151
# File 'lib/hallon/artist_browse.rb', line 149

def similar_artists
  SimilarArtists.new(self)
end

#statusSymbol

Returns artist browser error status.

Returns:

  • (Symbol)

    artist browser error status.

See Also:

  • Error.explain


105
106
107
# File 'lib/hallon/artist_browse.rb', line 105

def status
  Spotify.artistbrowse_error(pointer)
end

#top_hitsTopHits

Returns enumerator of the artist’s most popular tracks.

Returns:

  • (TopHits)

    enumerator of the artist’s most popular tracks.



154
155
156
# File 'lib/hallon/artist_browse.rb', line 154

def top_hits
  TopHits.new(self)
end

#tracksTracks

Returns artist authored tracks.

Returns:

  • (Tracks)

    artist authored tracks.



139
140
141
# File 'lib/hallon/artist_browse.rb', line 139

def tracks
  Tracks.new(self)
end