Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions Gopkg.lock

This file was deleted.

34 changes: 0 additions & 34 deletions Gopkg.toml

This file was deleted.

5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/wtfutil/todoist

go 1.18

require github.com/jarcoal/httpmock v1.2.0 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc=
github.com/jarcoal/httpmock v1.2.0/go.mod h1:oCoTsnAz4+UoOUIf5lJOWV2QQIW5UoeUI6aM2YnWAZk=
10 changes: 5 additions & 5 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Project is a model of todoist project entity
type Project struct {
ID uint `json:"id"`
ID string `json:"id"`
Name string `json:"name"`
CommentCount int `json:"comment_count"`
Order int `json:"order"`
Expand Down Expand Up @@ -62,8 +62,8 @@ func ListProject() ([]Project, error) {
// panic(err)
// }
// fmt.Println(project)
func GetProject(id uint) (Project, error) {
path := fmt.Sprintf("projects/%d", id)
func GetProject(id string) (Project, error) {
path := fmt.Sprintf("projects/%s", id)
res, err := makeRequest(http.MethodGet, path, nil)
if err != nil {
return Project{}, err
Expand Down Expand Up @@ -109,7 +109,7 @@ func CreateProject(name string) (Project, error) {
// panic(err)
// }
func (p Project) Delete() error {
path := fmt.Sprintf("projects/%d", p.ID)
path := fmt.Sprintf("projects/%s", p.ID)
_, err := makeRequest(http.MethodDelete, path, nil)
if err != nil {
return err
Expand All @@ -133,7 +133,7 @@ func (p Project) Delete() error {
// }
// fmt.Println(project)
func (p Project) Update() error {
path := fmt.Sprintf("projects/%d", p.ID)
path := fmt.Sprintf("projects/%s", p.ID)
project := struct {
Name string `json:"name"`
}{
Expand Down
6 changes: 3 additions & 3 deletions projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"testing"

httpmock "gopkg.in/jarcoal/httpmock.v1"
"github.com/jarcoal/httpmock"
)

func TestProject(t *testing.T) {
Expand All @@ -23,7 +23,7 @@ func TestProject(t *testing.T) {
return httpmock.NewStringResponse(400, ""), nil
}
project := Project{
ID: 1,
ID: "1",
Name: body.Name,
}
listProjects = append(listProjects, project)
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestProject(t *testing.T) {
t.Errorf("Expected len(projects) != '%d'", len(projects))
}

project, err = GetProject(1)
project, err = GetProject("1")
if err != nil {
t.Error(err)
}
Expand Down
16 changes: 8 additions & 8 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (

// Task is a model of todoist project entity
type Task struct {
ID uint `json:"id"`
ID string `json:"id"`
CommentCount int `json:"comment_count"`
Completed bool `json:"completed"`
Content string `json:"content"`
Indent int `json:"indent"`
LabelIDs []int `json:"label_ids"`
Order int `json:"order"`
Priority int `json:"priority"`
ProjectID int `json:"project_id"`
ProjectID string `json:"project_id"`
Due Due `json:"due"`
}

Expand Down Expand Up @@ -94,8 +94,8 @@ func ListTask(qp QueryParam) ([]Task, error) {
}

// GetTask return a task by id
func GetTask(id uint) (Task, error) {
path := fmt.Sprintf("tasks/%d", id)
func GetTask(id string) (Task, error) {
path := fmt.Sprintf("tasks/%s", id)
res, err := makeRequest(http.MethodGet, path, nil)
if err != nil {
return Task{}, err
Expand All @@ -116,7 +116,7 @@ func CreateTask(task Task) (Task, error) {

// Delete remove a task
func (t Task) Delete() error {
path := fmt.Sprintf("tasks/%d", t.ID)
path := fmt.Sprintf("tasks/%s", t.ID)
_, err := makeRequest(http.MethodDelete, path, nil)
if err != nil {
return err
Expand All @@ -127,7 +127,7 @@ func (t Task) Delete() error {

// Update a task
func (t Task) Update() error {
path := fmt.Sprintf("tasks/%d", t.ID)
path := fmt.Sprintf("tasks/%s", t.ID)
_, err := makeRequest(http.MethodPost, path, t.taskSave())
if err != nil {
return err
Expand All @@ -138,7 +138,7 @@ func (t Task) Update() error {

// Close mask task as done
func (t Task) Close() error {
path := fmt.Sprintf("tasks/%d/close", t.ID)
path := fmt.Sprintf("tasks/%s/close", t.ID)
_, err := makeRequest(http.MethodPost, path, nil)
if err != nil {
return err
Expand All @@ -149,7 +149,7 @@ func (t Task) Close() error {

// Reopen a task
func (t Task) Reopen() error {
path := fmt.Sprintf("tasks/%d/reopen", t.ID)
path := fmt.Sprintf("tasks/%s/reopen", t.ID)
_, err := makeRequest(http.MethodPost, path, nil)
if err != nil {
return err
Expand Down
14 changes: 7 additions & 7 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
"testing"

httpmock "gopkg.in/jarcoal/httpmock.v1"
"github.com/jarcoal/httpmock"
)

func TestQueryParam(t *testing.T) {
Expand All @@ -24,7 +24,7 @@ func TestQueryParam(t *testing.T) {
"param2": "param2",
}
if qp.String() != "?param1=param1&param2=param2" {
t.Errorf("Expected '?param1=param1' != '%s'", qp)
t.Errorf("Expected '?param1=param1&param2=param2' != '%s'", qp)
}
}

Expand All @@ -42,7 +42,7 @@ func TestTask(t *testing.T) {
return httpmock.NewStringResponse(400, ""), nil
}
task := Task{
ID: 1,
ID: "1",
Content: body.Content,
ProjectID: body.ProjectID,
Order: body.Order,
Expand Down Expand Up @@ -71,7 +71,7 @@ func TestTask(t *testing.T) {
return httpmock.NewStringResponse(400, ""), nil
}
task := Task{
ID: 1,
ID: "1",
Content: body.Content,
ProjectID: body.ProjectID,
Order: body.Order,
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestTask(t *testing.T) {
t.Error(err)
}

task, err = GetTask(1)
task, err = GetTask("1")
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -163,12 +163,12 @@ func TestTask(t *testing.T) {


func TestDecodeTask(t *testing.T) {
taskData := `{"id": 3408210133,"project_id": 2217869113,"order": 3,"content": "Therapy","completed": false,"label_ids": [],"priority": 1,"comment_count": 0,"created": "2019-09-21T06:06:08Z","due": {"recurring": true,"string": "every monday at 10pm","date": "2019-10-07","datetime": "2019-10-07T14:00:00Z","timezone": "Asia/Kuala_Lumpur"}}`
taskData := `{"id": "3408210133","project_id": "2217869113","order": 3,"content": "Therapy","completed": false,"label_ids": [],"priority": 1,"comment_count": 0,"created": "2019-09-21T06:06:08Z","due": {"recurring": true,"string": "every monday at 10pm","date": "2019-10-07","datetime": "2019-10-07T14:00:00Z","timezone": "Asia/Kuala_Lumpur"}}`
bytes := []byte(taskData)
var task Task
err := json.Unmarshal(bytes, &task)

if err != nil {
t.Error(err)
}
}
}
8 changes: 4 additions & 4 deletions todoist.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

// Token save the personal token from todoist
var Token string
var todoistURL = "https://api.todoist.com/rest/v1/"
var todoistURL = "https://api.todoist.com/rest/v2/"

func makeRequest(method, endpoint string, data interface{}) (*http.Response, error) {
url := todoistURL + endpoint
Expand Down Expand Up @@ -57,7 +57,7 @@ func makeRequest(method, endpoint string, data interface{}) (*http.Response, err

type taskSave struct {
Content string `json:"content"`
ProjectID int `json:"project_id,omitempty"`
ProjectID string `json:"project_id,omitempty"`
Order int `json:"order,omitempty"`
LabelIDs []int `json:"label_ids,omitempty"`
Priority int `json:"priority,omitempty"`
Expand All @@ -74,8 +74,8 @@ func (ts taskSave) MarshalJSON() ([]byte, error) {
}
buffer.WriteString(fmt.Sprintf("\"content\":\"%s\"", ts.Content))

if ts.ProjectID != 0 {
buffer.WriteString(fmt.Sprintf(",\"project_id\":%d", ts.ProjectID))
if ts.ProjectID != "" {
buffer.WriteString(fmt.Sprintf(",\"project_id\":%s", ts.ProjectID))
}

if ts.Order != 0 {
Expand Down
4 changes: 2 additions & 2 deletions todoist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"testing"
"time"
httpmock "gopkg.in/jarcoal/httpmock.v1"
"github.com/jarcoal/httpmock"
)

func TestMakeRequest(t *testing.T) {
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestTaskSaveMarshalJSON(t *testing.T) {
t.Errorf("Expected '{\"content\":\"test\"}' != '%s'", string(b))
}

ts = taskSave{Content: "test", ProjectID: 1}
ts = taskSave{Content: "test", ProjectID: "1"}
b, _ = ts.MarshalJSON()
if string(b) != "{\"content\":\"test\",\"project_id\":1}" {
t.Errorf("Expected '{\"content\":\"test\",\"project_id\":1}' != '%s'", string(b))
Expand Down