-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
179 lines (158 loc) · 6.98 KB
/
client.go
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package main
import (
"github.com/parnurzeal/gorequest"
_ "google.golang.org/api/tasks/v1"
)
//GoogleTaskClient ...
type GoogleTaskClient struct {
request *gorequest.SuperAgent
baseURL string
token string
}
//NewGoogleTaskClient ...
func NewGoogleTaskClient(token string) *GoogleTaskClient {
googleTaskClient := new(GoogleTaskClient)
googleTaskClient.baseURL = "https://www.googleapis.com/tasks/v1"
googleTaskClient.token = token
googleTaskClient.request = gorequest.New()
return googleTaskClient
}
//GetAllLists: Returns all the authenticated user's task lists ...
func (googleTaskClient GoogleTaskClient) GetAllLists() (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists" //build endpoint url
//Build Request
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO: Add function that goes and fetches the access token
End() //Needed after each request
}
//Returns all the authenticated user's task lists ...
func (googleTaskClient GoogleTaskClient) GetAllListsWithQuery(query string) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists" //build endpoint url
//Build Request
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO: Add function that goes and fetches the access token
Query(query).
End() //Needed after each request
}
//Returns the authenticated user's specified task list ...
func (googleTaskClient GoogleTaskClient) GetTaskList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists/" + taskList.ID() //build endpoint url
//Build Request
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Creates a new task list and adds it to the authenticated user's task lists ...
func (googleTaskClient GoogleTaskClient) CreateTaskList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists"
return googleTaskClient.request.
Post(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Set("Accept", "application/json").
Send(taskList). //GoRequest marshals struct into json format using Send()
End()
}
//Updates the authenticated user's specified task list ...
func (googleTaskClient GoogleTaskClient) UpdateTaskList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists/" + taskList.ID()
return googleTaskClient.request.
Put(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Set("Accept", "application/json").
Send(taskList).
End()
}
//Deletes the authenticated user's specified task list ...
func (googleTaskClient GoogleTaskClient) DeleteTaskList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/users/@me/lists/" + taskList.ID()
return googleTaskClient.request.
Delete(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Returns all tasks in the specified task list.
func (googleTaskClient GoogleTaskClient) GetAllTasksInList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "tasks"
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Returns all tasks in the specified task list.
func (googleTaskClient GoogleTaskClient) GetAllTasksInListWithQuery(taskList TaskList, query string) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "tasks"
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Query(query).
End()
}
//Returns the specified task.
func (googleTaskClient GoogleTaskClient) GetTaskInList(taskList TaskList, task Task) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/tasks/" + task.ID()
return googleTaskClient.request.
Get(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Creates a new task on the specified task list.
func (googleTaskClient GoogleTaskClient) CreateTaskInList(taskList TaskList, task Task) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "tasks"
return googleTaskClient.request.
Post(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Set("Accept", "application/json").
Send(task).
End()
}
//Updates the specified task.
func (googleTaskClient GoogleTaskClient) UpdateTaskInList(taskList TaskList, task Task) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/tasks/" + task.ID()
return googleTaskClient.request.
Put(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Set("Accept", "application/json").
Send(task).
End()
}
//Deletes the specified task from the task list.
func (googleTaskClient GoogleTaskClient) DeleteTaskInList(taskList TaskList, task Task) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/tasks/" + task.ID()
return googleTaskClient.request.
Delete(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Clears all completed tasks from the specified task list.
//The affected tasks will be marked as 'hidden' and no longer be returned by default when retrieving all tasks for a task list.
func (googleTaskClient GoogleTaskClient) ClearAllTasksInTaskList(taskList TaskList) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/clear"
return googleTaskClient.request.
Post(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Moves the specified task to another position in the task list.
//This can include putting it as a child task under a new parent and/or move it to a different position among its sibling tasks.
func (googleTaskClient GoogleTaskClient) MoveTaskInTaskList(taskList TaskList, task Task) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/tasks/" + task.ID() + "move"
return googleTaskClient.request.
Post(endpoint).
Set("access-token", googleTaskClient.token). //TODO
End()
}
//Moves the specified task to another position in the task list.
//This can include putting it as a child task under a new parent and/or move it to a different position among its sibling tasks.
func (googleTaskClient GoogleTaskClient) MoveTaskInTaskListWithQuery(taskList TaskList, task Task, query string) (gorequest.Response, string, []error) {
endpoint := googleTaskClient.baseURL + "/lists/" + taskList.ID() + "/tasks/" + task.ID() + "move"
return googleTaskClient.request.
Post(endpoint).
Set("access-token", googleTaskClient.token). //TODO
Query(query).
End()
}
func doSom(){
}