From d3e497df4c2535de14efd6022aaa7c7c8bdc0838 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Sat, 11 Jan 2014 16:03:50 +0100 Subject: [PATCH] Added sample api scripts to docs. --- docs/api.rst | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/api.rst b/docs/api.rst index ebd6ded..fcbdb63 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -10,7 +10,7 @@ do is a simple ``POST`` request to the API endpoint ``/api/``:: Available POST data for an API call: ----------------------------------------- +==================================== ``content`` (required) ~~~~~~~~~~~~~~~~~~~~~~ @@ -54,3 +54,31 @@ Optional. The format of the API response. Choices are: history page since they are related to a browser session. .. _lexer list: https://github.com/bartTC/dpaste/blob/master/dpaste/highlight.py#L25 + +Example code snippets: +====================== + +A sample Python 2 script to publish snippets:: + + #!/usr/bin/env python + + import urllib + import urllib2 + import sys + + def paste_code(): + request = urllib2.Request( + 'https://dpaste.de/api/', + urllib.urlencode([('content', sys.stdin.read())]), + ) + response = urllib2.urlopen(request) + # Strip surrounding quotes (NB: response has no trailing newline) + print response.read()[1:-1] + + if __name__ == '__main__': + paste_code() + +You can simply use curl to publish a whole file:: + + $ alias dpaste="curl -F 'content=<-' https://dpaste.de/api/" + $ cat foo.txt | dpaste