Skip to content

Commit 304bc36

Browse files
committed
add some examples.
1 parent ef3dafe commit 304bc36

6 files changed

Lines changed: 60 additions & 10 deletions

File tree

example/gistview.vim

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function! s:dump(node, syntax)
2+
let syntax = a:syntax
3+
if type(a:node) == 1
4+
if len(syntax) | exe "echohl ".syntax | endif
5+
echon webapi#html#decodeEntityReference(a:node)
6+
echohl None
7+
elseif type(a:node) == 3
8+
for n in a:node
9+
call s:dump(n, syntax)
10+
endfor
11+
return
12+
elseif type(a:node) == 4
13+
"echo a:node.name
14+
"echo a:node.attr
15+
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'}
16+
for a in keys(syndef)
17+
if has_key(a:node.attr, 'class') && a:node.attr['class'] == a | let syntax = syndef[a] | endif
18+
endfor
19+
if has_key(a:node.attr, 'class') && a:node.attr['class'] == 'line' | echon "\n" | endif
20+
for c in a:node.child
21+
call s:dump(c, syntax)
22+
unlet c
23+
endfor
24+
endif
25+
endfunction
26+
27+
let no = 357275
28+
let res = webapi#http#get(printf('http://gist.github.com/%d.json', no))
29+
let obj = webapi#json#decode(res.content)
30+
let dom = webapi#html#parse(obj.div)
31+
echo "-------------------------------------------------"
32+
for file in dom.childNodes('div')
33+
unlet! meta
34+
let meta = file.childNodes('div')
35+
if len(meta) > 1
36+
echo "URL:".meta[1].find('a').attr['href']
37+
endif
38+
echo "\n"
39+
call s:dump(file.find('pre'), '')
40+
echo "-------------------------------------------------"
41+
endfor
42+
43+
" vim: set et:

example/hatenadiary.vim

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ scriptencoding utf-8
33
let hatena_id = 'your-hatena-id'
44
let password = 'your-hatena-password'
55

6-
" エントリを書く
6+
" write entry
77
let entry = atom#newEntry()
8-
call entry.setTitle("日記エントリータイトル")
8+
call entry.setTitle("title of entry")
99
call entry.setContentType("text/html")
1010
call entry.setContent("<script>alert(2)</script>")
1111

12-
" エントリを下書きとしてポストする
12+
" post draft
1313
let id = atom#createEntry("http://d.hatena.ne.jp/".hatena_id."/atom/draft", hatena_id, password, entry)
1414

15-
" ちょっと修正して下書きから公開に変更し、新しいIDを得る
15+
" modify it. publish it.
1616
call entry.setContent("<script>alert(1)</script>")
1717
let id = atom#updateEntry(id, hatena_id, password, entry, {"X-HATENA-PUBLISH": 1})
1818

19-
" 公開エントリを取得して表示する
19+
" get the entry.
2020
let entry = atom#getEntry(id, hatena_id, password)
2121
echo entry.getTitle()
2222
echo entry.getContent()
2323

24-
" エントリを消す
24+
" delete the entry.
2525
call atom#deleteEntry(id, hatena_id, password)
2626

2727
" vim:set ft=vim:

example/jugem.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ let imgurl = api.newMediaObject(jugem_id, jugem_id, password, {
1212
\ "path": imagePath,
1313
\})
1414

15-
let text = "どないや<br /><img src=\"".imgurl["url"]."\">"
15+
let text = "How about this?<br /><img src=\"".imgurl["url"]."\">"
1616

1717
echo api.newPost(jugem_id, jugem_id, password, {
18-
\ "title": "vimでmetaWeblogAPIを叩いて画像付きブログをポストする",
18+
\ "title": "post from webpi-vim",
1919
\ "description": text,
2020
\ "dateCreated": "",
2121
\ "categories": ["test"],

example/livedoor.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ scriptencoding utf-8
33
let livedoor_id = 'your-livedoor-id'
44
let password = 'your-livedoor-password'
55

6-
" エントリを書く
6+
" write entry
77
let entry = atom#newEntry()
8-
call entry.setTitle("日記エントリータイトル")
8+
call entry.setTitle("title of entry")
99
call entry.setContentType("text/html")
1010
call entry.setContent("<script>alert(3)</script>")
1111

example/rss.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
for item in webapi#feed#parseURL('http://rss.slashdot.org/Slashdot/slashdot')
2+
echo item.link
3+
echo " " item.title
4+
endfor

example/weather.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
let loc = 'Osaka'
2+
let dom = webapi#xml#parseURL(printf('http://www.google.com/ig/api?weather=%s', webapi#http#encodeURIComponent(loc)))
3+
echo loc.'''s current weather is '.dom.find('current_conditions').childNode('condition').attr['data']

0 commit comments

Comments
 (0)