-
Notifications
You must be signed in to change notification settings - Fork 0
/
activity.go
92 lines (77 loc) · 2.06 KB
/
activity.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
package blogplus
import (
"bytes"
"encoding/gob"
"html/template"
)
// https://developers.google.com/+/api/latest/activities/list#response
type ActivityFeed struct {
ETag string `json:"etag"`
NextPageToken string `json:"nextPageToken"`
Items []Activity `json:"items"`
}
// https://developers.google.com/+/api/latest/activities#resource
type Activity struct {
ETag string `json:"etag"`
Title string `json:"title"`
Published string `json:"published"` // RFC3339 timestamp
Updated string `json:"updated"` // RFC3339 timestamp
Id string `json:"id"`
Url string `json:"url"`
Verb string `json:"verb"`
Object Object `json:"object"`
// used in blogplus
FormedAttachment string
Permalink string
}
func (a Activity) HTMLFormedAttachment() template.HTML {
return template.HTML(a.FormedAttachment)
}
type Object struct {
Content string `json:"content"`
Attachments []Attachment `json:"attachments"`
Replies Counter `json:"replies"`
PlusOners Counter `json:"plusoners"`
Resharers Counter `json:"resharers"`
// used in blogplus
Subject string
}
func (o Object) HTMLContent() template.HTML {
return template.HTML(o.Content)
}
type Attachment struct {
ObjectType string `json:"objectType"`
DisplayName string `json:"displayName"`
Id string `json:"id"`
Content string `json:"content"`
Url string `json:"url"`
Image Image `json:"image"`
}
func (a Attachment) HTMLDisplayName() template.HTML {
return template.HTML(a.DisplayName)
}
type Image struct {
Url string `json:"url"`
}
type Counter struct {
TotalItems int `json:"totalItems"`
}
func init() {
var post Activity
gob.Register(post)
}
func DecodeActivity(data []byte) (post Activity, err error) {
buf := bytes.NewBuffer(data)
d := gob.NewDecoder(buf)
err = d.Decode(&post)
return post, err
}
func EncodeActivity(post Activity) ([]byte, error) {
buf := bytes.NewBuffer(nil)
e := gob.NewEncoder(buf)
err := e.Encode(post)
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}