Add tests, edit error messages

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian 2020-08-03 00:00:29 -04:00
parent c3b2ab00c2
commit 8259f16f19
11 changed files with 726 additions and 22 deletions

View File

@ -68,7 +68,7 @@ func (s *CommentService) Edit(ctx context.Context, id string, text string) (*Com
// LoadMoreReplies retrieves more replies that were left out when initially fetching the comment.
func (s *CommentService) LoadMoreReplies(ctx context.Context, comment *Comment) (*Response, error) {
if comment == nil {
return nil, errors.New("comment: must not be nil")
return nil, errors.New("comment: cannot be nil")
}
if !comment.hasMore() {

View File

@ -2,7 +2,6 @@ package reddit
import (
"context"
"errors"
"fmt"
"net/http"
"strings"
@ -16,17 +15,9 @@ type ListingsService struct {
client *Client
}
// Get returns posts, comments, and subreddits from their IDs.
// Get returns posts, comments, and subreddits from their full IDs.
func (s *ListingsService) Get(ctx context.Context, ids ...string) ([]*Post, []*Comment, []*Subreddit, *Response, error) {
type query struct {
IDs []string `url:"id,comma"`
}
path := "api/info"
path, err := addOptions(path, query{ids})
if err != nil {
return nil, nil, nil, nil, err
}
path := fmt.Sprintf("api/info?id=%s", strings.Join(ids, ","))
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
@ -48,11 +39,8 @@ func (s *ListingsService) Get(ctx context.Context, ids ...string) ([]*Post, []*C
// GetPosts returns posts from their full IDs.
func (s *ListingsService) GetPosts(ctx context.Context, ids ...string) ([]*Post, *Response, error) {
if len(ids) == 0 {
return nil, nil, errors.New("must provide at least 1 id")
}
path := fmt.Sprintf("by_id/%s", strings.Join(ids, ","))
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
@ -64,5 +52,6 @@ func (s *ListingsService) GetPosts(ctx context.Context, ids ...string) ([]*Post,
return nil, resp, err
}
return root.getPosts().Posts, resp, nil
posts := root.getPosts().Posts
return posts, resp, nil
}

183
listings_test.go Normal file
View File

@ -0,0 +1,183 @@
package reddit
import (
"fmt"
"net/http"
"net/url"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var expectedListingPosts = []*Post{
{
ID: "i2gvg4",
FullID: "t3_i2gvg4",
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 8, 0, time.UTC)},
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
URL: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
Title: "This is a title",
Body: "This is some text",
Likes: Bool(true),
Score: 1,
UpvoteRatio: 1,
NumberOfComments: 1,
SubredditID: "t5_2qh23",
SubredditName: "test",
SubredditNamePrefixed: "r/test",
AuthorID: "t2_164ab8",
AuthorName: "v_95",
IsSelfPost: true,
},
}
var expectedListingComments = []*Comment{
{
ID: "g05v931",
FullID: "t1_g05v931",
Created: &Timestamp{time.Date(2020, 8, 3, 1, 15, 40, 0, time.UTC)},
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
ParentID: "t3_i2gvg4",
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/g05v931/",
// todo fix naming
Body: "Test comment",
Author: "v_95",
AuthorID: "t2_164ab8",
// todo fix naming
Subreddit: "test",
SubredditNamePrefixed: "r/test",
SubredditID: "t5_2qh23",
Likes: Bool(true),
Score: 1,
Controversiality: 0,
PostID: "t3_i2gvg4",
IsSubmitter: true,
},
}
var expectedListingSubreddits = []*Subreddit{
{
ID: "2qh23",
FullID: "t5_2qh23",
Created: &Timestamp{time.Date(2008, 1, 25, 5, 11, 28, 0, time.UTC)},
URL: "/r/test/",
Name: "test",
NamePrefixed: "r/test",
Title: "Testing",
Type: "public",
Subscribers: 8202,
},
}
var expectedListingPosts2 = []*Post{
{
ID: "i2gvg4",
FullID: "t3_i2gvg4",
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 8, 0, time.UTC)},
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
Permalink: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
URL: "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
Title: "This is a title",
Body: "This is some text",
Likes: Bool(true),
Score: 1,
UpvoteRatio: 1,
NumberOfComments: 1,
SubredditID: "t5_2qh23",
SubredditName: "test",
SubredditNamePrefixed: "r/test",
AuthorID: "t2_164ab8",
AuthorName: "v_95",
IsSelfPost: true,
},
{
ID: "i2gvs1",
FullID: "t3_i2gvs1",
Created: &Timestamp{time.Date(2020, 8, 2, 18, 23, 37, 0, time.UTC)},
Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)},
Permalink: "https://www.reddit.com/r/test/comments/i2gvs1/this_is_a_title/",
URL: "http://example.com",
Title: "This is a title",
Likes: Bool(true),
Score: 1,
UpvoteRatio: 1,
NumberOfComments: 0,
SubredditID: "t5_2qh23",
SubredditName: "test",
SubredditNamePrefixed: "r/test",
AuthorID: "t2_164ab8",
AuthorName: "v_95",
},
}
func TestListingsService_Get(t *testing.T) {
setup()
defer teardown()
blob, err := readFileContents("testdata/listings/posts-comments-subreddits.json")
assert.NoError(t, err)
mux.HandleFunc("/api/info", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
form := url.Values{}
form.Set("id", "t5_2qh23,t3_i2gvg4,t1_g05v931")
err := r.ParseForm()
assert.NoError(t, err)
assert.Equal(t, form, r.Form)
fmt.Fprint(w, blob)
})
posts, comments, subreddits, _, err := client.Listings.Get(ctx, "t5_2qh23", "t3_i2gvg4", "t1_g05v931")
assert.NoError(t, err)
assert.Equal(t, expectedListingPosts, posts)
assert.Equal(t, expectedListingComments, comments)
assert.Equal(t, expectedListingSubreddits, subreddits)
}
func TestListingsService_GetPosts(t *testing.T) {
setup()
defer teardown()
blob, err := readFileContents("testdata/listings/posts.json")
assert.NoError(t, err)
mux.HandleFunc("/by_id/t3_i2gvg4,t3_i2gwgz", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method)
fmt.Fprint(w, blob)
})
posts, _, err := client.Listings.GetPosts(ctx, "t3_i2gvg4", "t3_i2gwgz")
assert.NoError(t, err)
assert.Equal(t, expectedListingPosts2, posts)
}

