dbgcensus
v1.0.1
Published
A simple way to use the Daybreak Games Census API service
Downloads
27
Maintainers
Readme
dbgcensus
A simple way to use the Daybreak Games Census API service
Table of Contents
- Installing
- Creating a new query
- Returning data from the query
- Setting global parameters
- Defining a condition
- Setting a language
- Show certain fields
- Hide certain fields
- Set a limit for number of rows to return
- Set the starting row
- Add a resolve
- Join to another service
- Tree results on a field
- Getting the url of the query
Installing
npm install dbgcensus --save
Creating a new query
var CensusQuery = require('dbgcensus').Query;
var query = new CensusQuery('character', 'ps2', 'example')
The dbgcensus.Query constructor accepts a service, optional serviceType, and optional serviceId. If a globalNamespace
is not set than that argument becomes required. The acceptable namespaces can be found on the census.daybreakgames.com website. If a serviceId is not provided it defaults to the globalKey
if one is set or 'example'.
Returning data from the query
query.get(function (error, data) {
if (error) {
// something went wrong!
}
//do something with data
});
The data
variable represents the data of the collection list. Normally when a query is made with the census API it is returned like:
{
character_list: [
{
'character_id': 1234,
//etc
}
]
}
However dbgcensus returns just the data so the above becomes:
[
{
'character_id': 1234,
//etc
}
]
Setting global parameters
var dbgcensus = require('dbgcensus');
dbgcensus.SetGlobalNamespace('ps2:v2');
dbgcensus.SetGlobalServiceKey('example');
Defining a condition
query.where('name.lower').equals('lampjaw');
The following operations and their equivalent syntax is below:
equals
: =notEquals
: =!isLessThan
: =<isLessThanOrEquals
: =[isGreaterThan
: =>isGreaterThanOrEquals
: =]startsWith
: =^contains
: =*
Setting a language
query.setLanguage('en');
No language is set by default so you will receive all localized strings if available.
Show certain fields
query.showFields(['character_id', 'name', 'faction_id']);
Hide certain fields
query.hideFields(['currency', 'times']);
Set a limit for number of rows to return
query.setLimit(10);
Set the starting row
query.setStart(100);
Add a resolve
query.addResolve('world');
or for multiple resolves
query.resolve(['world', 'outfit']);
Join to another service
var worldJoin = query.joinService('characters_world');
Join objects have the following methods:
isList(bool)
isOuterJoin(bool)
showFields(array)
: See the 'Show certain fields' section abovehideFields(array)
: See the 'Hide certain fields' section aboveonField(string)
toField(string)
injectAt(string)
where(string)
: See the 'Defining a condition' section abovejoinService(string)
: Returns another join object for sub joining
Tree results on a field
var query = new CensusQuery('vehicle', 'ps2');
var vehicleTree = query.treeField('type_id');
Tree objects have the following methods:
isList(bool)
groupPrefix(string)
startField(string)
treeField(string)
: Returns another tree object for sub grouping
Getting the url of the query
var url = query.toUrl();