require 'net/http' require 'pp' require 'rubygems' require 'json' class Hash def to_http_params results = [] return results if self.empty? self.each do |key, val| results << "#{key}=#{URI.encode(val.to_s)}" end results.join('&') end end username = ARGV[0] password = ARGV[1] api_key = ARGV[2] list_name = ARGV[3] if ! username || ! password || ! api_key || ! list_name print " Usage: ruby delete_lists.rb username password api_key list_name " exit 1 end #print "#{username}, #{password}, #{api_key}, #{list_name}\n" # Look for the user's lists Net::HTTP.version_1_2 req = Net::HTTP::Get.new("/users/#{username}/lists/creator.json?per_page=100&include_private=true") req.basic_auth(username, password) Net::HTTP.start('api.smart.fm', 80) {|http| res = http.request(req) JSON.parse(res.body).each { |item| # print "id: #{item['id']}\n" # Delete the list if it matches if item['title'] == list_name Net::HTTP.version_1_2 req = Net::HTTP::Delete.new("/lists/#{item['id']}?api_key=#{api_key}") req.basic_auth(username, password) Net::HTTP.start('api.smart.fm', 80) {|http| res = http.request(req) print "Deleting list id #{item['id']}\n" # pp res # puts "list: #{res.body}\n" } end } }