nobil

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 12 Imported by: 0

README

NOBIL Go

PkgGoDev GoReportCard Codecov

Go client to the NOBIL.no public charger API.

Usage

Get an API key

Visit info.nobil.no/api to ask for an API key for your project.

go get
$ go get -u go.einride.tech/nobil

Examples

Search charging stations in a rectangle
$ NOBIL_API_KEY=YOUR_API_KEY go run go.einride.tech/cmd/examples/searchrectangle
package main

import (
	"context"
	"fmt"
	"os"

	"go.einride.tech/nobil"
)

func main() {
	ctx := context.Background()
	client := nobil.NewClient(os.Getenv("NOBIL_API_KEY"))
	response, err := client.SearchRectangle(ctx, &nobil.SearchRectangleRequest{
		NorthEast: nobil.LatLng{
			Latitude:  59.94392,
			Longitude: 10.82668,
		},
		SouthWest: nobil.LatLng{
			Latitude:  59.88368,
			Longitude: 10.65090,
		},
		ExistingIDs: []string{"189", "195", "199", "89", "48"},
	})
	if err != nil {
		panic(err)
	}
	for _, chargingStation := range response.ChargingStations {
		fmt.Printf("%+v\n", chargingStation)
	}
}
Search nearby charging stations
$ NOBIL_API_KEY=YOUR_API_KEY go run go.einride.tech/cmd/examples/searchnear
import (
	"context"
	"fmt"
	"os"

	"go.einride.tech/nobil"
)

func main() {
	ctx := context.Background()
	client := nobil.NewClient(os.Getenv("NOBIL_API_KEY"))
	response, err := client.SearchNear(ctx, &nobil.SearchNearRequest{
		Coordinate: nobil.LatLng{
			Latitude:  59.91673,
			Longitude: 10.74782,
		},
		DistanceMetres: 2_000,
		Limit:          10,
	})
	if err != nil {
		panic(err)
	}
	for _, result := range response.Results {
		fmt.Printf("%dm: %+v\n", result.DistanceMetres, result.ChargingStation)
	}
}

Documentation

Overview

Package nobil provides a Go interface to the NOBIL charging station HTTP API.

Based on NOBIL API v3.0 rev. 08.08.2018.

https://info.nobil.no/images/downloads/API-NOBIL-Documentation_v3_20180808.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Accessibility

type Accessibility int
const (
	Accessibility_Open          Accessibility = 1
	Accessibility_StandardKey   Accessibility = 2
	Accessibility_Other         Accessibility = 3
	Accessibility_Rfid          Accessibility = 4
	Accessibility_Payment       Accessibility = 5
	Accessibility_CellularPhone Accessibility = 6
)

func (Accessibility) String

func (a Accessibility) String() string

type Attribute

type Attribute struct {
	ID          AttributeID `json:"attrtypeid"`
	Name        string      `json:"attrname"`
	ValueID     string      `json:"attrvalid"`
	Translation string      `json:"trans"`
	Value       interface{} `json:"attrval"`
}

type AttributeID

type AttributeID string
const (
	AttributeID_Location              AttributeID = "3"
	AttributeID_Availability          AttributeID = "2"
	AttributeID_Open24h               AttributeID = "24"
	AttributeID_ParkingFee            AttributeID = "7"
	AttributeID_TimeLimit             AttributeID = "6"
	AttributeID_RealTimeInformation   AttributeID = "21"
	AttributeID_PublicFunding         AttributeID = "22"
	AttributeID_VehicleType           AttributeID = "17"
	AttributeID_Accessibility         AttributeID = "1"
	AttributeID_ChargingCapacity      AttributeID = "5"
	AttributeID_Connector             AttributeID = "4"
	AttributeID_FixedCable            AttributeID = "25"
	AttributeID_ChargeMode            AttributeID = "20"
	AttributeID_PaymentMethod         AttributeID = "19"
	AttributeID_Reservable            AttributeID = "18"
	AttributeID_Manufacturer          AttributeID = "23"
	AttributeID_Timestamp             AttributeID = "16"
	AttributeID_PowerConsumption      AttributeID = "11"
	AttributeID_ConnectorSensorStatus AttributeID = "10"
	AttributeID_ConnectorErrorStatus  AttributeID = "9"
	AttributeID_ConnectorStatus       AttributeID = "8"
	AttributeID_Voltage               AttributeID = "12"
	AttributeID_MeterValue            AttributeID = "13"
	AttributeID_LastUsage             AttributeID = "15"
	AttributeID_AuxTypeId             AttributeID = "14"
	AttributeID_EnergyCarrier         AttributeID = "26"
	AttributeID_Evseid                AttributeID = "27"
	AttributeID_ChargerId             AttributeID = "28"
)

