PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/plugins/twitpic.rb

https://github.com/Epictetus/termtter
Ruby | 46 lines | 31 code | 4 blank | 11 comment | 6 complexity | a4d2e557ffcc0eda35efc06d68680124 MD5 | raw file
  1. # = twitpic
  2. #
  3. # == usage
  4. # > twitpic [MESSAGE] [IMAGE_FILE]
  5. #
  6. # == requirements
  7. # * twitpic
  8. # sudo gem install twitpic
  9. #
  10. # == TODO
  11. # * スペースの混じったファイル名を扱えるようにする
  12. gem "twitpic", ">=0.3.1"
  13. require 'twitpic'
  14. module Termtter::Client
  15. register_command(
  16. :name => :twitpic,
  17. :help => ['twitpic [MESSAGE] [IMAGE_FILE]', 'Upload a image file to TwitPic'],
  18. :exec => lambda do |arg|
  19. path = arg.scan(/[^\s]+$/).flatten.first rescue nil
  20. if path && File.exists?(path) && File.file?(path)
  21. text = arg.gsub(/[^\s]+$/, '').strip
  22. else
  23. path = Termtter::CONF_DIR + '/tmp/twitpic_screencapture.png'
  24. File.delete(path) if File.exists?(path)
  25. puts 'Please capture screen!'
  26. system('screencapture', '-i', '-f', path) || system('import', path) # TODO: こんなんで大丈夫かな
  27. text = arg
  28. end
  29. if File.exists?(path)
  30. puts 'Uploading...'
  31. url = TwitPic.new(config.user_name, config.password).upload(path)[:mediaurl]
  32. puts " => \"#{url}\""
  33. post_message = "#{text} #{url}".strip
  34. puts 'Post a message...'
  35. Termtter::API.twitter.update(post_message)
  36. puts " => \"#{post_message}\""
  37. else
  38. puts 'Aboat!'
  39. end
  40. end
  41. )
  42. end