whitehouse
v0.0.1
Published
Whitehouse API module
Downloads
4
Readme
White House API Module for Node.js
Overview
Currently this module only supports the we the people APIs. However we'll add support for other parts of the WH APIs over time. Pull requests welcome
Installation
Easy installation with NPM
npm install whitehouse
License
This project is licensed under the BSD license
Usage
Simply include the whitehouse
module and then create a new API object you can then call methods to make requests.
var wh = require('whitehouse'),
whApi = wh.createWhiteHouse()
whApi.getPetitions(function(output) {
var obj = JSON.parse(output)
console.log(obj)
})
Exact details of available filters are on the We The People documentation.
getPetitions(fn)
Get all petitions call fn
with the data.
getPetitions(filter, fn)
Get all petitions that match the filter
object, call fn
with the data.
getPetition(id, fn)
Get petition matching id
call fn
with the data.
getSignatures(id, fn)
Get signatures matching petition id
call fn
with the data.
getSignatures(id, filter, fn)
Get signatures matching petition id
and filter
call fn
with the data.
Examples
var wh = require('whitehouse'),
whApi = wh.createWhiteHouse()
whApi.getPetitions(function(output) {
var obj = JSON.parse(output)
console.log(obj)
})
whApi.getPetitions(function(output) {
var obj = JSON.parse(output)
console.log(obj)
})
Todo
- Add in actual tests
- Better JSON support
- Better streaming suport
- Improved documentation
- Improved error handling
- Support for node.js domains
Legacy
When creating API objects the setting of an API Key is still supported from an earlier version of the API.
whApi = wh.createWhiteHouse(apiKey)
You can also pass a second parameter to the contructor to set the mock
value. This was originally used to get mock requests for testing.
whApi = wh.createWhiteHouse(apiKey,true) //use mock requests