module GetHappy
Constants
- COLLECTION
- COLLECTION_DIR
- VERSION
Public Instance Methods
ensure_user_data!()
click to toggle source
# File lib/get_happy/engine.rb, line 40 def ensure_user_data! unless File.directory?(COLLECTION_DIR) FileUtils.mkdir_p(COLLECTION_DIR) end File.open(COLLECTION, "w") do |file| file.write [].to_yaml end unless File.file?(COLLECTION) end
get_collection()
click to toggle source
# File lib/get_happy/engine.rb, line 27 def get_collection ensure_user_data! YAML::load_file(COLLECTION) end
get_playlist(id)
click to toggle source
# File lib/get_happy/engine.rb, line 32 def get_playlist(id) url = "http://gdata.youtube.com/feeds/api/playlists/#{id}?v=2&alt=json" request = Net::HTTP.get_response(URI.parse(url)) success = request.is_a? Net::HTTPSuccess data = JSON.parse(request.body, :symbolize_names => true) if success success ? data[:feed][:entry].map {|e| e[:link].first[:href]} : [] end
seed()
click to toggle source
# File lib/get_happy/engine.rb, line 23 def seed write_collection get_collection + @urls end
write_collection(collection)
click to toggle source
# File lib/get_happy/engine.rb, line 16 def write_collection(collection) collection = collection.compact.uniq File.open(COLLECTION, "w") do |file| file.write collection.to_yaml end end