diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 967d571..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,17 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - branch = "v1" - digest = "1:2d483dd5582af8d6db0875cfb21c35469ab4f52e4a5ffaddd91f8e1d76f00f87" - name = "gopkg.in/jarcoal/httpmock.v1" - packages = ["."] - pruneopts = "UT" - revision = "ccdff90978eff65b4bda9df540e18a1448bdfce8" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = ["gopkg.in/jarcoal/httpmock.v1"] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index ec866df..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,34 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[[constraint]] - branch = "v1" - name = "gopkg.in/jarcoal/httpmock.v1" - -[prune] - go-tests = true - unused-packages = true diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6d9705f --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/wtfutil/todoist + +go 1.18 + +require github.com/jarcoal/httpmock v1.2.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1b7e484 --- /dev/null +++ b/go.sum @@ -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= diff --git a/projects.go b/projects.go index 8ce2ae5..68a3c0a 100644 --- a/projects.go +++ b/projects.go @@ -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"` @@ -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 @@ -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 @@ -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"` }{ diff --git a/projects_test.go b/projects_test.go index 3a31dff..b63007e 100644 --- a/projects_test.go +++ b/projects_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "github.com/jarcoal/httpmock" ) func TestProject(t *testing.T) { @@ -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) @@ -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) } diff --git a/task.go b/task.go index 8ccce0c..819cca3 100644 --- a/task.go +++ b/task.go @@ -10,7 +10,7 @@ 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"` @@ -18,7 +18,7 @@ type Task struct { 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"` } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/task_test.go b/task_test.go index 3115b8b..2d04807 100644 --- a/task_test.go +++ b/task_test.go @@ -5,7 +5,7 @@ import ( "net/http" "testing" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "github.com/jarcoal/httpmock" ) func TestQueryParam(t *testing.T) { @@ -24,7 +24,7 @@ func TestQueryParam(t *testing.T) { "param2": "param2", } if qp.String() != "?param1=param1¶m2=param2" { - t.Errorf("Expected '?param1=param1' != '%s'", qp) + t.Errorf("Expected '?param1=param1¶m2=param2' != '%s'", qp) } } @@ -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, @@ -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, @@ -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) } @@ -163,7 +163,7 @@ 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) @@ -171,4 +171,4 @@ func TestDecodeTask(t *testing.T) { if err != nil { t.Error(err) } -} \ No newline at end of file +} diff --git a/todoist.go b/todoist.go index 1b8d8fa..19d5284 100644 --- a/todoist.go +++ b/todoist.go @@ -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 @@ -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"` @@ -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 { diff --git a/todoist_test.go b/todoist_test.go index 116cf8c..e8b0449 100644 --- a/todoist_test.go +++ b/todoist_test.go @@ -6,7 +6,7 @@ import ( "net/http" "testing" "time" - httpmock "gopkg.in/jarcoal/httpmock.v1" + "github.com/jarcoal/httpmock" ) func TestMakeRequest(t *testing.T) { @@ -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))