Shared success lambdas between different paste providers

This will make it easier to create providers and to test providers.
master
Elis Axelsson 9 years ago
parent e04d885b0b
commit 406d713873
No known key found for this signature in database
GPG Key ID: D57EFA625C9A925F
  1. 4
      test/webpaste-test.el
  2. 74
      webpaste.el

@ -16,8 +16,8 @@
:post-field "data" :post-field "data"
:no-failover t :no-failover t
:sync t :sync t
:success (cl-function (lambda (&allow-other-keys) :success-lambda (cl-function (lambda (&allow-other-keys)
(setq success-lambda nil)))))) (setq success-lambda nil))))))
(funcall provider "dummy-text") (funcall provider "dummy-text")

@ -68,27 +68,27 @@ each run.")
(no-failover nil) (no-failover nil)
(sync nil) (sync nil)
post-field post-field
success) success-lambda)
"Macro to create the lambda function for a provider. "Macro to create the lambda function for a provider.
This macro accepts the parameters :uri, :type, :parser, :post-data, :post-field This macro accepts the parameters :uri, :type, :parser, :post-data, :post-field
and :success. and :success-lambda.
Usage: Usage:
(webpaste-provider (webpaste-provider
[:keyword [option]]...) [:keyword [option]]...)
:uri URI that we should do the request to to paste data. :uri URI that we should do the request to to paste data.
:type HTTP Request type, defaults to POST. :type HTTP Request type, defaults to POST.
:parser Defines how request.el parses the result. Look up :parser for :parser Defines how request.el parses the result. Look up :parser for
`request`. This defaults to 'buffer-string. `request'. This defaults to 'buffer-string.
:post-data Default post fields sent to service. Defaults to nil. :post-data Default post fields sent to service. Defaults to nil.
:post-field Name of the field to insert the code into. :post-field Name of the field to insert the code into.
:no-failover Set to t to not allow doing failovers, Defaults to nil. :no-failover Set to t to not allow doing failovers. Defaults to nil.
:sync Set to t to wait until request is done. Defaults to nil. :sync Set to t to wait until request is done. Defaults to nil. This
This should only be used for debugging purposes. should only be used for debugging purposes.
:success 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'."
(lambda (text) (lambda (text)
"Paste TEXT to provider" "Paste TEXT to provider"
@ -101,7 +101,7 @@ Usage:
:type type :type type
:data post-data :data post-data
:parser parser :parser parser
:success success :success success-lambda
:sync sync :sync sync
:error :error
(cl-function (lambda (&key error-thrown &allow-other-keys) (cl-function (lambda (&key error-thrown &allow-other-keys)
@ -111,36 +111,43 @@ Usage:
;;; Predefined success lambdas for providers
(defvar webpaste/providers-success-location-header
(cl-function (lambda (&key response &allow-other-keys)
(when response
(webpaste-return-url
(request-response-header response "Location")))))
"Predefined success callback for providers returning a Location header.")
(defvar webpaste/providers-success-returned-string
(cl-function (lambda (&key data &allow-other-keys)
(when data
(webpaste-return-url
(replace-regexp-in-string "\n$" "" data)))))
"Predefined success callback for providers returning a string with URL.")
;;; Define providers ;;; Define providers
(defcustom webpaste-providers-alist (defcustom webpaste-providers-alist
`(("ptpb.pw" `(("ptpb.pw"
,(webpaste-provider ,(webpaste-provider
:uri "https://ptpb.pw/" :uri "https://ptpb.pw/"
:post-field "c" :post-field "c"
:success :success-lambda webpaste/providers-success-location-header))
(cl-function (lambda (&key response &allow-other-keys)
(webpaste-return-url
(request-response-header response "Location"))))))
("ix.io" ("ix.io"
,(webpaste-provider ,(webpaste-provider
:uri "http://ix.io/" :uri "http://ix.io/"
:post-field "f:1" :post-field "f:1"
:success :success-lambda webpaste/providers-success-returned-string))
(cl-function (lambda (&key data &allow-other-keys)
(when data
(webpaste-return-url
(replace-regexp-in-string "\n$" "" data)))))))
("sprunge.us" ("sprunge.us"
,(webpaste-provider ,(webpaste-provider
:uri "http://sprunge.us/" :uri "http://sprunge.us/"
:post-field "sprunge" :post-field "sprunge"
:success :success-lambda webpaste/providers-success-returned-string))
(cl-function (lambda (&key data &allow-other-keys)
(when data
(webpaste-return-url
(replace-regexp-in-string "\n$" "" data)))))))
("dpaste.com" ("dpaste.com"
,(webpaste-provider ,(webpaste-provider
@ -150,10 +157,7 @@ Usage:
("poster" . "") ("poster" . "")
("expiry_days" . 1)) ("expiry_days" . 1))
:post-field "content" :post-field "content"
:success :success-lambda webpaste/providers-success-location-header))
(cl-function (lambda (&key response &allow-other-keys)
(webpaste-return-url
(request-response-header response "Location"))))))
("dpaste.de" ("dpaste.de"
,(webpaste-provider ,(webpaste-provider
@ -162,11 +166,7 @@ Usage:
("format" . "url") ("format" . "url")
("expires" . 86400)) ("expires" . 86400))
:post-field "content" :post-field "content"
:success :success-lambda webpaste/providers-success-returned-string)))
(cl-function (lambda (&key data &allow-other-keys)
(when data
(webpaste-return-url
(replace-regexp-in-string "\n$" "" data))))))))
"Define all webpaste.el providers. "Define all webpaste.el providers.
Consists of provider name and lambda function to do the actuall call to the Consists of provider name and lambda function to do the actuall call to the

Loading…
Cancel
Save