@@ -135,6 +135,7 @@ This uses `browse-url-generic' to open URLs."
135135
136136 (" gist.github.com"
137137 :uri " https://api.github.com/gists"
138+ :headers-lambda webpaste--provider-gist-headers
138139 :post-field nil
139140 :post-field-lambda (lambda () (cl-function (lambda (&key text &allow-other-keys )
140141 (let ((filename (if (buffer-file-name )
@@ -321,6 +322,22 @@ This is the default failover hook that we use for most providers."
321322 (webpaste--return-url (cdr (assq 'link (json-read-from-string data)))))))
322323
323324
325+ (cl-defun webpaste--provider-gist-headers ()
326+ " Provide headers for gist API authentication.
327+
328+ This expects your authinfo to contain authorization for using gist API.
329+ You can generate your token at https://github.com/settings/tokens
330+ Only gist scope is necessary.
331+
332+ Then save the token in your authinfo as:
333+ machine api.github.com/gists login wgetpaste password <token>"
334+ (cl-function (lambda ()
335+ (cons `(" Authorization" . ,(concat " token "
336+ (auth-source-pick-first-password
337+ :host " api.github.com/gists"
338+ :login " wgetpaste" ))) nil ))))
339+
340+
324341
325342
326343(cl-defun webpaste--get-lang-alist-with-overrides (overrides )
@@ -344,6 +361,7 @@ This is the default failover hook that we use for most providers."
344361 (post-data '())
345362 (post-lang-field-name nil )
346363 (parser 'buffer-string )
364+ (headers-lambda nil )
347365 (lang-overrides '())
348366 (lang-uri-separator nil )
349367 (error-lambda 'webpaste--providers-error-lambda )
@@ -390,6 +408,10 @@ Optional params:
390408 `webpaste--providers-error-lambda-no-failover' available if
391409 you need a provider that isn't allowed to failover.
392410
411+ :headers-lambda Function that builds and returns headers that should be sent
412+ to the provider. This can be useful to add authentication
413+ for example.
414+
393415:post-field-lambda Function that builds and returns the post data that should be
394416 sent to the provider. It should accept named parameters by
395417 the names TEXT, POST-FIELD and POST-DATA. POST-DATA should
@@ -432,6 +454,7 @@ Optional params:
432454 :post-lang-field-name post-lang-field-name
433455 :post-data post-data)
434456 :parser parser
457+ :headers (when headers-lambda (funcall (funcall headers-lambda)))
435458 :success (funcall success-lambda)
436459 :sync sync
437460 :error (funcall error-lambda :text text))))))
0 commit comments