@@ -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,22 @@ 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 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
+
324
341
325
342
326
343
(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."
344
361
(post-data '())
345
362
(post-lang-field-name nil )
346
363
(parser 'buffer-string )
364
+ (headers-lambda nil )
347
365
(lang-overrides '())
348
366
(lang-uri-separator nil )
349
367
(error-lambda 'webpaste--providers-error-lambda )
@@ -390,6 +408,10 @@ Optional params:
390
408
`webpaste--providers-error-lambda-no-failover' available if
391
409
you need a provider that isn't allowed to failover.
392
410
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
+
393
415
:post-field-lambda Function that builds and returns the post data that should be
394
416
sent to the provider. It should accept named parameters by
395
417
the names TEXT, POST-FIELD and POST-DATA. POST-DATA should
@@ -432,6 +454,7 @@ Optional params:
432
454
:post-lang-field-name post-lang-field-name
433
455
:post-data post-data)
434
456
:parser parser
457
+ :headers (when headers-lambda (funcall (funcall headers-lambda)))
435
458
:success (funcall success-lambda)
436
459
:sync sync
437
460
:error (funcall error-lambda :text text))))))
0 commit comments