Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit d1ae289a5c651a8ef8894fe1126723c830e7ec47 @jessefulton committed Apr 15, 2012
Showing with 66 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. 0 README
  3. +1 −0 index.js
  4. BIN lib/.DS_Store
  5. +37 −0 lib/pastehtml.js
  6. +25 −0 package.json
  7. +2 −0 test.js
@@ -0,0 +1 @@
+node_modules
No changes.
@@ -0,0 +1 @@
+module.exports = require('./lib/pastehtml');
Binary file not shown.
@@ -0,0 +1,37 @@
+var http = require('http');
+var querystring = require('querystring');
+
+
+/**
+ * This will create a page on pastehtml.com and will return the URL of that page
+ *
+ * @param {String} data the text/html/markdown
+ * @param {String} type either "html", "txt" or "mrk"
+ * @pram {Function} callback handler, passed the URL of the created page
+ *
+ * @see http://pastehtml.com/help/api
+ */
+module.exports.create = function(data, type, callback) {
+
+ var post_data = querystring.stringify({
+ "txt": data
+ });
+
+ var options = {
+ hostname: 'pastehtml.com',
+ path: '/upload/create?input_type=' + type + '&result=address',
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/x-www-form-urlencoded',
+ 'Content-Length': post_data.length
+ }
+ };
+
+ var req = http.request(options, function(res) {
+ res.setEncoding('utf8');
+ res.on('data', callback);
+ });
+
+ req.write(post_data);
+ req.end();
+};
@@ -0,0 +1,25 @@
+{
+ "name": "pastehtml",
+ "version": "0.0.1",
+ "author": "Jesse Fulton <jesse.fulton@gmail.com> (http://jessefulton.com)",
+ "description": "API for pastehtml.com",
+ "contributors": [
+ "Jesse Fulton <jessefulton@gmail.com>"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/jessefulton/node-pastehtml.git"
+ },
+ "keywords": [
+ "paste", "api", "pastehtml", "pastebin"
+ ],
+ "dependencies": {
+ "querystring": "0.1.0"
+ },
+ "devDependencies": {},
+ "optionalDependencies": {},
+ "engines": {
+ "node": "*"
+ },
+ "main": "index"
+}
@@ -0,0 +1,2 @@
+var pastehtml = require('./index');
+pastehtml.create("<h1>Goodbye, World</h1>", "html", function(url) { console.log(url); });

0 comments on commit d1ae289

Please sign in to comment.