Added support for custom handler of how to build the post data for providers

master
Elis Axelsson 9 years ago
parent 69f9452003
commit 6ea53d0e67
No known key found for this signature in database
GPG Key ID: D57EFA625C9A925F
  1. 17
      webpaste.el

@ -91,6 +91,14 @@ each run.")
(replace-regexp-in-string "\n$" "" data))))) (replace-regexp-in-string "\n$" "" data)))))
"Predefined success callback for providers returning a string with URL.") "Predefined success callback for providers returning a string with URL.")
(defvar webpaste/providers-default-post-field-lambda
(lambda (text post-field post-data)
(cl-pushnew (cons post-field text) post-data)
post-data)
"Predefined lambda for building post fields.")
(cl-defun webpaste-provider (&key uri (cl-defun webpaste-provider (&key uri
@ -99,6 +107,7 @@ each run.")
(post-data '()) (post-data '())
(sync nil) (sync nil)
post-field post-field
(post-field-lambda webpaste/providers-default-post-field-lambda)
error-lambda error-lambda
success-lambda) success-lambda)
"Function to create the lambda function for a provider. "Function to create the lambda function for a provider.
@ -115,6 +124,9 @@ Usage:
:post-field Name of the field to insert the code into. :post-field Name of the field to insert the code into.
:sync Set to t to wait until request is done. Defaults to nil. This :sync Set to t to wait until request is done. Defaults to nil. This
should only be used for debugging purposes. should only be used for debugging purposes.
:post-field-lambda Function that builds and returns the post data that should be
sent to the provider. It should accept the parameter TEXT
only which contains the content that should be sent.
:success-lambda Callback sent to `request', look up how to write these in the :success-lambda Callback sent to `request', look up how to write these in the
documentation for `request'. documentation for `request'.
:error-lambda Callback sent to `request', look up how to write these in the :error-lambda Callback sent to `request', look up how to write these in the
@ -126,13 +138,10 @@ Usage:
"Paste TEXT to provider" "Paste TEXT to provider"
(prog1 nil (prog1 nil
;; Local variable post-data
(cl-pushnew (cons post-field text) post-data)
;; Do request ;; Do request
(request uri (request uri
:type type :type type
:data post-data :data (funcall post-field-lambda text post-field post-data)
:parser parser :parser parser
:success success-lambda :success success-lambda
:sync sync :sync sync

Loading…
Cancel
Save