Skip to content

A go framework for the DaybreakGames Census API

License

Notifications You must be signed in to change notification settings

Lampjaw/censusgo

Repository files navigation

censusgo

This package is unofficial and is NOT in any way supported by Daybreak Games.

All use of game data and other content must comply with Daybreak Games Intellectual Property policy and Daybreak Game Company's Terms of Service.


censusgo is a library that makes it much easier to use the Census API provided by Daybreak Games Company. It uses dot notation chaining to make it easy to define and maintain queries.

For example, the following code will return all character faction stats saved after lastLoginTime and retrieve them from the API in chunks of 500 at a time.

b := censusgo.NewQueryBuilder("example", "ps2")

q := b.NewQuery("characters_stat_by_faction")
q.SetLimit(500)
q.Where("character_id").Equals("5428010917249639985")
q.ShowFields(
    "character_id",
    "stat_name",
    "profile_id",
    "value_forever_vs",
    "value_forever_nc",
    "value_forever_tr")
q.Where("last_save_date").IsGreaterThanOrEquals(lastLoginTime)

results, err := q.GetResultsBatch()

For a working example check out the examples!

Table of Contents

Installing

To download the censusgo library use

go get github.com/Lampjaw/censusgo

Creating a new query

To start creating queries, first create a QueryBuilder. QueryBuilder is a factory for generating queries that share the same service id and namespace. Using QueryBuilder you can call NewQuery(<collection_name>) to begin building your query definition.

builder := censusgo.NewQueryBuilder("example", "ps2")
query := builder.NewQuery("character")

Returning data from the query

There are two methods of query resolution: GetResults() and GetResultsBatch(). Both methods return type []interface{} as a []byte but execute the query differently.

GetResults() will only return the number of results or less of the limit specified or a single result if no limit is set.

GetResultsBatch() will attempt to return every record in the collection until either an error is thrown or the number of records returns is less than the limit. If no limit is specified it defaults to 500 records per fetch attempt.

results, err := query.GetResults()

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.SetLanguageString("en")

OR

query.SetLanguage(censusgo.LangEnglish)

No language is set by default so you will receive all localized strings if available.

Show certain fields

query.ShowFields("character_id"[, "field2", "field3", ...])

Hide certain fields

query.HideFields("currency"[, "field2", "field3", ...])

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"[, "resolve2", "resolve3", ...])

Join to another service

worldJoin := query.JoinCollection("characters_world")

Join objects have the following methods:

  • IsList(bool)
  • IsOuterJoin(bool)
  • ShowFields(...string): See the 'Show certain fields' section above
  • HideFields(...string): See the 'Hide certain fields' section above
  • OnField(string)
  • ToField(string)
  • WithInjectAt(string)
  • Where(string): See the 'Defining a condition' section above
  • JoinCollection(string): Returns another join object for sub joining

Tree results on a field

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

url := query.GetURL()

About

A go framework for the DaybreakGames Census API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages