Class: ListenBrainz::Artist

Inherits:
Base
  • Object
show all
Defined in:
lib/listenbrainz/models/artist.rb

Overview

Model class for artists.

Defined Under Namespace

Classes: Payload

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#as_json

Instance Attribute Details

#artist_mbidString? (readonly) Also known as: mbid

Returns:

  • (String, nil)


76
# File 'lib/listenbrainz/models/artist.rb', line 76

attribute? :artist_mbid, Types::String.optional

#artist_nameString (readonly) Also known as: name

Returns:

  • (String)


81
# File 'lib/listenbrainz/models/artist.rb', line 81

attribute :artist_name, Types::String

#listen_countInteger (readonly)

Returns:

  • (Integer)


86
# File 'lib/listenbrainz/models/artist.rb', line 86

attribute :listen_count, Types::Integer

Class Method Details

.get(username = ListenBrainz.client.username, count: nil, offset: nil, range: nil) ⇒ Payload

Retrieves the top artists for a given user.

Parameters:

  • username (String) (defaults to: ListenBrainz.client.username)
  • count (Integer, nil) (defaults to: nil)

    Number of artists to retrieve

  • offset (Integer, nil) (defaults to: nil)

    Number of artists to skip

  • range (Symbol, nil) (defaults to: nil)

    all_time, month, week, year, quarter, half_yearly, this_week, this_month or this_year

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/listenbrainz/models/artist.rb', line 19

def self.get(
  username = ListenBrainz.client.username, count: nil, offset: nil,
  range: nil
)
  params = { count:, offset:, range: }.compact
  ListenBrainz.client.query(
    :get, "1/stats/user/#{username}/artists", params:
  ).fetch(:payload).then { Payload.new(_1) }
end

.sitewide(count: nil, offset: nil, range: nil) ⇒ Payload

Retrieves site-wide top artists.

Parameters:

  • count (Integer, nil) (defaults to: nil)

    Number of artists to retrieve

  • offset (Integer, nil) (defaults to: nil)

    Number of artists to skip

  • range (Symbol, nil) (defaults to: nil)

    all_time, month, week, year, quarter, half_yearly, this_week, this_month or this_year

Returns:



38
39
40
41
42
43
44
45
46
47
# File 'lib/listenbrainz/models/artist.rb', line 38

def self.sitewide(count: nil, offset: nil, range: nil)
  params = { count:, offset:, range: }.compact
  payload = ListenBrainz.client.query(
    :get, '1/stats/sitewide/artists', params:
  ).fetch(:payload)

  # HACK: API is not consistent between site-wide and user schema.
  payload[:total_artist_count] = payload[:count]
  Payload.new(payload)
end