module Flumtter

Constants

Config
Logger
PluginDir
Plugins
SourcePath
StartTime
TITLE
UserPath
VERSION

Public Instance Methods

callback(event,object=nil) click to toggle source
# File lib/flumtter/app/core/core.rb, line 58
def callback(event,object=nil)
  @events[event].each{|blk|blk.call(object)}
end
delete(obj, twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/delete.rb, line 3
def delete(obj, twitter)
  if obj.user.id == twitter.account.id
    begin
      twitter.rest.destroy_status(obj.id)
    rescue Twitter::Error::NotFound => e
      raise ExecutedError, e.message
    end
  else
    raise ExecutedError, "You may not delete another user's status."
  end
end
directmessage(user, text, twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/directmessage.rb, line 3
def directmessage(user, text, twitter)
  case user
  when Twitter::User
    twitter.rest.create_direct_message(user.id, text)
  else
    twitter.rest.create_direct_message(user, text)
  end
end
favorite(obj, twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/favorite.rb, line 3
def favorite(obj, twitter)
  if obj.favorited?
    raise ExecutedError, "already favorited"
  else
    twitter.rest.favorite(obj.id)
  end
end
load_plugin(source, path, file=nil) click to toggle source
# File lib/flumtter/app/core/core.rb, line 37
def load_plugin(source, path, file=nil)
  path = file.nil? ? source.join(path, '*.rb') : source.join(path, file)
  Dir.glob(path).each do |plugin|
    logger.debug("Load: #{plugin}")
    require plugin
  end
end
logger() click to toggle source
# File lib/flumtter/app/core/core.rb, line 33
def logger
  Logger
end
mux_setting(panes) click to toggle source
# File lib/flumtter/app/plugins/tmux.rb, line 11
def mux_setting(panes)
  {
    "name"=> "flumtter",
    "root"=> "~/",
    "windows"=> [
      {
        "window1"=> {
          "layout"=> "even-horizon",
          "panes"=> panes
        }
      }
    ]
  }
end
on_event(event,&blk) click to toggle source
# File lib/flumtter/app/core/core.rb, line 54
def on_event(event,&blk)
  @events[event] << blk
end
pane_setting(name) click to toggle source
# File lib/flumtter/app/plugins/tmux.rb, line 3
def pane_setting(name)
  {
    "#{name}"=> [
      "flumtter -n #{name}"
    ]
  }
end
retweet(obj, twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/retweet.rb, line 3
def retweet(obj, twitter)
  if obj.retweeted?
    raise ExecutedError, "already retweeted"
  else
    begin
      twitter.rest.retweet(obj.id)
    rescue Twitter::Error::Forbidden => e
      if e.message == "You have already retweeted this tweet."
        raise ExecutedError, "already retweeted"
      else
        raise e
      end
    end
  end
end
sarastire(*args) click to toggle source
# File lib/flumtter/app/core/core.rb, line 45
def sarastire(*args)
  load_plugin(SourcePath, *args)
end
sarastire_user(*args) click to toggle source
# File lib/flumtter/app/core/core.rb, line 49
def sarastire_user(*args)
  load_plugin(UserPath, *args)
end
set_yml(setting) click to toggle source
# File lib/flumtter/app/plugins/tmux.rb, line 26
def set_yml(setting)
  File.write(File.join(Dir.home, ".tmuxinator", "flumtter.yml"), YAML.dump(setting))
end
start() click to toggle source
# File lib/flumtter/app/core/core.rb, line 76
  def start
    options = Initializer.optparse
    Setting.merge!(options)
    Client.new AccountSelector.select(options)
  rescue Interrupt
  rescue Exception => ex
    logger.fatal(<<~EOS)
      #{ex.backtrace.shift}: #{ex.message} (#{ex.class})
      #{ex.backtrace.join("\n")}
    EOS
    raise ex
  end
title(twitter) click to toggle source
# File lib/flumtter/app/plugins/toast.rb, line 3
def title(twitter)
  "#{twitter.account.screen_name} Flumtter"
end
unfavorite(obj, twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/unfavorite.rb, line 3
def unfavorite(obj, twitter)
  begin
    twitter.rest.unfavorite(obj.id)
  rescue Twitter::Error::NotFound => e
    if e.message == "No status found with that ID."
      raise ExecutedError, "not favorited"
    else
      raise e
    end
  end
end
update(obj,text,twitter) click to toggle source
# File lib/flumtter/app/plugins/commands/reply.rb, line 3
def update(obj,text,twitter)
  twitter.rest.update("@#{obj.user.screen_name} #{text}", :in_reply_to_status_id => obj.id)
end