Unoffical Go SDK for DigitalHumani's Reforestation as a Service API. A platform which easily integrates with your products to reforest the planet.
A DigitalHumani Account is needed to retrieve your:
- Enterprise ID
- Api Key
For information on how to setup and get your DigitalHumani account details, see the API Docs
To install, simply run go get
in your project.
go get github.com/AidanFogarty/go-digital-humani
To update the SDK, use go get -u
to retrieve the latest version.
go get -u github.com/AidanFogarty/go-digital-humani
To get started with the DigitalHumani sdk, simply create a new instance.
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox") // Can be either 'sandbox' or 'production'
// Plant some trees......... 🌲🌲🌲
}
To plant a single tree, add the following to your main.go
:
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
plantTreeResp, err := dh.PlantTree(context.TODO(), "93322350", "MyUser", 1)
if err != nil {
log.Fatal(err)
}
fmt.Println(plantTreeResp)
}
Compile & Execute:
> go run main.go
&{3ea84180-bffe-11ec-9d64-0242ac120002 2022-04-19T16:29:54.171Z 1 abcdefg 93322350 MyUser}
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
plantTreeResp, err := dh.GetTree(context.TODO(), "<uuid-of-request>")
if err != nil {
log.Fatal(err)
}
fmt.Println(plantTreeResp)
}
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
plantTreeCount, err := dh.GetTreeCount(context.TODO(), "<user-id>")
if err != nil {
log.Fatal(err)
}
fmt.Println(plantTreeCount)
}
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
enterprise, err := dh.GetEnterprise(context.TODO())
if err != nil {
log.Fatal(err)
}
fmt.Println(enterprise)
}
Can use the the NewDateRange
function to generate the date range parameter.
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
enterpriseTreeCount, err := dh.GetEnterpriseTreeCount(context.TODO(), digitalhumani.NewDateRange("2022-01-01", "2022-12-31"))
if err != nil {
log.Fatal(err)
}
fmt.Println(enterpriseTreeCount)
}
Month must be in format YYYY-MM
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
enterpriseTreeCount, err := dh.GetEnterpriseMonthTreeCount(context.TODO(), "2022-04")
if err != nil {
log.Fatal(err)
}
fmt.Println(enterpriseTreeCount)
}
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
projects, err := dh.GetAllProjects(context.TODO())
if err != nil {
log.Fatal(err)
}
fmt.Println(projects)
}
package main
import (
"context"
"fmt"
"log"
"github.com/AidanFogarty/go-digital-humani/pkg/digitalhumani"
)
func main() {
dh := digitalhumani.New("<your-api-key>", "<your-enterprise-id>", "sandbox")
project, err := dh.GetProject(context.TODO(), "32146688")
if err != nil {
log.Fatal(err)
}
fmt.Println(project)
}
For other features and detailed description, see the docs
Contributions are always welcome! Please read the contribution guide.
If this project has helped you, consider leaving a ⭐!