示例#1
0
func main() {
	exists, err := config.OpenConfig()
	if err != nil {
		fmt.Printf("Error: %s\n", err.Error())
		os.Exit(1)
	}
	if !exists {
		api.DoAuth()
		config.SaveConfig()
	}

	// Parse command-line arguments.
	if len(os.Args) <= 2 {
		cmdHelp()
	}

	switch os.Args[1] {
	case "list":
		switch os.Args[2] {
		case "all":
			err = cmdListAll()
		case "show":
			params := getParams(1)
			err = cmdListShow(params[0])
		case "create":
			params := getParams(1)
			err = cmdListCreate(params[0])
		case "remove":
			params := getParams(1)
			err = cmdListRemove(params[0])
		default:
			cmdHelp()
		}
	case "task":
		switch os.Args[2] {
		case "create":
			params := getParams(2)
			err = cmdTaskCreate(params[0], params[1])
		case "check":
			params := getParams(1)
			err = cmdTaskCheck(params[0])
		case "edit":
			params := getParams(1)
			err = cmdTaskEdit(params[0])
		default:
			cmdHelp()
		}
	default:
		cmdHelp()
	}

	if err != nil {
		fmt.Printf("Error: %s\n\n", err.Error())
		os.Exit(1)
	}

}
示例#2
0
func TestDoRequest(t *testing.T) {
	exists, err := config.OpenConfig()
	if err != nil {
		t.Fatal(err.Error())
	}
	if !exists {
		DoAuth()
		config.SaveConfig()
	}

	if (clientID == "") || (clientSecret == "") {
		t.Skip("Cannot run test because of empty Client ID/Secret.")
	}

	var response []List
	err = DoRequest("GET", "https://a.wunderlist.com/api/v1/lists", nil, &response)
	if err != nil {
		t.Fatalf("DoRequest error: %s", err.Error())
	}

	t.Logf("response length is %d\n", len(response))
}