go-timeseries-client

module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: MPL-2.0

README

Golang client for Open Data Hub time series API

This is a golang client library for the Open Data Hub time series API: Ninja API

An OpenAPI spec and swagger instance to browse the API is available here

Usage

go get github.com/noi-techpark/go-timeseries-client

Setup the client
	// a short string identifying your application
	referer := "myapp.com"

	// create a default client
	c := odhts.NewDefaultClient(referer)

	// if you want to use different Timeseries or Authentication endpoints, create a custom client instead
	c := odhts.NewCustomClient(
		"http://localhost:8080",
		"http://authserver.example.com/auth/realms/test/protocol/openid-connect/token",
		referer)

	// (optional) use oauth credentials for requests
	c.UseAuth("myclientid", "myclientsecret")
Prepare request
	// Check OpenAPI spec at https://mobility.api.opendatahub.com for all options
	req := odhts.DefaultRequest()
	req.Repr = odhts.FlatNode
	req.AddStationType("EChargingStation")
	req.AddDataType("number-available")
	req.Limit = 5

	// add some custom filters
	req.Where = where.And(
		where.Eq("sorigin", "Neogy"),
		where.Eq("sactive", "true"),
	)
Request stations only
	// We use a provided response Dto, but you can (and sometimes have to) pass your own JSON-mappable types
	var stations odhts.Response[[]odhts.StationDto[map[string]any]]
	if err := odhts.StationType(c, req, &stations); err != nil {
		panic(err)
	}
	fmt.Printf("Stations:\n %v\n\n", stations)
Get latest measurements
	var latest odhts.Response[[]odhts.LatestDto]
	if err := odhts.Latest(c, req, &latest); err != nil {
		panic(err)
	}
	fmt.Printf("Measurements:\n %v", latest)

Information

Support

For support, please contact help@opendatahub.com.

Contributing

If you'd like to contribute, please follow our Getting Started instructions.

License

The code in this project is licensed under Mozilla Public License Version 2.0

REUSE

This project is REUSE compliant, more information about the usage of REUSE in NOI Techpark repositories can be found here.

Since the CI for this project checks for REUSE compliance you might find it useful to use a pre-commit hook checking for REUSE compliance locally. The pre-commit-config file in the repository root is already configured to check for REUSE compliance with help of the pre-commit tool.

Install the tool by running:

pip install pre-commit

Then install the pre-commit hook via the config file by running:

pre-commit install

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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