You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mastodon.rb 924B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'mastodon'
  2. require 'sanitize'
  3. require 'awesome_print'
  4. class CrossPost
  5. class Mastodon
  6. def initialize(config)
  7. url = config['mastodon.url']
  8. token = config['mastodon.token']
  9. user = config['mastodon.user']
  10. @user_url = URI.join(url, "/@#{user}").to_s
  11. @client = ::Mastodon::REST::Client.new base_url: url, bearer_token: token
  12. @stream = ::Mastodon::Streaming::Client.new base_url: url, bearer_token: token
  13. end
  14. def feed(twitter)
  15. @stream.user do |object|
  16. begin
  17. case object
  18. when ::Mastodon::Status
  19. next if reject? object
  20. LOGGER.info { 'Receiving status' }
  21. LOGGER.debug { status.ap }
  22. twitter.post_status object
  23. end
  24. rescue => e
  25. LOGGER.error e
  26. #raise
  27. end
  28. end
  29. end
  30. private
  31. def reject?(status)
  32. status.account.url != @user_url or
  33. status.visibility != 'public' or
  34. status.in_reply_to_id
  35. end
  36. end
  37. end