Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a function that returns submission's metadata if you pass a csv… #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,40 @@ func (s Session) CaptchaImage(iden string) (image.Image, error) {

return m, nil
}

// SubmissionInfo fetches the metadata for a string of comma-separated fullnames
// (e.g,"t3_5pbezh,t3_5pbezh"). Uses https://www.reddit.com/dev/api/#GET_by_id_{names}
func (s Session) SubmissionInfo(fullnameList string) ([]*Submission, error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather the parameter have more structure by requiring a []string and we join that inside the function.


redditURL := fmt.Sprintf("https://www.reddit.com/by_id/%s/.json", fullnameList)

req := &request{
url: redditURL,
useragent: s.useragent,
}
body, err := req.getResponse()
if err != nil {
return nil, err
}

type Response struct {
Data struct {
Children []struct {
Data *Submission
}
}
}

r := new(Response)
err = json.NewDecoder(body).Decode(r)
if err != nil {
return nil, err
}

submissions := make([]*Submission, len(r.Data.Children))
for i, child := range r.Data.Children {
submissions[i] = child.Data
}

return submissions, nil
}