Sha256: de5e18cfc823715797735af5ade7508c99156be2a4818062a0286b03b4f36da2

Contents?: true

Size: 623 Bytes

Versions: 2

Compression:

Stored size: 623 Bytes

Contents

require 'addressable/uri'

module ItunesApi
  module Music
    # Use to retrieve artist ids from their names.
    class Artist
      include Request

      def initialize(artist_name)
        @artist_name = artist_name
      end

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

      def apple_ids
        results.collect{ |r| r['artistId'] }.compact.uniq.sort
      end

      private

      def url
        "#{BASE_URL}/search?#{query}"
      end

      def query
        Addressable::URI.new(
          query_values: { term: @artist_name }
        ).query
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
itunes_api-0.0.3 lib/itunes_api/music/artist.rb
itunes_api-0.0.2 lib/itunes_api/music/artist.rb