Changeset 17068

Show
Ignore:
Timestamp:
08/04/08 22:19:48 (5 years ago)
Author:
ujihisa
Message:

add MixiEcho? (patch from haiku)

Files:
1 modified

Legend:

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

    r15724 r17068  
    11command! Mixi :call <SID>MixiStart() 
     2command! MixiEcho :call <SID>MixiEchoStart() 
    23 
    34function! s:MixiStart() 
     
    67endfunction 
    78 
     9function! s:MixiEchoStart() 
     10  set nonu 
     11  ruby mixi_run_echo 
     12endfunction 
     13 
    814ruby << EOF 
     15class Symbol 
     16  def to_proc 
     17    Proc.new{ |obj, *args| obj.send(self, *args) } 
     18  end 
     19end 
     20 
    921class Mixi 
    1022  def initialize(email, password, mixi_premium = false, image_dir = '~/.vim/mixi_images') 
     
    1830    @agent = WWW::Mechanize.new 
    1931    @agent.user_agent_alias = 'Mac Safari' 
     32  end 
     33 
     34  def post_echo(message) 
     35    page = @agent.get 'http://mixi.jp/home.pl' 
     36    form = page.forms[0] 
     37    form.email = @email 
     38    form.password = @password 
     39    @agent.submit form 
     40 
     41    page = @agent.get "http://mixi.jp/home.pl" 
     42    page = @agent.get(page.links.map(&:href).detect {|l| /recent_echo/ =~ l }) 
     43    form = page.forms[1] 
     44    form.body = message 
     45    page = @agent.submit form 
    2046  end 
    2147 
     
    120146  end 
    121147end 
     148 
     149def mixi_run_echo 
     150  vim = VIM::Buffer.current 
     151  # If you need: 
     152  # return if VIM.evaluate('confirm("really?")') == 0 
     153 
     154  message = VIM.evaluate %[getline(1)] 
     155 
     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 
     170  m.post_echo message.toeuc 
     171end 
     172 
    122173EOF