cross-post/lib/cross-post/mastodon.rb

42 lines
924 B
Ruby

require 'mastodon'
require 'sanitize'
require 'awesome_print'
class CrossPost
class Mastodon
def initialize(config)
url = config['mastodon.url']
token = config['mastodon.token']
user = config['mastodon.user']
@user_url = URI.join(url, "/@#{user}").to_s
@client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token
@stream = ::Mastodon::Streaming::Client.new base_url: url, bearer_token: token
end
def feed(twitter)
@stream.user do |object|
begin
case object
when ::Mastodon::Status
next if reject? object
LOGGER.info { 'Receiving status' }
LOGGER.debug { status.ap }
twitter.post_status object
end
rescue => e
LOGGER.error e
#raise
end
end
end
private
def reject?(status)
status.account.url != @user_url or
status.visibility != 'public' or
status.in_reply_to_id
end
end
end