Sha256: 6dbd548c5688928bbf147924ddd02da729dd0860238ada63a7ba61478e668c13

Contents?: true

Size: 679 Bytes

Versions: 1

Compression:

Stored size: 679 Bytes

Contents

module ItunesApi
  module Music
    # Artists or Bands resulting from a search
    class ArtistSearch
      def initialize(name)
        @name = name
      end

      def self.artists(name)
        new(name).artists
      end

      def artists
        @artists ||= artist_ids.map { |id| build_artist(id) }.compact
      end

      private

      attr_reader :name

      def artist_ids
        @search ||= ItunesApi.artist_ids(name)
      end

      def build_artist(id)
        if (lookup = lookup(id))
          Artist.new(lookup)
        end
      end

      def lookup(id)
        Requests::Lookup.artist_with_albums(id)
      rescue
        nil
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itunes_api-0.7.0 lib/itunes_api/music/artist_search.rb