11" =============================================================================
22" File: gist.vim
33" Author: Yasuhiro Matsumoto <mattn.jp@gmail.com>
4- " Last Change: 13 -Apr-2014.
4+ " Last Change: 15 -Apr-2014.
55" Version: 7.1
66" WebPage: http://github.com/mattn/gist-vim
77" License: BSD
@@ -34,10 +34,10 @@ if !exists('g:github_user')
3434 end
3535endif
3636
37- if ! exists (' g:github_api_url ' )
38- let g: github_api_url = substitute (s: system (' git config --get github.apiurl' ), " \n " , ' ' , ' ' )
39- if strlen (g: github_api_url ) == 0
40- let g: github_api_url = ' https://api.github.com'
37+ if ! exists (' g:gist_api_url ' )
38+ let g: gist_api_url = substitute (s: system (' git config --get github.apiurl' ), " \n " , ' ' , ' ' )
39+ if strlen (g: gist_api_url ) == 0
40+ let g: gist_api_url = ' https://api.github.com/ '
4141 end
4242endif
4343
@@ -117,13 +117,13 @@ endfunction
117117let s: bufprefix = ' gist' . (has (' unix' ) ? ' :' : ' _' )
118118function ! s: GistList (gistls, page)
119119 if a: gistls == ' -all'
120- let url = g: github_api_url . ' / gists/public'
120+ let url = g: gist_api_url . ' gists/public'
121121 elseif get (g: , ' gist_show_privates' , 0 ) && a: gistls == ' starred'
122- let url = g: github_api_url . ' / gists/starred'
122+ let url = g: gist_api_url . ' gists/starred'
123123 elseif get (g: , ' gist_show_privates' ) && a: gistls == ' mine'
124- let url = g: github_api_url . ' / gists'
124+ let url = g: gist_api_url . ' gists'
125125 else
126- let url = g: github_api_url . ' / users/' .a: gistls .' /gists'
126+ let url = g: gist_api_url . ' users/' .a: gistls .' /gists'
127127 endif
128128 let winnum = bufwinnr (bufnr (s: bufprefix .a: gistls ))
129129 if winnum != -1
@@ -199,13 +199,13 @@ endfunction
199199function ! gist#list (user , ... )
200200 let page = get (a: 000 , 0 , 0 )
201201 if a: user == ' -all'
202- let url = g: github_api_url . ' / gists/public'
202+ let url = g: gist_api_url . ' gists/public'
203203 elseif get (g: , ' gist_show_privates' , 0 ) && a: user == ' starred'
204- let url = g: github_api_url . ' / gists/starred'
204+ let url = g: gist_api_url . ' gists/starred'
205205 elseif get (g: , ' gist_show_privates' ) && a: user == ' mine'
206- let url = g: github_api_url . ' / gists'
206+ let url = g: gist_api_url . ' gists'
207207 else
208- let url = g: github_api_url . ' / users/' .a: user .' /gists'
208+ let url = g: gist_api_url . ' users/' .a: user .' /gists'
209209 endif
210210
211211 let auth = s: GistGetAuthHeader ()
@@ -221,7 +221,7 @@ function! s:GistGetFileName(gistid)
221221 if len (auth) == 0
222222 return ' '
223223 endif
224- let res = webapi#http#get (g: github_api_url . ' / gists/' .a: gistid , ' ' , { " Authorization" : auth })
224+ let res = webapi#http#get (g: gist_api_url . ' gists/' .a: gistid , ' ' , { " Authorization" : auth })
225225 let gist = webapi#json#decode (res .content)
226226 if has_key (gist, ' files' )
227227 return sort (keys (gist.files ))[0 ]
@@ -234,7 +234,7 @@ function! s:GistDetectFiletype(gistid)
234234 if len (auth) == 0
235235 return ' '
236236 endif
237- let res = webapi#http#get (g: github_api_url . ' / gists/' .a: gistid , ' ' , { " Authorization" : auth })
237+ let res = webapi#http#get (g: gist_api_url . ' gists/' .a: gistid , ' ' , { " Authorization" : auth })
238238 let gist = webapi#json#decode (res .content)
239239 let filename = sort (keys (gist.files ))[0 ]
240240 let ext = fnamemodify (filename, ' :e' )
@@ -262,7 +262,7 @@ endfunction
262262
263263function ! s: GistGet (gistid, clipboard )
264264 redraw | echon ' Getting gist... '
265- let res = webapi#http#get (g: github_api_url . ' / gists/' .a: gistid , ' ' , { " Authorization" : s: GistGetAuthHeader () })
265+ let res = webapi#http#get (g: gist_api_url . ' gists/' .a: gistid , ' ' , { " Authorization" : s: GistGetAuthHeader () })
266266 if res .status = ~ ' ^2'
267267 try
268268 let gist = webapi#json#decode (res .content)
@@ -393,7 +393,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc)
393393 if a: desc != ' '
394394 let gist[" description" ] = a: desc
395395 else
396- let res = webapi#http#get (g: github_api_url . ' / gists/' .a: gistid , ' ' , { " Authorization" : auth })
396+ let res = webapi#http#get (g: gist_api_url . ' gists/' .a: gistid , ' ' , { " Authorization" : auth })
397397 if res .status = ~ ' ^2'
398398 let old_gist = webapi#json#decode (res .content)
399399 let gist[" description" ] = old_gist.description
@@ -403,7 +403,7 @@ function! s:GistUpdate(content, gistid, gistnm, desc)
403403 let gist.files [filename] = { " content" : a: content , " filename" : filename }
404404
405405 redraw | echon ' Updating gist... '
406- let res = webapi#http#post (g: github_api_url . ' / gists/' . a: gistid ,
406+ let res = webapi#http#post (g: gist_api_url . ' gists/' . a: gistid ,
407407 \ webapi#json#encode (gist), {
408408 \ " Authorization" : auth,
409409 \ " Content-Type" : " application/json" ,
@@ -430,7 +430,7 @@ function! s:GistDelete(gistid)
430430 endif
431431
432432 redraw | echon ' Deleting gist... '
433- let res = webapi#http#post (g: github_api_url . ' / gists/' .a: gistid , ' ' , {
433+ let res = webapi#http#post (g: gist_api_url . ' gists/' .a: gistid , ' ' , {
434434 \ " Authorization" : auth,
435435 \ " Content-Type" : " application/json" ,
436436 \} , ' DELETE' )
@@ -502,7 +502,7 @@ function! s:GistPost(content, private, desc, anonymous)
502502 endif
503503
504504 redraw | echon ' Posting it to gist... '
505- let res = webapi#http#post (g: github_api_url . ' / gists' , webapi#json#encode (gist), header)
505+ let res = webapi#http#post (g: gist_api_url . ' gists' , webapi#json#encode (gist), header)
506506 if res .status = ~ ' ^2'
507507 let obj = webapi#json#decode (res .content)
508508 let loc = obj[" html_url" ]
@@ -558,7 +558,7 @@ function! s:GistPostBuffers(private, desc, anonymous)
558558 endif
559559
560560 redraw | echon ' Posting it to gist... '
561- let res = webapi#http#post (g: github_api_url . ' / gists' , webapi#json#encode (gist), header)
561+ let res = webapi#http#post (g: gist_api_url . ' gists' , webapi#json#encode (gist), header)
562562 if res .status = ~ ' ^2'
563563 let obj = webapi#json#decode (res .content)
564564 let loc = obj[" html_url" ]
@@ -612,10 +612,10 @@ function! gist#Gist(count, line1, line2, ...)
612612 if arg = ~ ' ^\(-h\|--help\)$\C'
613613 help :Gist
614614 return
615- elseif arg = ~ ' ^\(-g\|--git\)$\C' && gistidbuf != ' ' && g: github_api_url == ' https://api.github.com' && has_key (b: , ' gist' ) && has_key (b: gist , ' id' )
615+ elseif arg = ~ ' ^\(-g\|--git\)$\C' && gistidbuf != ' ' && g: gist_api_url == ' https://api.github.com/ ' && has_key (b: , ' gist' ) && has_key (b: gist , ' id' )
616616 echo printf (' git clone git@github.com:%s' , b: gist [' id' ])
617617 return
618- elseif arg = ~ ' ^\(-G\|--gitclone\)$\C' && gistidbuf != ' ' && g: github_api_url == ' https://api.github.com' && has_key (b: , ' gist' ) && has_key (b: gist , ' id' )
618+ elseif arg = ~ ' ^\(-G\|--gitclone\)$\C' && gistidbuf != ' ' && g: gist_api_url == ' https://api.github.com/ ' && has_key (b: , ' gist' ) && has_key (b: gist , ' id' )
619619 exe ' !' printf (' git clone git@github.com:%s' , b: gist [' id' ])
620620 return
621621 elseif arg = ~ ' ^\(-la\|--listall\)$\C'
@@ -640,7 +640,7 @@ function! gist#Gist(count, line1, line2, ...)
640640 let gistdesc = ' '
641641 elseif arg = ~ ' ^\(-c\|--clipboard\)$\C'
642642 let clipboard = 1
643- elseif arg = ~ ' ^--rawurl$\C' && gistidbuf != ' ' && g: github_api_url == ' https://api.github.com'
643+ elseif arg = ~ ' ^--rawurl$\C' && gistidbuf != ' ' && g: gist_api_url == ' https://api.github.com/ '
644644 let gistid = gistidbuf
645645 echo ' https://gist.github.com/raw/' .gistid
646646 return
@@ -656,7 +656,7 @@ function! gist#Gist(count, line1, line2, ...)
656656 echohl ErrorMsg | echomsg v: errmsg | echohl None
657657 else
658658 let gistid = gistidbuf
659- let res = webapi#http#post (g: github_api_url . ' / gists/' .gistid.' /star' , ' ' , { " Authorization" : auth }, ' PUT' )
659+ let res = webapi#http#post (g: gist_api_url . ' gists/' .gistid.' /star' , ' ' , { " Authorization" : auth }, ' PUT' )
660660 if res .status = ~ ' ^2'
661661 echomsg " Stared" gistid
662662 else
@@ -670,7 +670,7 @@ function! gist#Gist(count, line1, line2, ...)
670670 echohl ErrorMsg | echomsg v: errmsg | echohl None
671671 else
672672 let gistid = gistidbuf
673- let res = webapi#http#post (g: github_api_url . ' / gists/' .gistid.' /star' , ' ' , { " Authorization" : auth }, ' DELETE' )
673+ let res = webapi#http#post (g: gist_api_url . ' gists/' .gistid.' /star' , ' ' , { " Authorization" : auth }, ' DELETE' )
674674 if res .status = ~ ' ^2'
675675 echomsg " Unstared" gistid
676676 else
@@ -685,7 +685,7 @@ function! gist#Gist(count, line1, line2, ...)
685685 return
686686 else
687687 let gistid = gistidbuf
688- let res = webapi#http#post (g: github_api_url . ' / gists/' .gistid.' /fork' , ' ' , { " Authorization" : auth })
688+ let res = webapi#http#post (g: gist_api_url . ' gists/' .gistid.' /fork' , ' ' , { " Authorization" : auth })
689689 if res .status = ~ ' ^2'
690690 let obj = webapi#json#decode (res .content)
691691 let gistid = obj[" id" ]
@@ -807,7 +807,7 @@ function! s:GistGetAuthHeader()
807807 return ' '
808808 endif
809809 let insecureSecret = printf (" basic %s" , webapi#base64#b64encode (g: github_user ." :" .password))
810- let res = webapi#http#post (g: github_api_url . ' / authorizations' , webapi#json#encode ({
810+ let res = webapi#http#post (g: gist_api_url . ' authorizations' , webapi#json#encode ({
811811 \ " scopes" : [" gist" ],
812812 \ " note" : " Gist.vim on " .hostname (),
813813 \ " note_url" : " http://www.vim.org/scripts/script.php?script_id=2423"
@@ -822,7 +822,7 @@ function! s:GistGetAuthHeader()
822822 let v: errmsg = ' Canceled'
823823 return ' '
824824 endif
825- let res = webapi#http#post (g: github_api_url . ' / authorizations' , webapi#json#encode ({
825+ let res = webapi#http#post (g: gist_api_url . ' authorizations' , webapi#json#encode ({
826826 \ " scopes" : [" gist" ],
827827 \ " note" : " Gist.vim on " .hostname (),
828828 \ " note_url" : " http://www.vim.org/scripts/script.php?script_id=2423"
0 commit comments