Skip to content

Commit

Permalink
added support for delete endpoing
Browse files Browse the repository at this point in the history
  • Loading branch information
apexdodge committed Jan 28, 2019
1 parent 8bd32ba commit 407e25d
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 3 deletions.
83 changes: 83 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

test.js
package-lock.json
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Resources this API supports:
- [Headless Chrome](#chrome)
- [LibreOffice](#libreoffice)
- [Merge / Concatenate PDFs](#merge)
- [Helper Methods](#helpers)

## <a name="authorization"></a>Authorization

Expand Down Expand Up @@ -229,4 +230,17 @@ a2pClient.merge(urls, inline = true, filename = 'test.pdf').then(function(result
console.log(result);
});
```

---

## <a name="helpers"></a>Helper Methods

**Delete a PDF on Command with delete(responseId)**

By default, Api2Pdf will automatically delete your PDFs after 24 hours. If you have higher security requirements and need to delete the PDFs at-will, you can do so by calling the `delete(responseId)` method on the Api2Pdf object where `responseId` parameter comes from the responseId attribute in the result.

```
a2pClient.headlessChromeFromHtml('<p>Hello, World</p>').then(function(result) {
console.log(result);
a2pClient.delete(result.responseId); //delete pdf by using responseId attribute
});
```
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ module.exports = class Api2Pdf {
return this._makeRequest(API2PDF_LIBREOFFICE_CONVERT, payload);
}

delete(responseId) {
var endpoint = API2PDF_BASE_ENDPOINT + `/pdf/${responseId}`;
return new Promise((resolve, reject) => {
request.delete(endpoint, { headers: { Authorization: this.apiKey } }, function(e, r, body) {
var result = JSON.parse(body);
if (r.statusCode == 200 && result.success == true) {
return resolve(result);
}
else {
return reject(result);
}
});
});
}

_makeRequest(endpoint, payload) {
return new Promise((resolve, reject) => {
request.post({ url: endpoint, body: JSON.stringify(payload), headers: { Authorization: this.apiKey } }, function(e, r, body) {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "api2pdf",
"version": "1.0.0",
"version": "1.1.0",
"description": "Api2Pdf is a powerful PDF generation API with no rate limits or file size constraints. Api2Pdf runs on AWS Lambda, a serverless architecture powered by Amazon to scale to millions of requests while being up to 90% cheaper than alternatives. Supports wkhtmltopdf, Headless Chrome, LibreOffice, and PDF Merge. You can also generate barcodes with ZXING (Zebra Crossing)",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,5 +28,8 @@
"bugs": {
"url": "https://github.com/Api2Pdf/api2pdf.node/issues"
},
"homepage": "https://github.com/Api2Pdf/api2pdf.node#readme"
"homepage": "https://github.com/Api2Pdf/api2pdf.node#readme",
"dependencies": {
"request": "^2.88.0"
}
}

0 comments on commit 407e25d

Please sign in to comment.