Skip to content

Commit 1274e5a

Browse files
committed
Add journal
1 parent da069ca commit 1274e5a

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

habitify.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import (
1313
const DefaultEndpoint = "https://api.habitify.me"
1414

1515
const (
16-
urlHabits = "/habits"
17-
urlNotes = "/notes"
18-
urlStatus = "/status"
16+
urlHabits = "/habits"
17+
urlJournal = "/journal"
18+
urlNotes = "/notes"
19+
urlStatus = "/status"
1920
)
2021

2122
type apiResponse struct {

journal.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package habitify
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
)
8+
9+
type Journal struct {
10+
ID string `json:"id"`
11+
Name string `json:"name"`
12+
IsArchived bool `json:"is_archived"`
13+
StartDate time.Time `json:"start_date"`
14+
TimeOfDay []string `json:"time_of_day"`
15+
Goal struct {
16+
UnitType string `json:"unit_type"`
17+
Value int `json:"value"`
18+
Periodicity string `json:"periodicity"`
19+
} `json:"goal"`
20+
GoalHistoryItems []struct {
21+
UnitType string `json:"unit_type"`
22+
Value int `json:"value"`
23+
Periodicity string `json:"periodicity"`
24+
} `json:"goal_history_items"`
25+
LogMethod string `json:"log_method"`
26+
Recurrence string `json:"recurrence"`
27+
Remind []string `json:"remind"`
28+
Area struct {
29+
ID string `json:"id"`
30+
Name string `json:"name"`
31+
Priority string `json:"priority"`
32+
} `json:"area"`
33+
CreatedDate time.Time `json:"created_date"`
34+
Priority float64 `json:"priority"`
35+
Status string `json:"status"`
36+
Progress struct {
37+
CurrentValue int `json:"current_value"`
38+
TargetValue int `json:"target_value"`
39+
UnitType string `json:"unit_type"`
40+
Periodicity string `json:"periodicity"`
41+
ReferenceDate time.Time `json:"reference_date"`
42+
} `json:"progress"`
43+
}
44+
45+
func (c *Client) ListJournals(ctx context.Context, targetDate time.Time) ([]*Journal, error) {
46+
var journals []*Journal
47+
err := c.get(ctx, fmt.Sprintf("%s?target_date=%s", urlJournal, formatTime(targetDate)), &journals)
48+
if err != nil {
49+
return nil, err
50+
}
51+
52+
return journals, nil
53+
}

0 commit comments

Comments
 (0)