Module: Genius::Artists

Defined in:
lib/genius/api/artists.rb

Overview

An artist is how Genius represents the creator of one or more songs (or other documents hosted on Genius). It’s usually a musician or group of musicians.

Class Method Summary collapse

Class Method Details

.artists(token: nil, id: nil) ⇒ Hash?

Data for a specific artist.

Parameters:

  • token (String?) (defaults to: nil)

    Token to access api.genius.com.

  • id (Integer?) (defaults to: nil)

    ID of the artist.

Returns:

Raises:

  • (ArgumentError)

    if id is nil.



14
15
16
17
18
19
20
21
# File 'lib/genius/api/artists.rb', line 14

def artists(token: nil, id: nil)
  Auth.authorized?(method_name: "#{Module.nesting[1].name}.#{__method__}") if token.nil?
  Errors.validate_token(token) unless token.nil?
  raise ArgumentError, "`id` can't be nil!" if id.nil?

  response = HTTParty.get("#{Api::RESOURCE}/artists/#{id}?access_token=#{token_ext(token)}").body
  JSON.parse(response)
end

.artists_songs(token: nil, id: nil, options: {}) ⇒ Hash?

Songs for the artist specified. By default 20 items per request.

Parameters:

  • token (String?) (defaults to: nil)

    Token to access api.genius.com.

  • id (Integer?) (defaults to: nil)

    ID of the artist.

  • options (Hash) (defaults to: {})

    Optional query params: :sort, :per_page, :page.

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/genius/api/artists.rb', line 29

def artists_songs(token: nil, id: nil, options: {})
  return if token.nil? && !Auth.authorized?.nil?

  Errors.validate_token(token) unless token.nil?

  sort_values = %w[title popularity]
  validate(sort_values, sort: options[:sort], per_page: options[:per_page], page: options[:page])

  params = options_helper(options, %i[sort per_page page])
  response = HTTParty.get("#{Api::RESOURCE}/artists/#{id}?access_token=#{token_ext(token)}#{params}").body
  JSON.parse(response)
end