class AppleMusic::StoreClient
Public Instance Methods
find_artist(artist_name:)
click to toggle source
# File lib/storeClient.rb, line 10 def find_artist(artist_name:) response = get_catalog("search?term=#{escape(artist_name)}&types=artists") parse(response.dig("results", "artists", "data"))[0] end
get_albums(artist:)
click to toggle source
# File lib/storeClient.rb, line 20 def get_albums(artist:) response = PaginatedResponse.new(self, get("/v1/catalog/us/artists/#{artist.id}/albums?limit=100")) parse(response).sort_by { |album| album.releaseDate }.reverse end
get_artist(artist_id:)
click to toggle source
# File lib/storeClient.rb, line 15 def get_artist(artist_id:) response = get_catalog("artists/#{artist_id}") parse(response["data"])[0] end
Private Instance Methods
escape(term)
click to toggle source
# File lib/storeClient.rb, line 27 def escape(term) ERB::Util.url_encode(term) end
get_catalog(resource)
click to toggle source
# File lib/storeClient.rb, line 31 def get_catalog(resource) get("/v1/catalog/us/#{resource}") end
parse(payload)
click to toggle source
# File lib/storeClient.rb, line 35 def parse(payload) return [] if payload.nil? payload.map do |value| if value["type"] == "artists" Artist.new(value) elsif value["type"] == "albums" Album.new(value) else puts "Unknown type:", value end end end