censusgo

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2020 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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{} 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()

Documentation

Index

Constants

View Source
const VERSION = "1.0.0"

Variables

This section is empty.

Functions

This section is empty.

Types

type CensusClient

type CensusClient struct {
	// contains filtered or unexported fields
}

func NewCensusClient

func NewCensusClient(serviceID string, collectionNamespace string) *CensusClient

type CensusLanguage

type CensusLanguage int
const (
	LangEnglish CensusLanguage = iota
	LangGerman
	LangSpanish
	LangFrench
	LangItalian
	LangTurkish
)

type QueryBuilder

type QueryBuilder struct {
	CensusClient *CensusClient
}

func NewQueryBuilder

func NewQueryBuilder(serviceID string, collectionNamespace string) *QueryBuilder

func (*QueryBuilder) NewQuery

func (b *QueryBuilder) NewQuery(collection string) *query

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL