pastebin-js
Advanced tools
Comparing version 0.3.6 to 0.4.0
@@ -51,2 +51,11 @@ 'use strict'; | ||
Pastebin.prototype.createPaste = function (text, title, format, privacy, expiration) { | ||
if (_.isObject(text) && typeof title === 'undefined') { | ||
// assume the first parameter is an object with the information | ||
expiration = text.expiration; | ||
privacy = text.privacy; | ||
format = text.format; | ||
title = text.title; | ||
text = text.text; | ||
} | ||
var deferred = Q.defer(); | ||
@@ -79,2 +88,3 @@ var p = { | ||
if (typeof privacy !== 'undefined' && privacy !== null) { | ||
p.api_paste_private = privacy; | ||
if (privacy === 0 || privacy === 1) { | ||
@@ -132,2 +142,11 @@ p.api_paste_private = privacy; | ||
Pastebin.prototype.createPasteFromFile = function (filename, title, format, privacy, expiration) { | ||
if (_.isObject(filename) && typeof title === 'undefined') { | ||
// assume the first parameter is an object with the information | ||
expiration = filename.expiration; | ||
privacy = filename.privacy; | ||
format = filename.format; | ||
title = filename.title; | ||
filename = filename.filename; | ||
} | ||
var deferred = Q.defer(); | ||
@@ -430,2 +449,53 @@ var self = this; | ||
/*************************************************** | ||
* Synchronous methods | ||
***************************************************/ | ||
function runWithCallback(promiseFunc, callback) { | ||
if (!_.isFunction(callback)) { throw new Error('This function requires a callback!'); } | ||
promiseFunc.then(function (data) { | ||
callback(null, data); | ||
}).fail(function (err) { | ||
callback(err, null); | ||
}); | ||
} | ||
Pastebin.prototype.getPasteSync = function (id, callback) { | ||
runWithCallback(this.getPaste(id), callback); | ||
}; | ||
Pastebin.prototype.createPasteSync = function (text, title, format, privacy, expiration, callback) { | ||
if (_.isObject(text) && _.isFunction(title)) { | ||
callback = title; | ||
runWithCallback(this.createPaste(text), callback); | ||
} else { | ||
runWithCallback(this.createPaste(text, title, format, privacy, expiration), callback); | ||
} | ||
}; | ||
Pastebin.prototype.createPasteFromFileSync = function (filename, title, format, privacy, expiration, callback) { | ||
if (_.isObject(filename) && _.isFunction(title)) { | ||
callback = title; | ||
runWithCallback(this.createPasteFromFile(filename), callback); | ||
} else { | ||
runWithCallback(this.createPasteFromFile(filename, title, format, privacy, expiration), callback); | ||
} | ||
}; | ||
Pastebin.prototype.deletePasteSync = function (pasteID, callback) { | ||
runWithCallback(this.deletePaste(pasteID), callback); | ||
}; | ||
Pastebin.prototype.listUserPastesSync = function (limit, callback) { | ||
runWithCallback(this.listUserPastes(limit), callback); | ||
}; | ||
Pastebin.prototype.listTrendingPastesSync = function (callback) { | ||
runWithCallback(this.listTrendingPastes(), callback); | ||
}; | ||
Pastebin.prototype.getUserInfoSync = function (callback) { | ||
runWithCallback(this.getUserInfo(), callback); | ||
}; | ||
module.exports = Pastebin; |
{ | ||
"name": "pastebin-js", | ||
"version": "0.3.6", | ||
"version": "0.4.0", | ||
"npm-shrinkwrap-version": "5.4.1", | ||
@@ -5,0 +5,0 @@ "node-version": "v4.1.0", |
{ | ||
"name": "pastebin-js", | ||
"version": "0.3.6", | ||
"version": "0.4.0", | ||
"description": "NodeJS module for Pastebin API", | ||
@@ -5,0 +5,0 @@ "main": "index", |
@@ -118,2 +118,25 @@ pastebin-js | ||
You can also use an object as the first parameter: | ||
```js | ||
pastebin | ||
.createPaste({ | ||
text: "This is a private paste", | ||
title: "Private", | ||
format: null, | ||
privacy: 2, | ||
expiration: '10M' | ||
}) | ||
pastebin | ||
.createPasteFromFile({ | ||
text: "./filename.txt", | ||
title: "Public text file listed under my username", | ||
format: null, | ||
privacy: 3, | ||
expiration: '10M' | ||
}) | ||
``` | ||
### Privacy | ||
@@ -136,3 +159,20 @@ | ||
## Synchronous support | ||
pastebin-js now has synchronous support as well. The following methods are available: | ||
``` | ||
.getPasteSync(id, callback) | ||
.createPasteSync(text, title, format, privacy, expiration, callback) | ||
.createPasteSync(object, callback) | ||
.createPasteFromFileSync(filename, title, format, privacy, expiration, callback) | ||
.createPasteFromFileSync(object, callback) | ||
.deletePasteSync(pasteID, callback) | ||
.listUserPastesSync(limit, callback) | ||
.listTrendingPastesSync(callback) | ||
.getUserInfoSync(callback) | ||
``` | ||
The callback will be called with two parameters: ```callback(err, data)``` | ||
## Bugs / issues | ||
@@ -146,3 +186,3 @@ | ||
Copyright (c) 2013-2013 J.W. Lagendijk <jwlagendijk@gmail.com> | ||
Copyright (c) 2013-2016 J.W. Lagendijk <jwlagendijk@gmail.com> | ||
@@ -149,0 +189,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65333
1038
204