Skip to content

Commit

Permalink
change to use register_hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn committed Jan 26, 2009
1 parent 7daaf03 commit 4547f03
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
17 changes: 8 additions & 9 deletions lib/plugin/wassr_post.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
require 'uri'
require 'net/http'

module Termtter::Client
# NOTE: overwrite original update command
add_command /^(update|u)\s+(.*)/ do |m, t|
text = ERB.new(m[2]).result(binding).gsub(/\n/, ' ')
t.update_status(text)
puts "=> #{text}"
Termtter::Client.register_hook(
:name => :wassr_post,
:points => [:modify_arg_for_update],
:exec_proc => proc {|cmd, arg|
begin
Net::HTTP.version_1_2
req = Net::HTTP::Post.new("/statuses/update.json?")
req.basic_auth configatron.plugins.wassr_post.username, configatron.plugins.wassr_post.password
Net::HTTP.start('api.wassr.jp', 80) do |http|
res = http.request(req, "status=#{URI.escape(text)}&source=Termtter")
res = http.request(req, "status=#{URI.escape(arg.strip)}&source=Termtter")
end
rescue
puts "RuntimeError: #{$!}"
end
end
end
return arg
}
)
2 changes: 1 addition & 1 deletion lib/termtter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def call_commands(text, tw = nil)
command_found = true
input_command, arg = *command_info

modified_arg = call_new_hooks("modify_arg_for_#{command.name.to_s}", input_command, arg) || arg
modified_arg = call_new_hooks("modify_arg_for_#{command.name.to_s}", input_command, arg) || arg || ''
pre_exec_hook_result = call_new_hooks("pre_exec_#{command.name.to_s}", input_command, modified_arg)

unless pre_exec_hook_result == false
Expand Down

0 comments on commit 4547f03

Please sign in to comment.