View File

@ -117,6 +117,9 @@ func TestMultiService_Copy(t *testing.T) {
fmt.Fprint(w, blob)
})
_, _, err = client.Multi.Copy(ctx, nil)
assert.EqualError(t, err, "copyRequest: cannot be nil")
multi, _, err := client.Multi.Copy(ctx, &MultiCopyRequest{
FromPath: "user/testuser/m/testmulti",
ToPath: "user/testuser2/m/testmulti2",
@ -157,6 +160,9 @@ func TestMultiService_Create(t *testing.T) {
fmt.Fprint(w, blob)
})
_, _, err = client.Multi.Create(ctx, nil)
assert.EqualError(t, err, "createRequest: cannot be nil")
multi, _, err := client.Multi.Create(ctx, createRequest)
assert.NoError(t, err)
assert.Equal(t, expectedMulti, multi)
@ -191,6 +197,9 @@ func TestMultiService_Update(t *testing.T) {
fmt.Fprint(w, blob)
})
_, _, err = client.Multi.Update(ctx, "user/testuser/m/testmulti", nil)
assert.EqualError(t, err, "updateRequest: cannot be nil")
multi, _, err := client.Multi.Update(ctx, "user/testuser/m/testmulti", updateRequest)
assert.NoError(t, err)
assert.Equal(t, expectedMulti, multi)

View File

@ -436,7 +436,7 @@ func (s *PostService) DisableContestMode(ctx context.Context, id string) (*Respo
// LoadMoreComments retrieves more comments that were left out when initially fetching the post.
func (s *PostService) LoadMoreComments(ctx context.Context, pc *PostAndComments) (*Response, error) {
if pc == nil {
return nil, errors.New("pc: must not be nil")
return nil, errors.New("pc: cannot be nil")
}
if !pc.hasMore() {

View File

@ -753,7 +753,7 @@ func TestPostService_MoreNil(t *testing.T) {
defer teardown()
_, err := client.Comment.LoadMoreReplies(ctx, nil)
assert.EqualError(t, err, "comment: must not be nil")
assert.EqualError(t, err, "comment: cannot be nil")
parentComment := &Comment{
Replies: Replies{

View File

@ -103,7 +103,7 @@ func (s *SubredditService) Top(ctx context.Context, subreddit string, opts ...Se
// Get gets a subreddit by name.
func (s *SubredditService) Get(ctx context.Context, name string) (*Subreddit, *Response, error) {
if name == "" {
return nil, nil, errors.New("name: must not be empty")
return nil, nil, errors.New("name: cannot be empty")
}
path := fmt.Sprintf("r/%s/about", name)
@ -406,7 +406,7 @@ func (s *SubredditService) RandomNSFW(ctx context.Context) (*Subreddit, *Respons
// This text is set by the subreddit moderators and intended to be displayed on the submission form.
func (s *SubredditService) SubmissionText(ctx context.Context, name string) (string, *Response, error) {
if name == "" {
return "", nil, errors.New("name: must not be empty")
return "", nil, errors.New("name: cannot be empty")
}
path := fmt.Sprintf("r/%s/api/submit_text", name)

View File

@ -317,7 +317,7 @@ func TestSubredditService_Get(t *testing.T) {
})
_, _, err = client.Subreddit.Get(ctx, "")
assert.EqualError(t, err, "name: must not be empty")
assert.EqualError(t, err, "name: cannot be empty")
subreddit, _, err := client.Subreddit.Get(ctx, "golang")
assert.NoError(t, err)

View File

@ -0,0 +1,290 @@
{
"kind": "Listing",
"data": {
"modhash": null,
"dist": 3,
"children": [
{
"kind": "t5",
"data": {
"user_flair_background_color": null,
"submit_text_html": null,
"restrict_posting": true,
"user_is_banned": false,
"free_form_reports": true,
"wiki_enabled": null,
"user_is_muted": false,
"user_can_flair_in_sr": null,
"display_name": "test",
"header_img": null,
"title": "Testing",
"allow_galleries": true,
"icon_size": null,
"primary_color": "",
"active_user_count": null,
"icon_img": "",
"display_name_prefixed": "r/test",
"accounts_active": null,
"public_traffic": false,
"subscribers": 8202,
"user_flair_richtext": [],
"videostream_links_count": 2,
"name": "t5_2qh23",
"quarantine": false,
"hide_ads": false,
"emojis_enabled": false,
"advertiser_category": "",
"public_description": "",
"comment_score_hide_mins": 0,
"user_has_favorited": false,
"user_flair_template_id": null,
"community_icon": "",
"banner_background_image": "",
"original_content_tag_enabled": false,
"submit_text": "",
"description_html": "&lt;!-- SC_OFF --&gt;&lt;div class=\"md\"&gt;&lt;p&gt;This is a place to test things.&lt;/p&gt;\n&lt;/div&gt;&lt;!-- SC_ON --&gt;",
"spoilers_enabled": true,
"header_title": null,
"header_size": null,
"user_flair_position": "right",
"all_original_content": false,
"has_menu_widget": false,
"is_enrolled_in_new_modmail": null,
"key_color": "",
"can_assign_user_flair": true,
"created": 1201266688.0,
"wls": 6,
"show_media_preview": true,
"submission_type": "any",
"user_is_subscriber": true,
"disable_contributor_requests": false,
"allow_videogifs": true,
"user_flair_type": "text",
"allow_polls": true,
"collapse_deleted_comments": false,
"emojis_custom_size": null,
"public_description_html": null,
"allow_videos": true,
"is_crosspostable_subreddit": true,
"suggested_comment_sort": null,
"can_assign_link_flair": true,
"accounts_active_is_fuzzed": false,
"submit_text_label": null,
"link_flair_position": "left",
"user_sr_flair_enabled": null,
"user_flair_enabled_in_sr": false,
"allow_chat_post_creation": false,
"allow_discovery": true,
"user_sr_theme_enabled": true,
"link_flair_enabled": true,
"subreddit_type": "public",
"notification_level": "low",
"banner_img": "",
"user_flair_text": null,
"banner_background_color": "",
"show_media": true,
"id": "2qh23",
"user_is_contributor": false,
"over18": false,
"description": "This is a place to test things.",
"is_chat_post_feature_enabled": true,
"submit_link_label": null,
"user_flair_text_color": null,
"restrict_commenting": false,
"user_flair_css_class": null,
"allow_images": true,
"lang": "en",
"whitelist_status": "all_ads",
"url": "/r/test/",
"created_utc": 1201237888.0,
"banner_size": null,
"mobile_banner_image": "",
"user_is_moderator": false
}
},
{
"kind": "t3",
"data": {
"approved_at_utc": null,
"subreddit": "test",
"selftext": "This is some text",
"author_fullname": "t2_164ab8",
"saved": false,
"mod_reason_title": null,
"gilded": 0,
"clicked": false,
"title": "This is a title",
"link_flair_richtext": [],
"subreddit_name_prefixed": "r/test",
"hidden": false,
"pwls": 6,
"link_flair_css_class": null,
"downs": 0,
"thumbnail_height": null,
"top_awarded_type": null,
"hide_score": false,
"name": "t3_i2gvg4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 1.0,
"author_flair_background_color": null,
"subreddit_type": "public",
"ups": 1,
"total_awards_received": 0,
"media_embed": {},
"thumbnail_width": null,
"author_flair_template_id": null,
"is_original_content": false,
"user_reports": [],
"secure_media": null,
"is_reddit_media_domain": false,
"is_meta": false,
"category": null,
"secure_media_embed": {},
"link_flair_text": null,
"can_mod_post": false,
"score": 1,
"approved_by": null,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"author_flair_css_class": null,
"author_flair_richtext": [],
"gildings": {},
"content_categories": null,
"is_self": true,
"mod_note": null,
"created": 1596421388.0,
"link_flair_type": "text",
"wls": 6,
"removed_by_category": null,
"banned_by": null,
"author_flair_type": "text",
"domain": "self.test",
"allow_live_comments": false,
"selftext_html": "&lt;!-- SC_OFF --&gt;&lt;div class=\"md\"&gt;&lt;p&gt;This is some text&lt;/p&gt;\n&lt;/div&gt;&lt;!-- SC_ON --&gt;",
"likes": true,
"suggested_sort": null,
"banned_at_utc": null,
"view_count": null,
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"all_awardings": [],
"awarders": [],
"media_only": false,
"can_gild": false,
"spoiler": false,
"locked": false,
"author_flair_text": null,
"treatment_tags": [],
"rte_mode": "markdown",
"visited": false,
"removed_by": null,
"num_reports": null,
"distinguished": null,
"subreddit_id": "t5_2qh23",
"mod_reason_by": null,
"removal_reason": null,
"link_flair_background_color": "",
"id": "i2gvg4",
"is_robot_indexable": true,
"report_reasons": null,
"author": "v_95",
"discussion_type": null,
"num_comments": 1,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"mod_reports": [],
"author_patreon_flair": false,
"author_flair_text_color": null,
"permalink": "/r/test/comments/i2gvg4/this_is_a_title/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
"subreddit_subscribers": 8202,
"created_utc": 1596392588.0,
"num_crossposts": 0,
"media": null,
"is_video": false
}
},
{
"kind": "t1",
"data": {
"total_awards_received": 0,
"approved_at_utc": null,
"edited": false,
"mod_reason_by": null,
"banned_by": null,
"author_flair_type": "text",
"removal_reason": null,
"link_id": "t3_i2gvg4",
"author_flair_template_id": null,
"likes": true,
"replies": "",
"user_reports": [],
"saved": false,
"id": "g05v931",
"banned_at_utc": null,
"mod_reason_title": null,
"gilded": 0,
"archived": false,
"no_follow": false,
"author": "v_95",
"can_mod_post": false,
"created_utc": 1596417340.0,
"send_replies": true,
"parent_id": "t3_i2gvg4",
"score": 1,
"author_fullname": "t2_164ab8",
"approved_by": null,
"mod_note": null,
"all_awardings": [],
"subreddit_id": "t5_2qh23",
"body": "Test comment",
"awarders": [],
"author_flair_css_class": null,
"name": "t1_g05v931",
"author_patreon_flair": false,
"downs": 0,
"author_flair_richtext": [],
"is_submitter": true,
"body_html": "&lt;div class=\"md\"&gt;&lt;p&gt;Test comment&lt;/p&gt;\n&lt;/div&gt;",
"gildings": {},
"collapsed_reason": null,
"distinguished": null,
"associated_award": null,
"stickied": false,
"author_premium": false,
"can_gild": false,
"top_awarded_type": null,
"author_flair_text_color": null,
"score_hidden": false,
"permalink": "/r/test/comments/i2gvg4/this_is_a_title/g05v931/",
"num_reports": null,
"locked": false,
"report_reasons": null,
"created": 1596446140.0,
"subreddit": "test",
"author_flair_text": null,
"treatment_tags": [],
"rte_mode": "markdown",
"collapsed": false,
"subreddit_name_prefixed": "r/test",
"controversiality": 0,
"author_flair_background_color": null,
"collapsed_because_crowd_control": null,
"mod_reports": [],
"subreddit_type": "public",
"ups": 1
}
}
],
"after": null,
"before": null
}
}

232
testdata/listings/posts.json vendored Normal file
View File

@ -0,0 +1,232 @@
{
"kind": "Listing",
"data": {
"modhash": null,
"dist": 2,
"children": [
{
"kind": "t3",
"data": {
"approved_at_utc": null,
"subreddit": "test",
"selftext": "This is some text",
"author_fullname": "t2_164ab8",
"saved": false,
"mod_reason_title": null,
"gilded": 0,
"clicked": false,
"title": "This is a title",
"link_flair_richtext": [],
"subreddit_name_prefixed": "r/test",
"hidden": false,
"pwls": 6,
"link_flair_css_class": null,
"downs": 0,
"thumbnail_height": null,
"top_awarded_type": null,
"hide_score": false,
"name": "t3_i2gvg4",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 1.0,
"author_flair_background_color": null,
"subreddit_type": "public",
"ups": 1,
"total_awards_received": 0,
"media_embed": {},
"thumbnail_width": null,
"author_flair_template_id": null,
"is_original_content": false,
"user_reports": [],
"secure_media": null,
"is_reddit_media_domain": false,
"is_meta": false,
"category": null,
"secure_media_embed": {},
"link_flair_text": null,
"can_mod_post": false,
"score": 1,
"approved_by": null,
"author_premium": false,
"thumbnail": "self",
"edited": false,
"author_flair_css_class": null,
"author_flair_richtext": [],
"gildings": {},
"content_categories": null,
"is_self": true,
"mod_note": null,
"created": 1596421388.0,
"link_flair_type": "text",
"wls": 6,
"removed_by_category": null,
"banned_by": null,
"author_flair_type": "text",
"domain": "self.test",
"allow_live_comments": false,
"selftext_html": "&lt;!-- SC_OFF --&gt;&lt;div class=\"md\"&gt;&lt;p&gt;This is some text&lt;/p&gt;\n&lt;/div&gt;&lt;!-- SC_ON --&gt;",
"likes": true,
"suggested_sort": null,
"banned_at_utc": null,
"view_count": null,
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"all_awardings": [],
"awarders": [],
"media_only": false,
"can_gild": false,
"spoiler": false,
"locked": false,
"author_flair_text": null,
"treatment_tags": [],
"rte_mode": "markdown",
"visited": false,
"removed_by": null,
"num_reports": null,
"distinguished": null,
"subreddit_id": "t5_2qh23",
"mod_reason_by": null,
"removal_reason": null,
"link_flair_background_color": "",
"id": "i2gvg4",
"is_robot_indexable": true,
"report_reasons": null,
"author": "v_95",
"discussion_type": null,
"num_comments": 1,
"send_replies": true,
"whitelist_status": "all_ads",
"contest_mode": false,
"mod_reports": [],
"author_patreon_flair": false,
"author_flair_text_color": null,
"permalink": "/r/test/comments/i2gvg4/this_is_a_title/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "https://www.reddit.com/r/test/comments/i2gvg4/this_is_a_title/",
"subreddit_subscribers": 8201,
"created_utc": 1596392588.0,
"num_crossposts": 0,
"media": null,
"is_video": false
}
},
{
"kind": "t3",
"data": {
"approved_at_utc": null,
"subreddit": "test",
"selftext": "",
"author_fullname": "t2_164ab8",
"saved": false,
"mod_reason_title": null,
"gilded": 0,
"clicked": false,
"title": "This is a title",
"link_flair_richtext": [],
"subreddit_name_prefixed": "r/test",
"hidden": false,
"pwls": 6,
"link_flair_css_class": null,
"downs": 0,
"thumbnail_height": null,
"top_awarded_type": null,
"hide_score": false,
"name": "t3_i2gvs1",
"quarantine": false,
"link_flair_text_color": "dark",
"upvote_ratio": 1.0,
"author_flair_background_color": null,
"subreddit_type": "public",
"ups": 1,
"total_awards_received": 0,
"media_embed": {},
"thumbnail_width": null,
"author_flair_template_id": null,
"is_original_content": false,
"user_reports": [],
"secure_media": null,
"is_reddit_media_domain": false,
"is_meta": false,
"category": null,
"secure_media_embed": {},
"link_flair_text": null,
"can_mod_post": false,
"score": 1,
"approved_by": null,
"author_premium": false,
"thumbnail": "default",
"edited": false,
"author_flair_css_class": null,
"author_flair_richtext": [],
"gildings": {},
"content_categories": null,
"is_self": false,
"mod_note": null,
"created": 1596421417.0,
"link_flair_type": "text",
"wls": 6,
"removed_by_category": null,
"banned_by": null,
"author_flair_type": "text",
"domain": "example.com",
"allow_live_comments": false,
"selftext_html": null,
"likes": true,
"suggested_sort": null,
"banned_at_utc": null,
"url_overridden_by_dest": "http://example.com",
"view_count": null,
"archived": false,
"no_follow": false,
"is_crosspostable": true,
"pinned": false,
"over_18": false,
"all_awardings": [],
"awarders": [],
"media_only": false,
"can_gild": false,
"spoiler": false,
"locked": false,
"author_flair_text": null,
"treatment_tags": [],
"rte_mode": "markdown",
"visited": false,
"removed_by": null,
"num_reports": null,
"distinguished": null,
"subreddit_id": "t5_2qh23",
"mod_reason_by": null,
"removal_reason": null,
"link_flair_background_color": "",
"id": "i2gvs1",
"is_robot_indexable": true,
"report_reasons": null,
"author": "v_95",
"discussion_type": null,
"num_comments": 0,
"send_replies": false,
"whitelist_status": "all_ads",
"contest_mode": false,
"mod_reports": [],
"author_patreon_flair": false,
"author_flair_text_color": null,
"permalink": "/r/test/comments/i2gvs1/this_is_a_title/",
"parent_whitelist_status": "all_ads",
"stickied": false,
"url": "http://example.com",
"subreddit_subscribers": 8201,
"created_utc": 1596392617.0,
"num_crossposts": 0,
"media": null,
"is_video": false
}
}
],
"after": null,
"before": null
}
}

View File

@ -167,6 +167,7 @@ type Comment struct {
Score int `json:"score"`
Controversiality int `json:"controversiality"`
// todo: check the validity of these comments
PostID string `json:"link_id,omitempty"`
// This doesn't appear when submitting a comment.
PostTitle string `json:"link_title,omitempty"`