class APIS::Itunes

this file will go into a certain file within our directory

Public Instance Methods

fun_times() click to toggle source
# File lib/tia.rb, line 28
def fun_times
        parsed["results"].each{|song|songs<<{name: song}}
end
itunes_api_response() click to toggle source
this class could be called anything

by having this initial method initializes for if ARGV. in terms of the API we're working with- if you're doing the same type of search- create or wrap this in it's own method (def search) URI converts the strings to a URL def itunes_api_response. encode the URI using the URI constant

# File lib/tia.rb, line 14
def itunes_api_response
        uri = URI("https://itunes.apple.com/search?term=nirvana&entity=song")
        response = Net::HTTP.get(uri)
end
turn_to_name_id_hash() click to toggle source
# File lib/tia.rb, line 18
def turn_to_name_id_hash
        parsed = JSON.parse(itunes_api_response)
        songs = []
        parsed["results"].each{|song|songs<<{name: song["trackName"], album:song["collectionName"],
                id: song["trackid"]}}
                #ap p[name]
                #|word| inside of pipes is creating a variable
                #this method returns song name, album name, id

end