@@ -135,6 +135,7 @@ This uses `browse-url-generic' to open URLs."
135
135
136
136
(" gist.github.com"
137
137
:uri " https://api.github.com/gists"
138
+ :headers-lambda webpaste--provider-gist-headers
138
139
:post-field nil
139
140
:post-field-lambda (lambda () (cl-function (lambda (&key text &allow-other-keys )
140
141
(let ((filename (if (buffer-file-name )
@@ -321,6 +322,25 @@ This is the default failover hook that we use for most providers."
321
322
(webpaste--return-url (cdr (assq 'link (json-read-from-string data)))))))
322
323
323
324
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 webpaste password <token>"
334
+ (cl-function (lambda ()
335
+ (cons `(" Authorization"
336
+ .
337
+ ,(concat " token "
338
+ (auth-source-pick-first-password
339
+ :host " api.github.com/gists"
340
+ :login " webpaste" )))
341
+ nil ))))
342
+
343
+
324
344
325
345
326
346
(cl-defun webpaste--get-lang-alist-with-overrides (overrides )
@@ -344,6 +364,7 @@ This is the default failover hook that we use for most providers."
344
364
(post-data '())
345
365
(post-lang-field-name nil )
346
366
(parser 'buffer-string )
367
+ (headers-lambda nil )
347
368
(lang-overrides '())
348
369
(lang-uri-separator nil )
349
370
(error-lambda 'webpaste--providers-error-lambda )
@@ -390,6 +411,10 @@ Optional params:
390
411
`webpaste--providers-error-lambda-no-failover' available if
391
412
you need a provider that isn't allowed to failover.
392
413
414
+ :headers-lambda Function that builds and returns headers that should be sent
415
+ to the provider. This can be useful to add authentication
416
+ for example.
417
+
393
418
:post-field-lambda Function that builds and returns the post data that should be
394
419
sent to the provider. It should accept named parameters by
395
420
the names TEXT, POST-FIELD and POST-DATA. POST-DATA should
@@ -432,6 +457,7 @@ Optional params:
432
457
:post-lang-field-name post-lang-field-name
433
458
:post-data post-data)
434
459
:parser parser
460
+ :headers (when headers-lambda (funcall (funcall headers-lambda)))
435
461
:success (funcall success-lambda)
436
462
:sync sync
437
463
:error (funcall error-lambda :text text))))))
0 commit comments