Commit from m3o/m3o action

This commit is contained in:
m3o-actions
2022-01-07 11:59:24 +00:00
parent 4029f043af
commit fc3cf88dd1
24 changed files with 1071 additions and 968 deletions

52
carbon/carbon.go Executable file
View File

@@ -0,0 +1,52 @@
package carbon
import (
"go.m3o.com/client"
)
type Carbon interface {
Offset(*OffsetRequest) (*OffsetResponse, error)
}
func NewCarbonService(token string) *CarbonService {
return &CarbonService{
client: client.NewClient(&client.Options{
Token: token,
}),
}
}
type CarbonService struct {
client *client.Client
}
// Purchase 1kg (0.001 tonnes) of carbon offsets in a single request
func (t *CarbonService) Offset(request *OffsetRequest) (*OffsetResponse, error) {
rsp := &OffsetResponse{}
return rsp, t.client.Call("carbon", "Offset", request, rsp)
}
type OffsetRequest struct {
}
type OffsetResponse struct {
// the metric used e.g KG or Tonnes
Metric string `json:"metric"`
// projects it was allocated to
Projects []Project `json:"projects"`
// number of tonnes
Tonnes float64 `json:"tonnes"`
// number of units purchased
Units int32 `json:"units"`
}
type Project struct {
// name of the project
Name string `json:"name"`
// percentage that went to this
Percentage float64 `json:"percentage"`
// amount in tonnes
Tonnes float64 `json:"tonnes"`
}