No Description
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.

cross-post.rb 763B

1234567891011121314151617181920212223242526272829303132333435
  1. require 'cross-post/config'
  2. require 'cross-post/mastodon'
  3. require 'cross-post/twitter'
  4. require 'open-uri'
  5. require 'logger'
  6. # Force OpenURI#open to return a TempFile and not a StringIO
  7. OpenURI::Buffer.send :remove_const, 'StringMax'
  8. OpenURI::Buffer.const_set 'StringMax', 0
  9. class CrossPost
  10. LOGGER = Logger.new STDERR
  11. LOGGER.level = Logger.const_get ENV.fetch('LOG', 'INFO').upcase
  12. LOGGER.formatter = proc do |severity, time, _, msg|
  13. time = time.strftime '%Y-%m-%dT%H:%M:%S.%6N'.freeze
  14. "#{time} #{severity} #{msg}\n"
  15. end
  16. attr_reader :mastodon, :twitter
  17. def initialize
  18. @config = Config.new
  19. @mastodon = Mastodon.new @config
  20. @twitter = Twitter.new @config
  21. end
  22. def feed
  23. @mastodon.feed @twitter
  24. end
  25. def self.feed
  26. self.new.feed
  27. end
  28. end