Sha256: 8e4741391391d8d4e4c28baa6d1b0f68cd8d932b2802e8b190cace0a2c77f03b

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

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 all_apple_ids(name, store)
          find_all_by_name(name, store).map(&:apple_id)
        end

        def find_all_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)
          artist = artist(apple_id, store)
          artist ? new(*artist.attributes) : nil
        end

        private

        def artist(apple_id, store)
          Requests::Artist.find_by_apple_id(apple_id, store)
        end
      end

      def albums
        @albums ||= Album.for_artist(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

1 entries across 1 versions & 1 rubygems

Version Path
itunes_api-2.1.0 lib/itunes_api/music/artist.rb