Created
March 18, 2013 07:21
-
-
Save sgur/5185554 to your computer and use it in GitHub Desktop.
taskodone.com の API を webapi.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
" taskodne.com API sample | |
let s:user_id = 1 | |
let s:api_key = 'See http://taskodone.com/user/account' | |
let s:number = type(0) | |
let s:string = type('') | |
function! s:validate_params(params, types) | |
if len(a:params) != len(a:types) | |
return 1 | |
endif | |
let i = 0 | |
while (i < len(a:params)) | |
if type(a:params[i]) != a:types[i] | |
return 1 | |
endif | |
let i += 1 | |
endwhile | |
return 0 | |
endfunction | |
function! s:papers(id, key) | |
let params = [a:id, a:key] | |
if s:validate_params(params | |
\ , [s:number, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'papers' | |
\ , params | |
\ ) | |
endfunction | |
function! s:get(id, key, paper) | |
let params = [a:id, a:key, a:paper] | |
if s:validate_params(params | |
\ , [s:number, s:string, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'paper' | |
\ , params) | |
endfunction | |
function! s:rename(id, key, old_paper, new_paper) | |
let params = [a:id, a:key, a:old_paper, a:new_paper] | |
if s:validate_params(params | |
\ , [s:number, s:string, s:string, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'rename' | |
\ , params) | |
endfunction | |
function! s:edit(id, key, title, body) | |
let params = [a:id, a:key, a:title, a:body] | |
if s:validate_params(params | |
\ , [s:number, s:string, s:string, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'edit' | |
\ , params) | |
endfunction | |
function! s:new(id, key, title, body) | |
let params = [a:id, a:key, a:title, a:body] | |
if s:validate_params(params | |
\ , [s:number, s:string, s:string, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'new' | |
\ , params) | |
endfunction | |
function! s:delete(id, key, paper) | |
let params = [a:id, a:key, a:paper] | |
if s:validate_params(params | |
\ , [s:number, s:string, s:string]) | |
echoerr 'Invalid param type' params | |
return | |
endif | |
return webapi#xmlrpc#call( | |
\ 'http://taskodone.com/api' | |
\ , 'delete' | |
\ , params) | |
endfunction | |
" let papers = s:papers(s:user_id, s:api_key) | |
" echo s:paper(s:user_id, s:api_key, papers[0]) | |
" echo s:new(s:user_id, s:api_key, 'Sample', 'This is sample:') | |
echo s:delete(s:user_id, s:api_key, 'Sample2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment