mirror of
https://github.com/Xevion/todoist-late-reset.git
synced 2025-12-09 14:08:57 -06:00
reorganize into /cmd & /internal
This commit is contained in:
45
internal/api/commands.go
Normal file
45
internal/api/commands.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (sc *SyncClient) RecentlyCompleted() (*ActivityLog, error) {
|
||||
baseURL := API_BASE_URL + "/activity/get"
|
||||
params := url.Values{}
|
||||
params.Add("event_type", "completed")
|
||||
|
||||
fullURL := baseURL + "?" + params.Encode()
|
||||
|
||||
req, err := http.NewRequest("GET", fullURL, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", "Bearer "+sc.ApiToken)
|
||||
|
||||
resp, err := sc.Http.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var activityLog *ActivityLog
|
||||
if err := json.Unmarshal(body, &activityLog); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return activityLog, nil
|
||||
}
|
||||
|
||||
func (sc *SyncClient) sync() {
|
||||
// Implementation for synchronize function
|
||||
}
|
||||
5
internal/api/constants.go
Normal file
5
internal/api/constants.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package api
|
||||
|
||||
var (
|
||||
API_BASE_URL = "https://api.todoist.com/sync/v9"
|
||||
)
|
||||
4
internal/api/go.mod
Normal file
4
internal/api/go.mod
Normal file
@@ -0,0 +1,4 @@
|
||||
module api
|
||||
|
||||
go 1.22.3
|
||||
|
||||
1
internal/api/sync.go
Normal file
1
internal/api/sync.go
Normal file
@@ -0,0 +1 @@
|
||||
package api
|
||||
42
internal/api/types.go
Normal file
42
internal/api/types.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SyncClient struct {
|
||||
Http *http.Client
|
||||
SyncToken string
|
||||
ApiToken string
|
||||
LastSync time.Time
|
||||
LastFullSync time.Time
|
||||
}
|
||||
|
||||
func NewSyncClient(apiToken string) *SyncClient {
|
||||
return &SyncClient{
|
||||
Http: &http.Client{},
|
||||
ApiToken: apiToken,
|
||||
SyncToken: "*",
|
||||
}
|
||||
}
|
||||
|
||||
type SyncResponse struct {
|
||||
}
|
||||
|
||||
type ActivityLog struct {
|
||||
Count int `json:"count"`
|
||||
Events []Event `json:"events"`
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
EventDate time.Time `json:"event_date"`
|
||||
EventType string `json:"event_type"`
|
||||
ExtraData map[string]any `json:"extra_data"`
|
||||
ExtraDataID int64 `json:"extra_data_id"`
|
||||
ID int64 `json:"id"`
|
||||
|
||||
InitiatorID *int64 `json:"initiator_id"`
|
||||
ObjectID string `json:"object_id"`
|
||||
ObjectType string `json:"object_type"`
|
||||
}
|
||||
Reference in New Issue
Block a user