GithubHelp home page GithubHelp logo

aidanfogarty / go-digital-humani Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 18 KB

Go SDK for DigitalHumani's Reforestation as a Service API. A platform which easily integrates with your products to reforest the planet.

Home Page: https://www.digitalhumani.com/

License: MIT License

Makefile 3.31% Go 96.69%
climate-change go reforestation

go-digital-humani's Introduction

Go DigitalHumani ๐ŸŒฒ

Build Status GoDoc

Unoffical Go SDK for DigitalHumani's Reforestation as a Service API. A platform which easily integrates with your products to reforest the planet.

Prerequisites


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

Installation


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

Getting Started


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......... ๐ŸŒฒ๐ŸŒฒ๐ŸŒฒ
}

Plant a tree

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}

Retrieve Details of a Plant Tree Request

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)
}

Get number of trees planted by a user

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)
}

Get Enterprise Details

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)
}

Get number of trees planted by an Enterprise between two dates

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)
}

Get number of trees planted by an Enterprise for a given month

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)
}

Get list of all reforestation 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")

	projects, err := dh.GetAllProjects(context.TODO())
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(projects)
}

Get a single project details by ID

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

Contribution


Contributions are always welcome! Please read the contribution guide.

If this project has helped you, consider leaving a โญ!

go-digital-humani's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.