Sha256: 5986f2311559541ce9ce636a720dbd1503be09992a1304beb21948dbf48f3dea

Contents?: true

Size: 754 Bytes

Versions: 3

Compression:

Stored size: 754 Bytes

Contents

module ItunesApi
  module Requests
    # Fetch all the artist ids corresponding to a search term
    class Search
      include Base

      def initialize(artist_name)
        @artist_name = artist_name
      end

      def self.artist_ids(artist_name)
        new(artist_name).artist_ids
      end

      def artist_ids
        results.collect do |result|
          result['amgArtistId']
        end.compact.uniq.sort
      end

      private

      def action
        'search'
      end

      def query
        {
          attribute: 'artistTerm',
          entity: 'album',
          term: @artist_name,
          country: COUNTRY_CODE,
          limit: LIMIT,
          media: 'music',
          sort: 'recent'
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
itunes_api-0.5.1 lib/itunes_api/requests/search.rb
itunes_api-0.5.0 lib/itunes_api/requests/search.rb
itunes_api-0.4.2 lib/itunes_api/requests/search.rb