reorganize into /cmd & /internal

This commit is contained in:
2024-09-22 04:43:26 -05:00
parent 2d552860a1
commit 25529f6585
9 changed files with 119 additions and 90 deletions

45
internal/api/commands.go Normal file
View 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
}

View File

@@ -0,0 +1,5 @@
package api
var (
API_BASE_URL = "https://api.todoist.com/sync/v9"
)

4
internal/api/go.mod Normal file
View File

@@ -0,0 +1,4 @@
module api
go 1.22.3

1
internal/api/sync.go Normal file
View File

@@ -0,0 +1 @@
package api

42
internal/api/types.go Normal file
View 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"`
}