rdmurphy / node-documentcloud

:page_facing_up::cloud: A Node.js wrapper around the DocumentCloud API.
https://www.npmjs.com/package/documentcloud
12 stars 1 forks source link

node-documentcloud

A Node.js wrapper around the DocumentCloud API. Requires Node.js >= 4.

Installation

npm install --save documentcloud

Usage

The client interface makes it possible to pass in your DocumentCloud username and password so you can do authenticated requests. While this is not required for some endpoints, your experience will likely be much better if you are authenticated.

// import the library
var DocumentCloudClient = require('documentcloud');

// create a client
var client = new DocumentCloudClient('username', 'password');

// get to work!
client.documents.get('1659580-economic-analysis-of-the-south-pole-traverse', function (err, response) {
  if (err) throw err;

  console.log(response);
});

// {
//   "status_code": 200,
//   "response": {
//     "document": {
//       "id": "1659580-economic-analysis-of-the-south-pole-traverse",
//       "title": "Economic Analysis of the South Pole Traverse",
//       "access": "public",
//       "pages": 38,
//       ...

API Docs

DocumentCloudClient

The main DocumentCloud client. A DocumentCloud username and password are optional, but some methods are not available to unauthenticated users.

It is also possible to override the default base API URL.

Parameters

Examples

var DocumentCloudClient = require('documentcloud');

var client = new DocumentCloudClient('email@example.com', 'example_pw');

ProjectClient

Handles all methods that interact with project API endpoints.

Should never be created manually — can be accessed on an instance of DocumentCloudClient at DocumentCloudClient.projects.

Parameters

create

Creates a project.

Parameters

delete

Deletes a project. Documents associated with the project are not effected.

Parameters

list

Lists all projects associated with the account.

Parameters

update

Updates data associated with a project. Do note - this replaces every field, whether it is provided or not. For example - if you do not provide a list of document_ids, it will be set to none.

Parameters

DocumentClient

Handles all methods that interact with document API endpoints.

Should never be created manually — can be accessed on an instance of DocumentCloudClient at DocumentCloudClient.documents.

Parameters

delete

Deletes a document on DocumentCloud.

Parameters

entities

Returns a list of entities associated with a document.

Parameters

get

Get a document's metadata from DocumentCloud.

Parameters

Examples

client.documents.get('1659580-economic-analysis-of-the-south-pole-traverse', function (err, response) {
  if (err) throw err;

  console.log(response);
});

// {
//   "status_code": 200,
//   "response": {
//     "document": {
//       "id": "1659580-economic-analysis-of-the-south-pole-traverse",
//       "title": "Economic Analysis of the South Pole Traverse",
//       "access": "public",
//       "pages": 38,
//       ...

search

Searches the DocumentCloud service for documents.

Parameters

update

Update a document's title, source, description, related article, access level, or data values. Values passed into opts will be updated on the requested document.

Parameters

upload

Uploads a document to DocumentCloud.

The file can be a path to a document on disk, a Node.js Buffer, or the URL to a public file.

Parameters

Major Thanks