Bunch of changes inspired by r00k
This commit is contained in:
43
vim/bundle/webapi-vim/example/gistview.vim
Normal file
43
vim/bundle/webapi-vim/example/gistview.vim
Normal file
@@ -0,0 +1,43 @@
|
||||
function! s:dump(node, syntax)
|
||||
let syntax = a:syntax
|
||||
if type(a:node) == 1
|
||||
if len(syntax) | exe "echohl ".syntax | endif
|
||||
echon webapi#html#decodeEntityReference(a:node)
|
||||
echohl None
|
||||
elseif type(a:node) == 3
|
||||
for n in a:node
|
||||
call s:dump(n, syntax)
|
||||
endfor
|
||||
return
|
||||
elseif type(a:node) == 4
|
||||
"echo a:node.name
|
||||
"echo a:node.attr
|
||||
let syndef = {'kt' : 'Type', 'mi' : 'Number', 'nb' : 'Statement', 'kp' : 'Statement', 'nn' : 'Define', 'nc' : 'Constant', 'no' : 'Constant', 'k' : 'Include', 's' : 'String', 's1' : 'String', 'err': 'Error', 'kd' : 'StorageClass', 'c1' : 'Comment', 'ss' : 'Delimiter', 'vi' : 'Identifier'}
|
||||
for a in keys(syndef)
|
||||
if has_key(a:node.attr, 'class') && a:node.attr['class'] == a | let syntax = syndef[a] | endif
|
||||
endfor
|
||||
if has_key(a:node.attr, 'class') && a:node.attr['class'] == 'line' | echon "\n" | endif
|
||||
for c in a:node.child
|
||||
call s:dump(c, syntax)
|
||||
unlet c
|
||||
endfor
|
||||
endif
|
||||
endfunction
|
||||
|
||||
let no = 357275
|
||||
let res = webapi#http#get(printf('http://gist.github.com/%d.json', no))
|
||||
let obj = webapi#json#decode(res.content)
|
||||
let dom = webapi#html#parse(obj.div)
|
||||
echo "-------------------------------------------------"
|
||||
for file in dom.childNodes('div')
|
||||
unlet! meta
|
||||
let meta = file.childNodes('div')
|
||||
if len(meta) > 1
|
||||
echo "URL:".meta[1].find('a').attr['href']
|
||||
endif
|
||||
echo "\n"
|
||||
call s:dump(file.find('pre'), '')
|
||||
echo "-------------------------------------------------"
|
||||
endfor
|
||||
|
||||
" vim: set et:
|
||||
40
vim/bundle/webapi-vim/example/google-buzz.vim
Normal file
40
vim/bundle/webapi-vim/example/google-buzz.vim
Normal file
@@ -0,0 +1,40 @@
|
||||
set rtp+=.
|
||||
|
||||
let ctx = {}
|
||||
let configfile = expand('~/.google-buzz-vim')
|
||||
if filereadable(configfile)
|
||||
let ctx = eval(join(readfile(configfile), ""))
|
||||
else
|
||||
let ctx.consumer_key = input("consumer_key:")
|
||||
let ctx.consumer_secret = input("consumer_secret:")
|
||||
let ctx.domain = input("domain:")
|
||||
let ctx.callback = input("callback:")
|
||||
|
||||
let request_token_url = "https://www.google.com/accounts/OAuthGetRequestToken"
|
||||
let auth_url = "https://www.google.com/accounts/OAuthAuthorizeToken"
|
||||
let access_token_url = "https://www.google.com/accounts/OAuthGetAccessToken"
|
||||
|
||||
let ctx = webapi#oauth#request_token(request_token_url, ctx, {"scope": "https://www.googleapis.com/auth/buzz", "oauth_callback": ctx.callback})
|
||||
if has("win32") || has("win64")
|
||||
exe "!start rundll32 url.dll,FileProtocolHandler ".auth_url."?oauth_token=".ctx.request_token."&domain=".ctx.domain."&scope=https://www.googleapis.com/auth/buzz"
|
||||
else
|
||||
call system("xdg-open '".auth_url."?oauth_token=".ctx.request_token. "&domain=".ctx.domain."&scope=https://www.googleapis.com/auth/buzz'")
|
||||
endif
|
||||
let verifier = input("VERIFIER:")
|
||||
let ctx = webapi#oauth#access_token(access_token_url, ctx, {"oauth_verifier": verifier})
|
||||
call writefile([string(ctx)], configfile)
|
||||
endif
|
||||
|
||||
let post_url = "https://www.googleapis.com/buzz/v1/activities/@me/@self"
|
||||
let data = ''
|
||||
\.'<entry xmlns:activity="http://activitystrea.ms/spec/1.0/"'
|
||||
\.' xmlns:poco="http://portablecontacts.net/ns/1.0"'
|
||||
\.' xmlns:georss="http://www.georss.org/georss"'
|
||||
\.' xmlns:buzz="http://schemas.google.com/buzz/2010">'
|
||||
\.' <activity:object>'
|
||||
\.' <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>'
|
||||
\.' <content>ばず! ばず!</content>'
|
||||
\.' </activity:object>'
|
||||
\.'</entry>'
|
||||
let ret = webapi#oauth#post(post_url, ctx, {}, data, {"Content-Type": "application/atom+xml", "GData-Version": "2.0"})
|
||||
echo ret
|
||||
27
vim/bundle/webapi-vim/example/hatenadiary.vim
Normal file
27
vim/bundle/webapi-vim/example/hatenadiary.vim
Normal file
@@ -0,0 +1,27 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let hatena_id = 'your-hatena-id'
|
||||
let password = 'your-hatena-password'
|
||||
|
||||
" write entry
|
||||
let entry = atom#newEntry()
|
||||
call entry.setTitle("title of entry")
|
||||
call entry.setContentType("text/html")
|
||||
call entry.setContent("<script>alert(2)</script>")
|
||||
|
||||
" post draft
|
||||
let id = atom#createEntry("http://d.hatena.ne.jp/".hatena_id."/atom/draft", hatena_id, password, entry)
|
||||
|
||||
" modify it. publish it.
|
||||
call entry.setContent("<script>alert(1)</script>")
|
||||
let id = atom#updateEntry(id, hatena_id, password, entry, {"X-HATENA-PUBLISH": 1})
|
||||
|
||||
" get the entry.
|
||||
let entry = atom#getEntry(id, hatena_id, password)
|
||||
echo entry.getTitle()
|
||||
echo entry.getContent()
|
||||
|
||||
" delete the entry.
|
||||
call atom#deleteEntry(id, hatena_id, password)
|
||||
|
||||
" vim:set ft=vim:
|
||||
24
vim/bundle/webapi-vim/example/jugem.vim
Normal file
24
vim/bundle/webapi-vim/example/jugem.vim
Normal file
@@ -0,0 +1,24 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let jugem_id = 'your-jugem-id'
|
||||
let password = 'your-jugem-password'
|
||||
let imageName = "my-image.gif"
|
||||
let imagePath = "/path/to/images/my-image.gif"
|
||||
|
||||
let api = metaWeblog#proxy("http://".jugem_id.".jugem.jp/admin/xmlrpc.php")
|
||||
|
||||
let imgurl = api.newMediaObject(jugem_id, jugem_id, password, {
|
||||
\ "name": imageName,
|
||||
\ "path": imagePath,
|
||||
\})
|
||||
|
||||
let text = "How about this?<br /><img src=\"".imgurl["url"]."\">"
|
||||
|
||||
echo api.newPost(jugem_id, jugem_id, password, {
|
||||
\ "title": "post from webpi-vim",
|
||||
\ "description": text,
|
||||
\ "dateCreated": "",
|
||||
\ "categories": ["test"],
|
||||
\}, 1)
|
||||
|
||||
" vim:set ft=vim:
|
||||
15
vim/bundle/webapi-vim/example/livedoor.vim
Normal file
15
vim/bundle/webapi-vim/example/livedoor.vim
Normal file
@@ -0,0 +1,15 @@
|
||||
scriptencoding utf-8
|
||||
|
||||
let livedoor_id = 'your-livedoor-id'
|
||||
let password = 'your-livedoor-password'
|
||||
|
||||
" write entry
|
||||
let entry = atom#newEntry()
|
||||
call entry.setTitle("title of entry")
|
||||
call entry.setContentType("text/html")
|
||||
call entry.setContent("<script>alert(3)</script>")
|
||||
|
||||
let postUrl = "http://cms.blog.livedoor.com/atom"
|
||||
echo atom#createEntry(postUrl, livedoor_id, password, entry)
|
||||
|
||||
" vim:set ft=vim:
|
||||
4
vim/bundle/webapi-vim/example/rss.vim
Normal file
4
vim/bundle/webapi-vim/example/rss.vim
Normal file
@@ -0,0 +1,4 @@
|
||||
for item in webapi#feed#parseURL('http://rss.slashdot.org/Slashdot/slashdot')
|
||||
echo item.link
|
||||
echo " " item.title
|
||||
endfor
|
||||
29
vim/bundle/webapi-vim/example/twitter.vim
Normal file
29
vim/bundle/webapi-vim/example/twitter.vim
Normal file
@@ -0,0 +1,29 @@
|
||||
set rtp+=webapi-vim
|
||||
|
||||
let ctx = {}
|
||||
let configfile = expand('~/.twitter-vim')
|
||||
if filereadable(configfile)
|
||||
let ctx = eval(join(readfile(configfile), ""))
|
||||
else
|
||||
let ctx.consumer_key = input("consumer_key:")
|
||||
let ctx.consumer_secret = input("consumer_secret:")
|
||||
|
||||
let request_token_url = "https://twitter.com/oauth/request_token"
|
||||
let auth_url = "https://twitter.com/oauth/authorize"
|
||||
let access_token_url = "https://api.twitter.com/oauth/access_token"
|
||||
|
||||
let ctx = webapi#oauth#request_token(request_token_url, ctx)
|
||||
if has("win32") || has("win64")
|
||||
exe "!start rundll32 url.dll,FileProtocolHandler ".auth_url."?oauth_token=".ctx.request_token
|
||||
else
|
||||
call system("xdg-open '".auth_url."?oauth_token=".ctx.request_token."'")
|
||||
endif
|
||||
let pin = input("PIN:")
|
||||
let ctx = webapi#oauth#access_token(access_token_url, ctx, {"oauth_verifier": pin})
|
||||
call writefile([string(ctx)], configfile)
|
||||
endif
|
||||
|
||||
let post_url = "https://api.twitter.com/1/statuses/update.xml"
|
||||
let status = "tweeeeeeeeeeeeeet"
|
||||
let ret = webapi#oauth#post(post_url, ctx, {}, {"status": status})
|
||||
echo ret
|
||||
3
vim/bundle/webapi-vim/example/weather.vim
Normal file
3
vim/bundle/webapi-vim/example/weather.vim
Normal file
@@ -0,0 +1,3 @@
|
||||
let loc = 'Osaka'
|
||||
let dom = webapi#xml#parseURL(printf('http://www.google.com/ig/api?weather=%s', webapi#http#encodeURIComponent(loc)))
|
||||
echo loc.'''s current weather is '.dom.find('current_conditions').childNode('condition').attr['data']
|
||||
Reference in New Issue
Block a user