mirror of
https://github.com/kevin-DL/m3o-go.git
synced 2026-01-11 18:44:26 +00:00
Commit from m3o/m3o action
This commit is contained in:
52
carbon/carbon.go
Executable file
52
carbon/carbon.go
Executable 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"`
|
||||
}
|
||||
Reference in New Issue
Block a user