opd-sdk
The javascript sdk for the Open Place Database API
Install
npm install opd-sdk --save
Requiring
var opdSDK = opdClient = opdSDK;
Again, but with options
var opdSDK = opdClient = opdSDK;
Notes
- All returned or thrown errors are standard javascript error objects created via
new Error('message here')
- This library uses the
debug
module (found here). To enable it, set theDEBUG
environment variable toopd-sdk
(DEBUG=opd-sdk
) - To view the schemas for places and geojsons, go here.
Methods
createClient(options)
// Overwrite ALL the options. Bwahahahaha.var opdSDK = opdClient = opdSDK;
-
host: The base url to use for the requests. Make sure to include the port if you are running locally. Default:
http://www.openplacedatabase.com/api/
-
username: The username to use for authentication. Only required for
deletePlace(s)
andsavePlace(s)
. Default:null
-
password: The password to use for authentication. Only required for
deletePlace(s)
andsavePlace(s)
. Default:null
validate
Validate OPD data via the opd-validate library. Read it's docs for more information.
var opdSDK = ; try opdSDKvalidate; opdSDKvalidate; catche // Validation failed
Client Methods
searchPlaces(query, [options], callback(error, data))
Find some historical places. Booyah. Note that options
is optional.
var options = count: 42 // Must be between 1 and 100, default 10 offset: 76 // Must be an integer > 0, default 0; opdClient;
get(id, callback(error, data))
Get a place or geojson.
opdClient;
getMulti(ids, callback(error, data))
Get several places or geojson.
var stuffIWant = "<place1>""<place2>""<geojsonId>"; opdClient;
save(id, place, callback(error))
Save a place or geojson
opdClient;
saveMulti(places, callback(error, data))
Save multiple places or geojsons at once
var dataToSave = '<place1>': placeOneObject '<place2>': placeTwoObject '<geojsonid1>': geojsonObject; opdClient;
delete(id, callback(error))
Delete a place
opdClient;
deleteMulti(places, callback(error))
Delete multiple places or geojsons
var places = '<place1>' '<place2>'; opdClient;
getChanges(from, to, callback(error, data))
Get changes for a given time range.
// Only get places that have changed since our last sync timevar from = ;// Yup, timestamp magic. Oh yeah.var to = Date; opdClient;