-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
33 lines (25 loc) · 823 Bytes
/
message.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type messagesWrapper struct {
Messages []Message
}
func GetMessages(roomId int64, year int, month int, day int) []Message {
req, err := NewCfRequest(fmt.Sprintf("/room/%d/transcript/%d/%d/%d.json", roomId, year, month, day))
CheckFatalError(err, "Could not create request")
resp, err := http.DefaultClient.Do(req)
CheckFatalError(err, "Could not execute campfire request")
body, err := ioutil.ReadAll(resp.Body)
CheckFatalError(err, "Could not read campfire response")
var messages messagesWrapper
err = json.Unmarshal(body, &messages)
CheckFatalError(err, "Could not parse campfire response")
for i, v := range messages.Messages {
messages.Messages[i].CreatedAt = ParseCfTime(v.Created_At).Unix()
}
return messages.Messages
}