type Availability

type Availability int
const (
	Availability_Public        Availability = 1
	Availability_Visitors      Availability = 2
	Availability_Employees     Availability = 3
	Availability_ByAppointment Availability = 4
	Availability_Residents     Availability = 5
)

func (Availability) String

func (a Availability) String() string

type ChargeMode

type ChargeMode int
const (
	ChargeMode_Mode1 ChargeMode = 1
	ChargeMode_Mode2 ChargeMode = 2
	ChargeMode_Mode3 ChargeMode = 3
	ChargeMode_Mode4 ChargeMode = 4
)

func (ChargeMode) String

func (a ChargeMode) String() string

type ChargingCapacity

type ChargingCapacity int
const (
	ChargingCapacity_Unspecified                                          ChargingCapacity = 0
	ChargingCapacity_BatteryExchange                                      ChargingCapacity = 1
	ChargingCapacity_3point6KW230v1PhaseMax16a                            ChargingCapacity = 7
	ChargingCapacity_7point4KW230v1PhaseMax32a                            ChargingCapacity = 8
	ChargingCapacity_11KW400v3PhaseMax16a                                 ChargingCapacity = 10
	ChargingCapacity_22KW400v3PhaseMax32a                                 ChargingCapacity = 11
	ChargingCapacity_43KW400v3PhaseMax63a                                 ChargingCapacity = 12
	ChargingCapacity_50KW500vdcMax100a                                    ChargingCapacity = 13
	ChargingCapacity_100KW500vdcMax200a                                   ChargingCapacity = 23
	ChargingCapacity_230v3PhaseMax16a                                     ChargingCapacity = 16
	ChargingCapacity_230v3PhaseMax32a                                     ChargingCapacity = 17
	ChargingCapacity_230v3PhaseMax63a                                     ChargingCapacity = 18
	ChargingCapacity_20KW500vdcMax50a                                     ChargingCapacity = 19
	ChargingCapacity_LessThen100KWAnd43KW500vdcMax200aAnd400v3PhaseMax63a ChargingCapacity = 20
	ChargingCapacity_LessThen100KWAnd22KW500vdcMax50aAnd400v3PhaseMax32a  ChargingCapacity = 21
	ChargingCapacity_135KW480vdcMax270a                                   ChargingCapacity = 22
	ChargingCapacity_150KWDc                                              ChargingCapacity = 24
	ChargingCapacity_350KWDc                                              ChargingCapacity = 25
	ChargingCapacity_350Bar                                               ChargingCapacity = 26
	ChargingCapacity_700Bar                                               ChargingCapacity = 27
	ChargingCapacity_50KW400vdcMax125a                                    ChargingCapacity = 28
)

func (ChargingCapacity) String

func (a ChargingCapacity) String() string

type ChargingStation

type ChargingStation struct {
	ID                          int
	Name                        string
	Street                      string
	HouseNumber                 string
	ZipCode                     string
	City                        string
	MunicipalityID              string
	Municipality                string
	CountyID                    string
	County                      string
	Description                 string
	Owner                       string
	ChargingPointCount          int
	AvailableChargingPointCount int
	Position                    LatLng
	Image                       string
	UserComment                 string
	ContactInfo                 string
	CreateTime                  time.Time
	UpdateTime                  time.Time
	StationStatus               int
	LandCode                    string
	InternationalID             string
	Location                    Location
	Availability                Availability
	Open24h                     Open24h
	ParkingFee                  ParkingFee
	TimeLimit                   TimeLimit
	RealTimeInformation         RealTimeInformation
	PublicFunding               PublicFunding
	Connections                 []*Connection
	Attributes                  map[AttributeID]*Attribute
}

