zonnepanelendelen

package module
v0.0.0-...-98bd591 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 6 Imported by: 0

README

Zonnepanelendelen API Golang client

Go Report Card Documentation

This is a simple golang library for interfacing with the API of the investment project Zonnepanelendelen. Zonnepanelendelen allows you to invest in solar panels when you don't have any more room left on your roof or can't put any solar panels on your roof at all.

For simplicity sake, currently only several API endpoints are supported. If you miss specific features in the library, please open an issue!

Example usage

An example for using the API client is shown below, where the credentials are those you would login to https://mijnstroom.zonnepanelendelen.nl/ with:

package main

import (
  "fmt"

  zonnepanelendelen "github.com/skoef/go-zonnepanelendelen"
)

func main() {
  api := zonnepanelendelen.New("johndoe", "s3cr3t")
  projects, err := api.GetProjects()
  if err != nil {
    panic(err)
  }

  fmt.Printf("found %d projects in your Zonnepanelendelen account\n", len(projects))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API is a container for holding authentication state for API interfacing

func New

func New(username, password string) API

New returns a new API struct for given username and password

func (API) GetProject

func (a API) GetProject(projectID int) (Project, error)

func (API) GetProjects

func (a API) GetProjects() ([]Project, error)

GetProjects returns all projects that the authenticated account invested in

type AuthToken

type AuthToken struct {
	Name  string `json:"name"`
	Token string `json:"token"`
}

AuthToken is the data structure as returned by /obtain-auth-token

func (AuthToken) String

func (t AuthToken) String() string

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is the interface that should be implemented by API HTTP clients while this usually is just the default HTTP client, but it allows to override the HTTP client for additional control over API calls or testing purposes

var HTTPAPIClient HTTPClient

HTTPAPIClient is the HTTP client used for interfacing with the API

type Measurement

type Measurement struct {
	Production         float64 `json:"production_kWh"`
	Expected           float64 `json:"expected_production_kWh"`
	Cumulative         float64 `json:"cumulative_production_kWh"`
	ExpectedCumulative float64 `json:"expected_cumulative_production_kWh"`
	Timestamp          string  `json:"timestamp"`
}

Measurement holds measurements for a specific moment in time

type Metrics

type Metrics struct {
	Parts     int         `json:"solar_parts"`
	Interest  float64     `json:"solar_interest"`
	Value     int         `json:"net_value"`
	Today     TimeMetrics `json:"production_today"`
	LastMonth TimeMetrics `json:"production_last_month"`
	LastYear  TimeMetrics `json:"production_last_year"`
	All       TimeMetrics `json:"production_all"`
}

Metrics is a container for all sorts of project metrics

type Project

type Project struct {
	Name      string  `json:"name"`
	ID        int     `json:"id"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	IsHidden  bool    `json:"is_hidden"`
	Metrics   Metrics `json:"metrics"`
}

Project is a single zonnepanelendelen project

type TimeMetrics

type TimeMetrics struct {
	TotalPower    float64       `json:"total_power_kWh"`
	TotalExpected float64       `json:"total_power_expected_kWh"`
	TotalProfit   float64       `json:"total_profit"`
	ROI           float64       `json:"return_on_investment"`
	Measurements  []Measurement `json:"data"`
}

TimeMetrics combine certain metrics over a specific period in time

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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