Created
May 27, 2019 15:53
-
-
Save kyanny/1ab31531a0a1f66bc9a66cb8771bfe1a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'openssl' | |
require 'uri' | |
require 'json' | |
begin | |
http = Net::HTTP.new(ENV.fetch('MASTODON_HOST'), 443) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | |
req = Net::HTTP::Get.new('/api/v1/accounts/verify_credentials') | |
req['User-Agent'] = 'curl/7.54.0' | |
req['Authorization'] = "Bearer #{ENV['MASTODON_ACCESS_TOKEN']}" | |
res = http.request(req) | |
account = JSON.parse(res.body) | |
id = account['id'] | |
req = Net::HTTP::Get.new("/api/v1/accounts/#{id}/statuses") | |
req['User-Agent'] = 'curl/7.54.0' | |
req['Authorization'] = "Bearer #{ENV['MASTODON_ACCESS_TOKEN']}" | |
res = http.request(req) | |
statuses = JSON.parse(res.body) | |
statuses.each do |status| | |
status_id = status['id'] | |
req = Net::HTTP::Delete.new("/api/v1/statuses/#{status_id}") | |
req['User-Agent'] = 'curl/7.54.0' | |
req['Authorization'] = "Bearer #{ENV['MASTODON_ACCESS_TOKEN']}" | |
res = http.request(req) | |
puts "DELETE #{status_id} #{res.code} #{res['x-ratelimit-remaining']} #{res['x-ratelimit-reset']}" | |
end | |
rescue => e | |
p e | |
puts <<USAGE | |
Usage: | |
$ MASTODON_HOST=example.com MASTODON_ACCESS_TOKEN=xxxxxxxx ruby delete_all_statuses.rb | |
USAGE | |
exit! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment