-
Notifications
You must be signed in to change notification settings - Fork 58
/
submission.go
57 lines (51 loc) · 1.87 KB
/
submission.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
// Copyright 2012 Jimmy Zelinskie. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package geddit
import (
"fmt"
)
// Submission represents an individual post from the perspective
// of a subreddit. Remember to check for nil pointers before
// using any pointer fields.
type Submission struct {
Author string `json:"author"`
Title string `json:"title"`
URL string `json:"url"`
Domain string `json:"domain"`
Subreddit string `json:"subreddit"`
SubredditID string `json:"subreddit_id"`
FullID string `json:"name"`
ID string `json:"id"`
Permalink string `json:"permalink"`
Selftext string `json:"selftext"`
SelftextHTML string `json:"selftext_html"`
ThumbnailURL string `json:"thumbnail"`
DateCreated float64 `json:"created_utc"`
NumComments int `json:"num_comments"`
Score int `json:"score"`
Ups int `json:"ups"`
Downs int `json:"downs"`
IsNSFW bool `json:"over_18"`
IsSelf bool `json:"is_self"`
WasClicked bool `json:"clicked"`
IsSaved bool `json:"saved"`
BannedBy *string `json:"banned_by"`
LinkFlairText string `json:"link_flair_text"`
}
func (h Submission) voteID() string { return h.FullID }
func (h Submission) deleteID() string { return h.FullID }
func (h Submission) replyID() string { return h.FullID }
// FullPermalink returns the full URL of a submission.
func (h *Submission) FullPermalink() string {
return "https://reddit.com" + h.Permalink
}
// String returns the string representation of a submission.
func (h *Submission) String() string {
plural := ""
if h.NumComments != 1 {
plural = "s"
}
comments := fmt.Sprintf("%d comment%s", h.NumComments, plural)
return fmt.Sprintf("%d - %s (%s)", h.Score, h.Title, comments)
}