Esempio n. 1
0
func newQiitaClient() (*qiita.Client, error) {
	loadConfig()
	var client *qiita.Client
	if accessToken := viper.GetString("accessToken"); accessToken != "" {
		ts := oauth2.StaticTokenSource(
			&oauth2.Token{AccessToken: accessToken},
		)
		tc := oauth2.NewClient(oauth2.NoContext, ts)
		client = qiita.NewClient(tc)
	} else {
		client = qiita.NewClient(nil)
	}

	return client, nil
}
Esempio n. 2
0
func cmdSetup(c *cli.Context) {
	token := c.Args().First()

	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	client := qiita.NewClient(tc)
	user, err := client.AuthenticatedUser.Show()
	if err != nil {
		fmt.Println("Auth failed")
		os.Exit(1)
	}

	loadConfig()
	viper.Set("accessToken", token)
	viper.Set("id", user.Id)

	err = saveConfig()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println("Token saved")
}