Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.