Move GetPost method to PostService

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-07-18 10:02:43 -04:00
parent c85bb5485f
commit 0bfff72973
4 changed files with 322 additions and 19 deletions
+20
View File
@@ -3,6 +3,7 @@ package reddit
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
@@ -58,6 +59,25 @@ type SubmitLinkOptions struct {
Spoiler bool `url:"spoiler,omitempty"`
}
// Get returns a post with its comments.
// id is the ID36 of the post, not its full id.
// Example: instead of t3_abc123, use abc123.
func (s *PostService) Get(ctx context.Context, id string) (*Post, []Comment, *Response, error) {
path := fmt.Sprintf("comments/%s", id)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, nil, err
}
root := new(postAndComments)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, nil, resp, err
}
return root.Post, root.Comments, resp, nil
}
func (s *PostService) submit(ctx context.Context, v interface{}) (*Submitted, *Response, error) {
path := "api/submit"