Changeset 7654

Show
Ignore:
Timestamp:
03/08/08 20:42:09 (5 years ago)
Author:
motemen
Message:

lang/vim/hatena/plugin/hatena.vim: その場編集の API に対応した関数を定義

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/hatena/plugin/hatena.vim

    r6313 r7654  
    365365                    \ . ' -F image= -F title=' . a:diary['day_title'] 
    366366    return system(s:curl_cmd . ' ' . a:base_url . a:user . '/edit -b "' . a:cookie_file . '"' . post_data . ' -D -') 
     367endfunction 
     368 
     369function! HatenaGetRKM(login_info) 
     370    let [base_url, user, cookie_file] = a:login_info 
     371    let json = system(s:curl_cmd . ' "' . base_url . user . '/?mode=json" -b "' . cookie_file . '"') 
     372    return matchstr(json, "'rkm':'\\zs.*\\ze'") 
     373endfunction 
     374 
     375" はてなダイアリー/グループに新しいエントリを投稿する 
     376" login_info: HatenaLogin() で得られるもの 
     377" rkm: HatenaGetRKM() などで得られるもの 
     378" entry: エントリの情報、以下のキーを持つ 
     379"  * title 
     380"  * body (body_file とどちらか一方) 
     381"  * body_file (body とどちらか一方) 
     382"  * date (optional) 
     383"  * timestamp (optional) 
     384function! HatenaPostEntry(login_info, rkm, entry) 
     385    let [base_url, user, cookie_file] = a:login_info 
     386 
     387    if base_url =~ 'g[.]hatena' 
     388        let fenc = 'utf-8' 
     389    else 
     390        let fenc = 'euc-jp' 
     391    endif 
     392 
     393    if has_key(a:entry, 'body_file') 
     394        let body_file = a:entry.body_file 
     395        execute 'split ' . body_file 
     396        let &fileencoding = fenc 
     397        write 
     398        quit 
     399    else 
     400        let body_file = tempname() 
     401        execute 'new ' . body_file 
     402        call append(0, a:entry.body) 
     403        let &fileencoding = fenc 
     404        write 
     405        bdelete 
     406    endif 
     407 
     408    let title_file = tempname() 
     409    execute 'new ' . title_file 
     410    normal! C=a:entry.title 
     411    let &fileencoding = fenc 
     412    write 
     413 
     414    let post_url = base_url . user . '/' 
     415    if has_key(a:entry, 'date') && has_key(a:entry, 'timestamp') 
     416        let post_url += a:entry.date . '/' . a:entry.timestamp . '/' 
     417    endif 
     418 
     419    return system(printf('%s %s -b "%s" -F "rkm=%s" -F "title=<%s" -F "body=<%s" -D -', 
     420                \ s:curl_cmd, 
     421                \ post_url, 
     422                \ cookie_file, 
     423                \ a:rkm, 
     424                \ title_file, 
     425                \ body_file 
     426                \ )) 
    367427endfunction 
    368428