Exemplo n.º 1
0
func Config(c *cli.Context) {
	_, err := ioutil.ReadFile(utils.Home() + "/.asana.yml")
	if err != nil || config.Load().Personal_access_token == "" {
		println("visit: http://app.asana.com/-/account_api")
		println("  Settings > Apps > Personal Access Tokens")
		println("  + Create New Personal Access Token")
		print("\npaste your Personal Access Token: ")
		var s string
		fmt.Scanf("%s", &s)

		f, _ := os.Create(utils.Home() + "/.asana.yml")
		defer f.Close()
		f.WriteString("personal_access_token: " + s + "\n")
	}

	ws := api.Me().Workspaces
	index := 0

	if len(ws) > 1 {
		fmt.Println("\n" + strconv.Itoa(len(ws)) + " workspaces found.")
		for i, w := range ws {
			fmt.Printf("[%d] %16d %s\n", i, w.Id, w.Name)
		}
		index = utils.EndlessSelect(len(ws)-1, index)
	}
	token := config.Load().Personal_access_token
	f, _ := os.Create(utils.Home() + "/.asana.yml")
	f.WriteString("personal_access_token: " + token + "\n")
	f.WriteString("workspace: " + strconv.Itoa(ws[index].Id) + "\n")
}
Exemplo n.º 2
0
func Browse(c *cli.Context) {
	taskId := api.FindTaskId(c.Args().First(), true)
	url := "https://app.asana.com/0/" + strconv.Itoa(config.Load().Workspace) + "/" + taskId
	launcher, err := utils.BrowserLauncher()
	utils.Check(err)
	cmd := exec.Command(launcher, url)
	err = cmd.Start()
	utils.Check(err)
}
Exemplo n.º 3
0
func fire(req *http.Request) []byte {
	client := &http.Client{}

	req.Header.Set("User-Agent", UserAgent)
	req.Header.Set("Authorization", "Bearer "+config.Load().Personal_access_token)

	resp, err := client.Do(req)
	body, err := ioutil.ReadAll(resp.Body)

	utils.Check(err)

	if resp.StatusCode >= 300 {
		println(resp.Status)
	}

	return body
}
Exemplo n.º 4
0
func Tasks(params url.Values, withCompleted bool) []Task_t {
	params.Add("workspace", strconv.Itoa(config.Load().Workspace))
	params.Add("assignee", "me")
	params.Add("opt_fields", "name,completed,due_on")
	var tasks map[string][]Task_t
	err := json.Unmarshal(Get("/api/1.0/tasks", params), &tasks)
	utils.Check(err)
	var tasks_without_due, tasks_with_due []Task_t
	for _, t := range tasks["data"] {
		if !withCompleted && t.Completed {
			continue
		}
		if t.Due_on == "" {
			tasks_without_due = append(tasks_without_due, t)
		} else {
			tasks_with_due = append(tasks_with_due, t)
		}
	}
	sort.Sort(ByDue(tasks_with_due))
	return append(tasks_with_due, tasks_without_due...)
}