ChargingStation represents a charging station.

func (*ChargingStation) CSVHeader

func (c *ChargingStation) CSVHeader() []string

func (*ChargingStation) CSVRecord

func (c *ChargingStation) CSVRecord() []string

type Client

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

func NewClient

func NewClient(apiKey string) *Client

func (*Client) Dump

func (c *Client) Dump(ctx context.Context, request *DumpRequest) (_ io.ReadCloser, err error)

Dump all chargers in the database.

func (*Client) SearchNear

func (c *Client) SearchNear(
	ctx context.Context,
	request *SearchNearRequest,
) (_ *SearchNearResponse, err error)

SearchNear searches for chargers located within the radius of a coordinate.

func (*Client) SearchRectangle

func (c *Client) SearchRectangle(
	ctx context.Context,
	request *SearchRectangleRequest,
) (_ *SearchRectangleResponse, err error)

SearchRectangle searches for chargers located within a rectangle.

func (*Client) SetDumpURL

func (c *Client) SetDumpURL(dumpURL string)

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient *http.Client)

func (*Client) SetSearchURL

func (c *Client) SetSearchURL(searchURL string)

type Connection

type Connection struct {
	ID                    string
	VehicleType           VehicleType
	Accessibility         Accessibility
	ChargingCapacity      ChargingCapacity
	Connector             Connector
	FixedCable            FixedCable
	ChargeMode            ChargeMode
	PaymentMethod         PaymentMethod
	Reservable            Reservable
	ConnectorSensorStatus ConnectorSensorStatus
	ConnectorErrorStatus  ConnectorErrorStatus
	ConnectorStatus       ConnectorStatus
	EnergyCarrier         EnergyCarrier
	EVSEID                string
	Manufacturer          string
	Attributes            map[AttributeID]*Attribute
}

Connection represents a single connection at a charging station.

func (*Connection) CSVHeader

func (c *Connection) CSVHeader() []string

func (*Connection) CSVRecord

func (c *Connection) CSVRecord() []string

type Connector

type Connector int
const (
	Connector_Schuko                      Connector = 14
	Connector_TeslaConnectorRoadster      Connector = 29
	Connector_ChadeMo                     Connector = 30
	Connector_Type1                       Connector = 31
	Connector_Type2                       Connector = 32
	Connector_Type1Type2                  Connector = 60
	Connector_BlueIndustrial3Pin          Connector = 34
	Connector_BlueIndustrial4Pin          Connector = 35
	Connector_RedIndustrial5Pin           Connector = 36
	Connector_CcsCombo                    Connector = 39
	Connector_TeslaConnectorModel         Connector = 40
	Connector_ComboAndChadeMo             Connector = 41
	Connector_ChadeMoAndType2             Connector = 42
	Connector_ChadeMoAndComboAndAcType2   Connector = 43
	Connector_Type2AndSchuko              Connector = 50
	Connector_Type2AndDanishSection1072D1 Connector = 51
	Connector_Hydrogen                    Connector = 70
)

func (Connector) String

func (a Connector) String() string

type ConnectorErrorStatus

type ConnectorErrorStatus int
const (
	ConnectorErrorStatus_InService         ConnectorErrorStatus = 0
	ConnectorErrorStatus_ErrorOutOfService ConnectorErrorStatus = 1
)

func (ConnectorErrorStatus) String

func (a ConnectorErrorStatus) String() string

type ConnectorSensorStatus

type ConnectorSensorStatus int
const (
	ConnectorSensorStatus_Vacant       ConnectorSensorStatus = 0
	ConnectorSensorStatus_BusyCharging ConnectorSensorStatus = 1
)

