Skip to content

iwata/go-esa

Repository files navigation

go-esa

Build Status Coverage Status GoDoc

go-esa is a client library for esa.io API v1.

Requirements

  • Go 1.7+

Installation

go get github.com/iwata/go-esa/esa

Sample code

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/iwata/go-esa/esa"
	"golang.org/x/oauth2"
)


func main() {
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: os.Getenv("ESA_TOKEN")},
	)

	ctx := context.Background()
	tc := oauth2.NewClient(ctx, ts)
	client := esa.NewClient(tc)

	// Fetch joining teams
	// ref. https://docs.esa.io/posts/102#4-1-0
	teamList, _, err := client.Teams.List(ctx)
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("--- Team List ---")
	fmt.Printf("%v\n", teamList)

	team := os.Getenv("ESA_TEAM")

	// Get URL for invitation
	// ref. https://docs.esa.io/posts/102#12-1-0
	url, _, err := client.Invitations.GetURL(ctx, team)
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("--- Invitation URL ---")
	fmt.Printf("%v\n", url)
	
	// Send invitations
	// ref. https://docs.esa.io/posts/102#13-1-0
	emails := []string{"hoge@example.com", "fuga@example.com"}
	resList, _, err := client.Invitations.SendToMember(ctx, team, &esa.InvitationMember{
		Member: &esa.InvitationEmails{Emails: emails},
	})
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("--- Invited List ---")
	fmt.Printf("%v\n", resList)

	// Send invitations
	// ref. https://docs.esa.io/posts/102#13-1-0
	emails := []string{"hoge@example.com", "fuga@example.com"}
	resList, _, err := client.Invitations.SendToMember(ctx, team, &esa.InvitationMember{
		Member: &esa.InvitationEmails{Emails: emails},
	})
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("--- Invited List ---")
	fmt.Printf("%v\n", resList)

	// Fetch pending invitations
	// ref. https://docs.esa.io/posts/102#13-2-0
	list, _, err := client.Invitations.PendingInvitations(ctx, team)
	if err != nil {
		log.Panic(err)
	}
	fmt.Println("--- Pending Invitations ---")
	fmt.Printf("%v\n", list)
}

Supported API

About

go-esa is a client library for esa API v1

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published