Sha256: af1c1c80f15ad4b72f26f2163bb5d3acf7c3d33d4ee134b1f25414bfd1b3f94e

Contents?: true

Size: 957 Bytes

Versions: 3

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module ItunesApi
  module Music
    # Artist or Band from the Apple catalog
    class Artist
      attr_reader_init :amg_id, :apple_id, :genre, :link, :name, :store

      class << self
        def find_by_name(name, store)
          Requests::Search.artists(name, store).map do |result|
            new(*result.attributes)
          end
        end

        def find_by_apple_id(apple_id, store)
          result = artists(apple_id, store).first

          new(*result.attributes) if result
        end

        private

        def artists(id, store)
          Requests::Artist.find_by_id(id, store)
        end
      end

      def albums
        @albums ||= Album.find_by_apple_id(apple_id, store)
      end

      def to_hash
        {
          amg_id: amg_id,
          apple_id: apple_id,
          genre: genre,
          link: link,
          name: name,
          store: store
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itunes_api-2.4.1 lib/itunes_api/music/artist.rb
itunes_api-2.4.0 lib/itunes_api/music/artist.rb
itunes_api-2.3.2 lib/itunes_api/music/artist.rb