Created
March 14, 2012 09:27
-
-
Save ha1t/2035352 to your computer and use it in GitHub Desktop.
wassr todoをvimの上で操作できるスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"" | |
" wassr-todo.vim | |
" | |
scriptencoding utf-8 | |
"let g:wassr_user = "your id" | |
"let g:wassr_pass = "your pass" | |
function! WassrTODOList() | |
let json = s:GetJson("http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/list.json") | |
"let i = 1 | |
"call setqflist([], 'r') | |
for jvar in json | |
echo jvar["body"] | |
"let qf_row = [{'bufnr':bufnr('%'), 'lnum': i, 'text':jvar["body"]}] | |
"call setqflist(qf_row, 'a') | |
"let i = i + 1 | |
endfor | |
"copen | |
endfunction | |
function! WassrEnumTODO(...) | |
echo a:1 | |
let json = s:GetJson("http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/list.json") | |
let todo_list = [] | |
for jvar in json | |
let is_match = match(jvar["body"], a:1) | |
if (is_match != -1) | |
call add(todo_list, "[" . jvar["todo_rid"] . "] " . jvar["body"]) | |
endif | |
endfor | |
echo todo_list | |
return todo_list | |
endfunction | |
function! WassrTODOAdd() | |
"let message = input('add TODO: ', '', 'customlist,HatenaEnumUsers') | |
let message = input('add TODO: ', '') | |
let ret = system("curl -s" | |
\ . " \"" . "http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/add.json\"" | |
\ . " -F body=" . message) | |
echo "added: " . message | |
endfunction | |
function! WassrTODOStart() | |
let message = input('start TODO: ', '', 'customlist,WassrEnumTODO') | |
let todo_rid = substitute(message, '\[\(.*\)] .*', '\1', '') | |
let ret = system("curl -s" | |
\ . " \"" . "http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/start.json\"" | |
\ . " -F todo_rid=" . todo_rid) | |
echo "started: " . message | |
endfunction | |
function! WassrTODOStop() | |
let message = input('stop TODO: ', '', 'customlist,WassrEnumTODO') | |
let todo_rid = substitute(message, '\[\(.*\)] .*', '\1', '') | |
let ret = system("curl -s" | |
\ . " \"" . "http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/stop.json\"" | |
\ . " -F todo_rid=" . todo_rid) | |
echo "stoped: " . message | |
endfunction | |
function! WassrTODODone() | |
let message = input('done TODO: ', '', 'customlist,WassrEnumTODO') | |
let todo_rid = substitute(message, '\[\(.*\)] .*', '\1', '') | |
let ret = system("curl -s" | |
\ . " \"" . "http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/done.json\"" | |
\ . " -F todo_rid=" . todo_rid) | |
echo "done: " . message | |
endfunction | |
function! WassrTODODelete() | |
let message = input('delete TODO: ', '', 'customlist,WassrEnumTODO') | |
let todo_rid = substitute(message, '\[\(.*\)] .*', '\1', '') | |
let ret = system("curl -s" | |
\ . " \"" . "http://" . g:wassr_user . ":" . g:wassr_pass . "@api.wassr.jp/todo/delete.json\"" | |
\ . " -F todo_rid=" . todo_rid) | |
echo "done: " . message | |
endfunction | |
function! s:JsonHandler(data) | |
return a:data | |
endfunction | |
"" | |
" http://mattn.kaoriya.net/software/vim/20070731150740.htm | |
" | |
function! s:GetJsonP(url) | |
let ret = system("curl -s \"" . a:url . "?callback=JsonHandler\"") | |
let org = &enc | |
let &enc = "utf-8" | |
let ret = substitute(ret, '\\u\([0-9a-zA-Z]\{4\}\)', '\=nr2char("0x".submatch(1))', 'g') | |
exe "let val = " . iconv(ret, "utf-8", org) | |
let &enc = org | |
return val | |
endfunction | |
function! s:GetJson(url) | |
let ret = system("curl -s \"" . a:url . "\"") | |
let org = &enc | |
let &enc = "utf-8" | |
let ret = substitute(ret, '\\u\([0-9a-zA-Z]\{4\}\)', '\=nr2char("0x".submatch(1))', 'g') | |
exe "let val = " . iconv(ret, "utf-8", org) | |
let &enc = org | |
return val | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment