Class: Tootify
- Inherits:
-
Object
- Object
- Tootify
- Defined in:
- app/tootify.rb
Instance Method Summary collapse
-
#initialize ⇒ Tootify
constructor
A new instance of Tootify.
- #login_bluesky(handle) ⇒ Object
- #login_mastodon(handle) ⇒ Object
- #post_to_mastodon(record) ⇒ Object
- #sync ⇒ Object
Constructor Details
#initialize ⇒ Tootify
Returns a new instance of Tootify.
7 8 9 10 |
# File 'app/tootify.rb', line 7 def initialize @bluesky = BlueskyAccount.new @mastodon = MastodonAccount.new end |
Instance Method Details
#login_bluesky(handle) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'app/tootify.rb', line 12 def login_bluesky(handle) handle = handle.gsub(/^@/, '') print "App password: " password = STDIN.noecho(&:gets).chomp puts @bluesky.login_with_password(handle, password) end |
#login_mastodon(handle) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'app/tootify.rb', line 22 def login_mastodon(handle) print "Email: " email = STDIN.gets.chomp print "Password: " password = STDIN.noecho(&:gets).chomp puts @mastodon.oauth_login(handle, email, password) end |
#post_to_mastodon(record) ⇒ Object
57 58 59 60 |
# File 'app/tootify.rb', line 57 def post_to_mastodon(record) p record p @mastodon.post_status(record['text']) end |
#sync ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/tootify.rb', line 33 def sync likes = @bluesky.fetch_likes likes.each do |r| like_uri = r['uri'] post_uri = r['value']['subject']['uri'] repo, collection, rkey = post_uri.split('/')[2..4] next unless repo == @bluesky.did && collection == 'app.bsky.feed.post' begin record = @bluesky.fetch_record(repo, collection, rkey) rescue Minisky::ClientErrorResponse => e puts "Record not found: #{post_uri}" @bluesky.delete_record_at(like_uri) next end post_to_mastodon(record['value']) @bluesky.delete_record_at(like_uri) end end |