func (ConnectorSensorStatus) String

func (a ConnectorSensorStatus) String() string

type ConnectorStatus

type ConnectorStatus int
const (
	ConnectorStatus_Vacant       ConnectorStatus = 0
	ConnectorStatus_BusyCharging ConnectorStatus = 1
	ConnectorStatus_Reserved     ConnectorStatus = 2
)

func (ConnectorStatus) String

func (a ConnectorStatus) String() string

type Date

type Date struct {
	Year  int        // Year (e.g., 2014).
	Month time.Month // Month of the year (January = 1, ...).
	Day   int        // Day of the month, starting at 1.
}

A Date represents a date (year, month, day).

This type does not include location information, and therefore does not describe a unique 24-hour timespan.

func (*Date) MarshalJSON

func (d *Date) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface. The output is the result of d.String().

func (Date) String

func (d Date) String() string

String returns the date in RFC3339 full-date format.

func (*Date) UnmarshalString

func (d *Date) UnmarshalString(s string) error

UnmarshalString sets the Date by decoding s.

type DumpRequest

type DumpRequest struct {
	// CountryCode to filter on (all countries if not specified).
	CountryCode string
	// FromDate to include in dump.
	FromDate Date
	// Format of the dump (XML if not specified).
	Format Format
	// NoRealTimeChargers filters out real-time chargers from the result set.
	NoRealTimeChargers bool
	// NoRealTimeData filters out chargers that have been updated by realtime data.
	NoRealTimeUpdates bool
}

DumpRequest is the input to the Dump method.

type EnergyCarrier

type EnergyCarrier int
const (
	EnergyCarrier_Electricity EnergyCarrier = 1
	EnergyCarrier_Hydrogen    EnergyCarrier = 2
)

func (EnergyCarrier) String

func (a EnergyCarrier) String() string

type FixedCable

type FixedCable int
const (
	FixedCable_Yes FixedCable = 1
	FixedCable_No  FixedCable = 2
)

func (FixedCable) String

func (a FixedCable) String() string

type Format

type Format string
const (
	FormatJSON Format = "json"
	FormatXML  Format = "xml"
)

type JSONScanner

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

func NewJSONScanner

func NewJSONScanner(r io.Reader) *JSONScanner

func (*JSONScanner) ChargingStation

func (s *JSONScanner) ChargingStation() *ChargingStation

func (*JSONScanner) Err

func (s *JSONScanner) Err() error

func (*JSONScanner) Scan

func (s *JSONScanner) Scan() bool

type LatLng

type LatLng struct {
	Latitude  float64
	Longitude float64
}

func (LatLng) MarshalJSON

func (l LatLng) MarshalJSON() ([]byte, error)

func (LatLng) String

func (l LatLng) String() string

func (*LatLng) UnmarshalJSON

func (l *LatLng) UnmarshalJSON(b []byte) error

func (*LatLng) UnmarshalString

func (l *LatLng) UnmarshalString(s string) (err error)

type Location

type Location int
const (
	Location_Street               Location = 1
	Location_CarPark              Location = 2
	Location_Airport              Location = 3
	Location_ShoppingCenter       Location = 4
	Location_TransportHub         Location = 5
	Location_HotelsAndRestaurants Location = 6
	Location_EnergyStation        Location = 7
)

func (Location) String

func (a Location) String() string

type Open24h

type Open24h int
const (
	Open24h_Yes Open24h = 1
	Open24h_No  Open24h = 2
)

func (Open24h) String

func (a Open24h) String() string

type ParkingFee

type ParkingFee int
const (
	ParkingFee_Yes ParkingFee = 1
	ParkingFee_No  ParkingFee = 2
)

func (ParkingFee) String

func (a ParkingFee) String() string

type PaymentMethod

