Sha256: 3e875ea8336f58dd095c8752b8ec4d4c2d7c1f8aa92715321904bfe1cdfaea3c

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module AppleMusic
  # https://developer.apple.com/documentation/applemusicapi/genre
  class Genre < Resource
    class << self
      # e.g. AppleMusic::Genre.find(14)
      # https://developer.apple.com/documentation/applemusicapi/get_a_catalog_genre
      # https://developer.apple.com/documentation/applemusicapi/get_a_catalog_song
      def find(id, **options)
        storefront = Storefront.lookup(options.delete(:storefront))
        response = AppleMusic.get("catalog/#{storefront}/genres/#{id}", options)
        Response.new(response.body).data.first
      end

      # e.g. AppleMusic::Genre.list
      # e.g. AppleMusic::Genre.list(ids: [20, 34])
      # https://developer.apple.com/documentation/applemusicapi/get_catalog_top_charts_genres
      # https://developer.apple.com/documentation/applemusicapi/get_multiple_catalog_genres
      def list(**options)
        if options[:ids]
          ids = options[:ids].is_a?(Array) ? options[:ids].join(',') : options[:ids]
          options[:ids] = ids
        end

        storefront = Storefront.lookup(options.delete(:storefront))
        response = AppleMusic.get("catalog/#{storefront}/genres", options)
        Response.new(response.body).data
      end

      def search(**_options)
        warn 'WARN: :genres is not searchable resource'
      end
    end
  end
end

require 'apple_music/genre/attributes'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apple_music-0.3.1 lib/apple_music/genre.rb
apple_music-0.3.0 lib/apple_music/genre.rb
apple_music-0.2.0 lib/apple_music/genre.rb