LoginSignup
1

More than 5 years have passed since last update.

esaに招待APIが実装されたのでGoでクライアントを書いてみた

Last updated at Posted at 2017-09-15

tl;dr

  • esa.ioに招待APIが追加された
  • 既存のGoクライアントが招待APIに対応してなかったので自分でクライアント書いた
    • 対応しているAPIはごく一部

はじめに

社内の情報共有にesa.ioを使っています。
そんなesaに先日招待APIが追加されました。
招待周りをchatops化するにあたりリクエストしていたAPIなので、早速対応していただいた中の人たちに感謝です!

esa APIのGoクライアントはいくつかあるのですが、新しいAPIには対応していないので自分で作ってみました。

使い方

README.md読んでもらえば使い方は大体わかると思います。

肝心の招待メールを送るケースのサンプルは以下のようになります。

main.go
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)

    // Send invitations
    // ref. https://docs.esa.io/posts/102#13-1-0
    emails := []string{"hoge@example.com", "fuga@example.com"}
    list, _, 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", list)
}

補足

  • contextパッケージに依存しているので、1.7以上じゃないと動かないです。
  • 招待やりたかったので、一部のAPIしか対応してません。
  • 実装はgo-githubをだいぶ参考にしました。

おしまい

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1