type PaymentMethod int
const (
	PaymentMethod_CellularPhone              PaymentMethod = 1
	PaymentMethod_VisaMastercard             PaymentMethod = 2
	PaymentMethod_MastercardVisa             PaymentMethod = 3
	PaymentMethod_AmericanExpress            PaymentMethod = 4
	PaymentMethod_Diners                     PaymentMethod = 5
	PaymentMethod_OtherCards                 PaymentMethod = 6
	PaymentMethod_Subscription               PaymentMethod = 7
	PaymentMethod_CoinMachine                PaymentMethod = 8
	PaymentMethod_MiscellaneousCards         PaymentMethod = 9
	PaymentMethod_Miscellaneous              PaymentMethod = 10
	PaymentMethod_CellularPhoneChargingCard  PaymentMethod = 20
	PaymentMethod_VisaMastercardChargingCard PaymentMethod = 21
)

func (PaymentMethod) String

func (a PaymentMethod) String() string

type PublicFunding

type PublicFunding int
const (
	PublicFunding_OsloKommune PublicFunding = 1
	PublicFunding_Transnova   PublicFunding = 2
	PublicFunding_Other       PublicFunding = 3
	PublicFunding_None        PublicFunding = 4
	PublicFunding_ClimateStep PublicFunding = 5
)

func (PublicFunding) String

func (a PublicFunding) String() string

type RealTimeInformation

type RealTimeInformation int
const (
	RealTimeInformation_Yes RealTimeInformation = 1
	RealTimeInformation_No  RealTimeInformation = 2
)

func (RealTimeInformation) String

func (a RealTimeInformation) String() string

type Reservable

type Reservable int
const (
	Reservable_Yes Reservable = 1
	Reservable_No  Reservable = 2
)

func (Reservable) String

func (a Reservable) String() string

type SearchNearRequest

type SearchNearRequest struct {
	// Coordinate to search around.
	Coordinate LatLng
	// DistanceMetres of radius to search within.
	DistanceMetres int
	// Limit number of results to return.
	Limit int
}

SearchNearRequest is the input to the SearchNear method.

type SearchNearResponse

type SearchNearResponse struct {
	// Results from the search.
	Results []*SearchNearResult
	// Raw JSON search response.
	Raw json.RawMessage
}

SearchNearResponse is the output from the SearchNear method.

type SearchNearResult

type SearchNearResult struct {
	// ChargingStation in the current search result.
	ChargingStation *ChargingStation
	// DistanceMetres from the searched coordinate.
	DistanceMetres int
}

SearchNearResult is a search result from the SearchNear method.

type SearchRectangleRequest

type SearchRectangleRequest struct {
	// SouthWest coordinate of the rectangle.
	SouthWest LatLng
	// NothEast coordinate of the rectangle.
	NorthEast LatLng
	// ExistingIDs of chargers to not include in the search results.
	ExistingIDs []string
}

SearchRectangleRequest is the input to the SearchRectangle method.

type SearchRectangleResponse

type SearchRectangleResponse struct {
	// ChargingStations returned from the search.
	ChargingStations []*ChargingStation
	// Raw JSON search response.
	Raw json.RawMessage
}

SearchRectangleResponse is the output from the SearchRectangle method.

type TimeLimit

type TimeLimit int
const (
	TimeLimit_Yes TimeLimit = 1
	TimeLimit_No  TimeLimit = 2
)

func (TimeLimit) String

func (a TimeLimit) String() string

type VehicleType

type VehicleType int
const (
	VehicleType_AllVehicles               VehicleType = 1
	VehicleType_ShortVehicles             VehicleType = 2
	VehicleType_TwoWheelMopedsMotorcycles VehicleType = 3
	VehicleType_ElectricBikes             VehicleType = 4
	VehicleType_PluginHybrids             VehicleType = 5
	VehicleType_Van                       VehicleType = 6
	VehicleType_AllVehicleHydrogen        VehicleType = 7
	VehicleType_HydrogenCar               VehicleType = 8
	VehicleType_HydrogenTruck             VehicleType = 9
)

func (VehicleType) String

func (a VehicleType) String() string

Directories

Path Synopsis
cmd
attributegen Module

Jump to

Keyboard shortcuts

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