-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
162 lines (109 loc) Β· 3.51 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { ReclaimClient } from "../src";
import {
ReclaimHabitCreateMock,
ReclaimHabitUpdateMock,
ReclaimTaskCreateMock,
ReclaimTaskUpdateMock,
} from "../tests/mocks";
// Create a new ReclaimClient instance.
const client = new ReclaimClient();
const createTaskExample = async () => {
console.log("\n\nCreate a task =>\n");
const newTask = await client.tasks.create(ReclaimTaskCreateMock);
return newTask;
};
const searchTasksExample = async () => {
console.log("\n\nSearch tasks =>\n");
const tasks = await client.tasks.search({ title: "Funky Imitation Game" });
return tasks;
};
const updateTaskExample = async (taskId: number) => {
console.log("\n\nUpdate a task =>\n");
const updatedTask = await client.tasks.update(taskId, ReclaimTaskUpdateMock);
return updatedTask;
};
const getTaskExample = async (taskId: number) => {
console.log("\n\nGet a task =>\n");
const task = await client.tasks.get(taskId);
return task;
};
const deleteTaskExample = async (taskId: number) => {
console.log("\n\nDelete a task =>\n");
const deletedTask = await client.tasks.delete(taskId);
return deletedTask;
};
const getCurrentUserExample = async () => {
console.log("\n\nGet current user =>\n");
const user = await client.users.current();
return user;
};
const updateCurrentUserExample = async () => {
console.log("\n\nUpdate current user =>\n");
const updatedUser = await client.users.update({ companyName: "Assembless" });
return updatedUser;
};
const markTaskAsDoneExample = async (taskId: number) => {
console.log("\n\nMark task as done =>\n");
const doneTask = await client.tasks.markDone(taskId);
return doneTask;
};
const createHabitExample = async () => {
console.log("\n\nCreate a habit =>\n");
const newHabit = await client.habits.create(ReclaimHabitCreateMock);
return newHabit;
};
const updateHabitExample = async (habitId: number) => {
console.log("\n\nUpdate a habit =>\n");
const updatedHabit = await client.habits.update(
habitId,
ReclaimHabitUpdateMock
);
return updatedHabit;
};
const searchHabitsExample = async () => {
console.log("\n\nSearch habits =>\n");
const habits = await client.habits.search({
title: ReclaimHabitCreateMock.title,
});
return habits;
};
const getHabitExample = async (habitId: number) => {
console.log("\n\nGet a habit =>\n");
const habit = await client.habits.get(habitId);
return habit;
};
const deleteHabitExample = async (habitId: number) => {
console.log("\n\nDelete a habit =>\n");
const deletedHabit = await client.habits.delete(habitId);
return deletedHabit;
};
const getAnalyticsExample = async () => {
console.log("\n\nGet analytics =>\n");
const analytics = await client.analytics.get({
start: "2023-11-01",
end: "2023-11-30",
metricName: ["DURATION_BY_CATEGORY"],
});
return analytics;
};
// This is an example of how to use the ReclaimClient class.
const main = async () => {
console.clear();
await getCurrentUserExample();
await updateCurrentUserExample();
await getAnalyticsExample();
const createdTask = await createTaskExample();
const taskId = createdTask.id;
await searchTasksExample();
await updateTaskExample(taskId);
await getTaskExample(taskId);
await markTaskAsDoneExample(taskId);
await deleteTaskExample(taskId);
const createdHabit = await createHabitExample();
const habitId = createdHabit.id;
await searchHabitsExample();
await updateHabitExample(habitId);
await getHabitExample(habitId);
await deleteHabitExample(habitId);
};
main();