Changeset 17102 for lang/vim

Show
Ignore:
Timestamp:
08/05/08 17:39:40 (4 months ago)
Author:
ujihisa
Message:

add MixiEchoGet? and etc

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/ruby/mixi.vim

    r17076 r17102  
    11command! Mixi :call <SID>MixiStart() 
    2 command! MixiEcho :call <SID>MixiEchoStart() 
     2command! MixiEcho :call <SID>MixiStartEcho() 
     3command! MixiEchoGet :call <SID>MixiStartEchoAndGetMessage() 
    34 
    45function! s:MixiStart() 
     
    78endfunction 
    89 
    9 function! s:MixiEchoStart() 
     10function! s:MixiStartEcho() 
    1011  set nonu 
    1112  ruby mixi_run_echo 
     13endfunction 
     14 
     15function! s:MixiStartEchoAndGetMessage() 
     16  set nonu 
     17  ruby mixi_run_echo_getmessage 
    1218endfunction 
    1319 
     
    8894  end 
    8995 
     96  def get_latest_echo 
     97    page = @agent.get 'http://mixi.jp/recent_echo.pl' 
     98    line = [] 
     99    10.downto(1) do |i| 
     100      buf = '' 
     101      buf << (page/("div#echo_nickname_" + i.to_s)).first.to_plain_text.toutf8 
     102      buf << ":" 
     103      buf << (page/("div#echo_body_" + i.to_s)).first.to_plain_text.toutf8 
     104      line.push buf 
     105    end 
     106    line 
     107  end 
     108 
    90109  def self.magic_body(body) 
    91110    body.gsub(/^(  )+/) {|i| ' '.toeuc * (i.length/2) } 
     
    116135end 
    117136 
    118 def mixi_run 
    119   vim = VIM::Buffer.current 
    120   return if VIM.evaluate('confirm("really?")') == 0 
    121  
    122   endline = VIM.evaluate %[line("$")] 
    123   title   = VIM.evaluate %[getline(1)] 
    124   body = VIM.evaluate(%[join(getline(2, #{endline}), "\n")]).split "\n" 
    125  
    126   images = body.reverse.inject([]) {|r, l| r.unshift l[4..-1] if l =~ /^img:/; r } 
    127   body = body[0..-(images.length + 1)].join "\n" 
    128  
     137def create_mixi_instance 
    129138  # ~/.mixi 
    130139  # line1: input your email 
    131140  # line2: input your password 
    132141  # line3: input "premium" if you are premium 
    133   m = 
    134142    if File.exist?(File.expand_path('~/.mixi')) 
    135143      mixi_config = File.read(File.expand_path('~/.mixi')) 
     
    141149  # if you are mixi premium member: 
    142150  # m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD', true 
     151end 
     152 
     153def mixi_run 
     154  vim = VIM::Buffer.current 
     155  return if VIM.evaluate('confirm("really?")') == 0 
     156 
     157  endline = VIM.evaluate %[line("$")] 
     158  title   = VIM.evaluate %[getline(1)] 
     159  body = VIM.evaluate(%[join(getline(2, #{endline}), "\n")]).split "\n" 
     160 
     161  images = body.reverse.inject([]) {|r, l| r.unshift l[4..-1] if l =~ /^img:/; r } 
     162  body = body[0..-(images.length + 1)].join "\n" 
     163 
     164  m = create_mixi_instance; 
     165 
    143166  m.post title.toeuc, body.toeuc, images 
    144167  m.get_latest.each do |line| 
     
    154177  message = VIM.evaluate %[getline('.')] 
    155178 
    156   # ~/.mixi 
    157   # line1: input your email 
    158   # line2: input your password 
    159   # line3: input "premium" if you are premium 
    160   m = 
    161     if File.exist?(File.expand_path('~/.mixi')) 
    162       mixi_config = File.read(File.expand_path('~/.mixi')) 
    163       email, password, premium = mixi_config.split(/\r?\n/) 
    164       Mixi.new email, password, (premium == 'premium') 
    165     else 
    166       m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD' 
    167     end 
    168   # if you are mixi premium member: 
    169   # m = Mixi.new 'YOUR_EMAIL', 'YOUR_PASSWORD', true 
     179  m = create_mixi_instance; 
     180 
    170181  fork { 
    171182    m.post_echo message.toeuc 
     
    173184end 
    174185 
     186def mixi_run_echo_getmessage 
     187  vim = VIM::Buffer.current 
     188  # If you need: 
     189  # return if VIM.evaluate('confirm("really?")') == 0 
     190 
     191  message = VIM.evaluate %[getline(1)] 
     192 
     193  m = create_mixi_instance; 
     194 
     195  m.post_echo message.toeuc 
     196  m.get_latest_echo.each do |line| 
     197    vim.append(1, line) 
     198  end 
     199end 
     200 
     201 
    175202EOF