Sha256: 192692693cd472c28bdf478efb7225057becfde0fe4007b697f90199fa515663

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

module ItunesApi
  module Requests
    # Fetch all the artist ids corresponding to a search term
    class Search
      include Base
      attr_reader_init :artist_name, :store
      selfie :artist_ids

      def artist_ids
        results.collect do |result|
          name_in?(result['artistName']) && result['artistId']
        end.compact.uniq
      end

      private

      def action
        'search'
      end

      def name_in?(complete_name)
        complete_name.downcase.include?(artist_name.downcase) ? true : nil
      end

      def query
        {
          attribute: 'artistTerm',
          entity: 'musicArtist',
          term: artist_name,
          country: store.to_s.upcase,
          limit: LIMIT,
          media: 'music',
          sort: 'recent'
        }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
itunes_api-1.4.1 lib/itunes_api/requests/search.rb