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 855B

123456789101112131415161718192021222324252627282930313233343536373839
  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 post(text)
  15. post = @client.create_status text
  16. ap post
  17. end
  18. def feed(twitter)
  19. @stream.user do |object|
  20. begin
  21. case object
  22. when ::Mastodon::Status
  23. next if object.account.url != @user_url
  24. next if object.visibility != 'public'
  25. next if object.in_reply_to_id
  26. ap object
  27. twitter.post object
  28. end
  29. rescue => e
  30. $stderr.puts e
  31. end
  32. end
  33. end
  34. end
  35. end