Skip to content

Fall back to ix.io when anonymous flag is used (Gist no longer supports anonymous posts) #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions autoload/gist.vim
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,29 @@ function! s:update_GistID(id) abort
return ret
endfunction

" AnonymousPost function:
" Post new pastebin. This is a fallback because Gist no longer supports
" anonymous gists.
"
function! s:AnonymousPost(content) abort
let filename = s:get_current_filename(1)
let ext = expand('%:e')
redraw | echon 'Posting anonymously to ix.io... (Gist no longer supports anonymous posts)'
let data = {'f:1': a:content, 'name:1': filename, 'ext:1': ext}
let res = webapi#http#post('http://ix.io', data)
if res.status =~# '^2'
let loc = res.content
let loc = substitute(loc, '\n*$', '', 'g')
let loc = loc.'/'
redraw | echomsg 'Done: '.loc
else
let loc = ''
echohl ErrorMsg | echomsg 'Post failed: '. res | echohl None
endif
return loc
endfunction
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. But I want to drop anonymous post.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright then. It was my first time writing VimL 👍

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to keep this, please do

if exists('g:gist_anonymous_fallback')
  return call('g:gist_anonymous_fallback', [a:content])
endif
" raise error?


"
" GistPost function:
" Post new gist to github
"
Expand All @@ -652,22 +675,27 @@ endfunction
" GistID: 123123
"
function! s:GistPost(content, private, desc, anonymous) abort
" Gist disabled anonymous gists so we are fallbacking on another anonymous
" pastebin service.
if a:anonymous
return s:AnonymousPost(a:content)
endif

let gist = { "files" : {}, "description": "","public": function('webapi#json#true') }
if a:desc !=# ' ' | let gist['description'] = a:desc | endif
if a:private | let gist['public'] = function('webapi#json#false') | endif
let filename = s:get_current_filename(1)
let gist.files[filename] = { "content": a:content, "filename": filename }

let header = {"Content-Type": "application/json"}
if !a:anonymous
let auth = s:GistGetAuthHeader()
if len(auth) == 0
redraw
echohl ErrorMsg | echomsg v:errmsg | echohl None
return
endif
let header['Authorization'] = auth

let auth = s:GistGetAuthHeader()
if len(auth) == 0
redraw
echohl ErrorMsg | echomsg v:errmsg | echohl None
return
endif
let header['Authorization'] = auth

redraw | echon 'Posting it to gist... '
let res = webapi#http#post(g:gist_api_url.'gists', webapi#json#encode(gist), header)
Expand Down Expand Up @@ -911,6 +939,11 @@ function! gist#Gist(count, bang, line1, line2, ...) abort
else
let url = ''
if multibuffer == 1
if anonymous == 1
let msg = 'Anonymous flag cannot be used with multiple buffers.'
echohl ErrorMsg | echomsg msg | echohl None
return 0
endif
let url = s:GistPostBuffers(private, gistdesc, anonymous)
else
if a:count < 1
Expand Down