Sha256: b1130ad8220f99fe2a95ded391904b934725b7228f7069ed8bca04511d7483bf

Contents?: true

Size: 787 Bytes

Versions: 3

Compression:

Stored size: 787 Bytes

Contents

require 'addressable/uri'
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_values
        {
          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.4.0 lib/itunes_api/requests/search.rb
itunes_api-0.3.1 lib/itunes_api/requests/search.rb
itunes_api-0.3 lib/itunes_api/requests/search.rb