-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapi.go
258 lines (227 loc) · 7.02 KB
/
api.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package gochatwork
import (
"encoding/json"
)
const BaseUrl = `https://api.chatwork.com/v1`
type Me struct {
AccountId int `json:"account_id"`
RoomId int `json:"room_id"`
Name string `json:"name"`
ChatworkId string `json:"chatwork_id"`
OrganizationId int `json:"organization_id"`
OrganizationName string `json:"organization_name"`
Department string `json:"department"`
Title string `json:"title"`
Url string `json:"url"`
Introduction string `json:"introduction"`
Mail string `json:"mail"`
TelOrganization string `json:"tel_organization"`
TelExtension string `json:"tel_extension"`
TelMobile string `json:"tel_mobile"`
Skype string `json:"skype"`
Facebook string `json:"facebook"`
Twitter string `json:"twitter"`
AvatarImageUrl string `json:"avatar_image_url"`
}
func (c *Client) Me() Me {
ret := c.Get("/me", map[string]string{})
var me Me
json.Unmarshal(ret, &me)
return me
}
type Status struct {
UnreadRoomNum int `json:"unread_room_num"`
MentionRoomNum int `json:"mention_room_num"`
MytaskRoomNum int `json:"mytask_room_num"`
UnreadNum int `json:"unread_num"`
MentionNum int `json:"mention_num"`
MyTaskNum int `json:"mytask_num"`
}
func (c *Client) MyStatus() Status {
ret := c.Get("/my/status", map[string]string{})
var status Status
json.Unmarshal(ret, &status)
return status
}
type MyTask struct {
Task
Room struct {
Roomid int `json:"room_id"`
Name string `json:"name"`
IconPath string `json:"icon_path"`
}
}
// params keys
// - assigned_by_account_id
// - status: [open, done]
func (c *Client) MyTasks(params map[string]string) []MyTask {
ret := c.Get("/my/tasks", params)
var tasks []MyTask
json.Unmarshal(ret, &tasks)
return tasks
}
type Contact struct {
AccountId int `json:"account_id"`
RoomId int `json:"room_id"`
Name string `json:"name"`
ChatworkId string `json:"chatwork_id"`
OrganizationId int `json:"organization_id"`
OrganizationName string `json:"organization_name"`
Department string `json:"department"`
AvatarImageUrl string `json:"avatar_image_url"`
}
func (c *Client) Contacts() []Contact {
ret := c.Get("/contacts", map[string]string{})
var contacts []Contact
json.Unmarshal(ret, &contacts)
return contacts
}
type Room struct {
RoomId int `json:"room_id"`
Name string `json:"name"`
Type string `json:"type"`
Role string `json:"role"`
Sticky bool `json:"sticky"`
UnreadNum int `json:"unread_num"`
MentionNum int `json:"mention_num"`
MytaskNum int `json:"mytask_num"`
MessageNum int `json:"message_num"`
FileNum int `json:"file_num"`
TaskNum int `json:"task_num"`
IconPath string `json:"icon_path"`
LastUpdateTime int64 `json:"last_update_time"`
}
func (c *Client) Rooms() []Room {
ret := c.Get("/rooms", map[string]string{})
var rooms []Room
json.Unmarshal(ret, &rooms)
return rooms
}
func (c *Client) Room(roomId string) Room {
ret := c.Get("/rooms/"+roomId, map[string]string{})
var room Room
json.Unmarshal(ret, &room)
return room
}
// params keys
// * name
// * members_admin_ids
// - description
// - icon_preset
// - members_member_ids
// - members_readonly_ids
func (c *Client) CreateRoom(params map[string]string) []byte {
return c.Post("/rooms", params)
}
// params keys
// - description
// - icon_preset
// - name
func (c *Client) UpdateRoom(roomId string, params map[string]string) []byte {
return c.Put("/rooms/"+roomId, params)
}
// params key
// * action_type: [leave, delete]
func (c *Client) DeleteRoom(roomId string, params map[string]string) []byte {
return c.Delete("/rooms/"+roomId, params)
}
type Member struct {
AccountId int `json:"account_id"`
Role string `json:"role"`
Name string `json:"name"`
ChatworkId string `json:"chatwork_id"`
Organization_Id int `json:"organization_id"`
Organization_Name string `json:"organization_name"`
Department string `json:"department"`
AvatarImageUrl string `json:"avatar_image_url"`
}
func (c *Client) RoomMembers(roomId string) []Member {
ret := c.Get("/rooms/"+roomId+"/members", map[string]string{})
var members []Member
json.Unmarshal(ret, &members)
return members
}
// params keys
// * members_admin_ids
// - members_member_ids
// - members_readonly_ids
func (c *Client) UpdateRoomMembers(roomId string, params map[string]string) []byte {
return c.Put("/rooms/"+roomId+"/members", params)
}
type Account struct {
AccountId int `json:"account_id"`
Name string `json:"name"`
AvatarImageUrl string `json:"avatar_image_url"`
}
type Message struct {
MessageId int `json:"message_id"`
Account Account `json:"account"`
Body string `json:"body"`
SendTime int64 `json:"send_time"`
UpdateTime int64 `json:"update_time"`
}
func (c *Client) RoomMessages(roomId string) []Message {
ret := c.Get("/rooms/"+roomId+"/messages", map[string]string{})
var messages []Message
json.Unmarshal(ret, &messages)
return messages
}
func (c *Client) PostRoomMessage(roomId string, body string) []byte {
return c.Post("/rooms/"+roomId+"/messages", map[string]string{"body": body})
}
func (c *Client) RoomMessage(roomId, messageId string) Message {
ret := c.Get("/rooms/"+roomId+"/messages/"+messageId, map[string]string{})
var message Message
json.Unmarshal(ret, &message)
return message
}
type Task struct {
TaskId int `json:"task_id"`
Account Account `json:"account"`
AssignedByAccount Account `json:"assigned_by_account"`
MessageId int `json:"message_id"`
Body string `json:"body"`
LimitTime int64 `json:"limit_time"`
Status string `json:"status"`
}
func (c *Client) RoomTasks(roomId string) []Task {
ret := c.Get("/rooms/"+roomId+"/tasks", map[string]string{})
var tasks []Task
json.Unmarshal(ret, &tasks)
return tasks
}
// params keys
// * body
// * to_ids
// - limit
func (c *Client) PostRoomTask(roomId string, params map[string]string) []byte {
return c.Post("/rooms/"+roomId+"/tasks", params)
}
func (c *Client) RoomTask(roomId, taskId string) Task {
ret := c.Get("/rooms/"+roomId+"/tasks/"+taskId, map[string]string{})
var task Task
json.Unmarshal(ret, &task)
return task
}
type File struct {
FileId int `json:"file_id"`
Account Account `json:"account"`
MessageId int `json:"message_id"`
Filename string `json:"filename"`
Filesize int `json:"filesize"`
UploadTime int64 `json:"upload_time"`
}
// params key
// - account_id
func (c *Client) RoomFiles(roomId string, params map[string]string) []File {
ret := c.Get("/rooms/"+roomId+"/files", params)
var files []File
json.Unmarshal(ret, &files)
return files
}
func (c *Client) RoomFile(roomId, fileId string) File {
ret := c.Get("/rooms/"+roomId+"/files/"+fileId, map[string]string{})
var file File
json.Unmarshal(ret, &file)
return file
}