@@ -275,10 +275,112 @@ func (s LoginSession) Delete(d Deleter) error {
return nil
}
+// Distinguish makes a Submission distinguished.
+func (s LoginSession) Distinguish(ns Deleter) error {
+ req := &request{
+ url: "https://www.reddit.com/api/distinguish",
+ values: &url.Values{
+ "id": {ns.deleteID()},
+ "how": {"yes"},
+ "uh": {s.modhash},
+ },
+ cookie: s.cookie,
+ useragent: s.useragent,
+ }
+
+ body, err := req.getResponse()
+ if err != nil {
+ return err
+ }
+
+ if strings.Contains(body.String(), "error") {
+ return errors.New("failed to sticky item")
+ }
+
+ return nil
+}
+
+// Unistinguish makes a Submission undistinguished.
+func (s LoginSession) Undistinguish(ns Deleter) error {
+ req := &request{
+ url: "https://www.reddit.com/api/distinguish",
+ values: &url.Values{
+ "id": {ns.deleteID()},
+ "how": {"no"},
+ "uh": {s.modhash},
+ },
+ cookie: s.cookie,
+ useragent: s.useragent,
+ }
+
+ body, err := req.getResponse()
+ if err != nil {
+ return err
+ }
+
+ if strings.Contains(body.String(), "error") {
+ return errors.New("failed to sticky item")
+ }
+
+ return nil
+}
+
+// Sticky makes a Submission sticky.
+func (s LoginSession) Sticky(ns Deleter) error {
+ req := &request{
+ url: "https://www.reddit.com/api/set_subreddit_sticky",
+ values: &url.Values{
+ "id": {ns.deleteID()},
+ "state": {"true"},
+ "uh": {s.modhash},
+ },
+ cookie: s.cookie,
+ useragent: s.useragent,
+ }
+
+ body, err := req.getResponse()
+ if err != nil {
+ return err
+ }
+
+fmt.Println(body.String())
+ if strings.Contains(body.String(), "error") {
+ return errors.New("failed to sticky item")
+ }
+
+ return nil
+}
+
+// Unsticky unsticks a Submission.
+func (s LoginSession) Unsticky(ns Deleter) error {
+ req := &request{
+ url: "https://www.reddit.com/api/set_subreddit_sticky",
+ values: &url.Values{
+ "id": {ns.deleteID()},
+ "state": {"false"},
+ "uh": {s.modhash},
+ },
+ cookie: s.cookie,
+ useragent: s.useragent,
+ }
+
+ body, err := req.getResponse()
+ if err != nil {
+ return err
+ }
+
+fmt.Println(body.String())
+ if strings.Contains(body.String(), "error") {
+ return errors.New("failed to unsticky item")
+ }
+
+ return nil
+}
+
// NeedsCaptcha returns true if captcha is required, false if it isn't
func (s LoginSession) NeedsCaptcha() (bool, error) {
req := &request{
- url: "http://www.reddit.com/api/needs_captcha.json",
+ url: "https://www.reddit.com/api/needs_captcha.json",
cookie: s.cookie,
useragent: s.useragent,
}
@@ -301,7 +403,7 @@ func (s LoginSession) NeedsCaptcha() (bool, error) {
// NewCaptchaIden gets a new captcha iden from reddit
func (s LoginSession) NewCaptchaIden() (string, error) {
req := &request{
- url: "http://www.reddit.com/api/new_captcha",
+ url: "https://www.reddit.com/api/new_captcha",
values: &url.Values{
"api_type": {"json"},
},
@@ -341,7 +443,7 @@ func (s LoginSession) Listing(username, listing string, sort popularitySort, aft
if after != "" {
values.Set("after", after)
}
- url := fmt.Sprintf("http://www.reddit.com/user/%s/%s.json?%s", username, listing, values.Encode())
+ url := fmt.Sprintf("https://www.reddit.com/user/%s/%s.json?%s", username, listing, values.Encode())
req := &request{
url: url,
cookie: s.cookie,
diff --git a/session.go b/session.go
index 8cfdb11..0788a74 100644
--- a/session.go
+++ b/session.go
@@ -27,7 +27,7 @@ func NewSession(useragent string) *Session {
// DefaultFrontpage returns the submissions on the default reddit frontpage.
func (s Session) DefaultFrontpage() ([]*Submission, error) {
req := request{
- url: "http://www.reddit.com/.json",
+ url: "https://www.reddit.com/.json",
useragent: s.useragent,
}
body, err := req.getResponse()
@@ -59,7 +59,7 @@ func (s Session) DefaultFrontpage() ([]*Submission, error) {
// SubredditSubmissions returns the submissions on the given subreddit.
func (s Session) SubredditSubmissions(subreddit string) ([]*Submission, error) {
req := request{
- url: fmt.Sprintf("http://www.reddit.com/r/%s.json", subreddit),
+ url: fmt.Sprintf("https://www.reddit.com/r/%s.json", subreddit),
useragent: s.useragent,
}
body, err := req.getResponse()
@@ -157,7 +157,7 @@ func (s Session) SortedSubmissions(subreddit string, popularity popularitySort,
// AboutRedditor returns a Redditor for the given username.
func (s Session) AboutRedditor(username string) (*Redditor, error) {
req := &request{
- url: fmt.Sprintf("http://www.reddit.com/user/%s/about.json", username),
+ url: fmt.Sprintf("https://www.reddit.com/user/%s/about.json", username),
useragent: s.useragent,
}
body, err := req.getResponse()
@@ -180,7 +180,7 @@ func (s Session) AboutRedditor(username string) (*Redditor, error) {
// AboutSubreddit returns a subreddit for the given subreddit name.
func (s Session) AboutSubreddit(subreddit string) (*Subreddit, error) {
req := &request{
- url: fmt.Sprintf("http://www.reddit.com/r/%s/about.json", subreddit),
+ url: fmt.Sprintf("https://www.reddit.com/r/%s/about.json", subreddit),
useragent: s.useragent,
}
body, err := req.getResponse()
@@ -204,7 +204,7 @@ func (s Session) AboutSubreddit(subreddit string) (*Subreddit, error) {
// Comments returns the comments for a given Submission.
func (s Session) Comments(h *Submission) ([]*Comment, error) {
req := &request{
- url: fmt.Sprintf("http://www.reddit.com/comments/%s/.json", h.ID),
+ url: fmt.Sprintf("https://www.reddit.com/comments/%s/.json", h.ID),
useragent: s.useragent,
}
body, err := req.getResponse()
@@ -226,7 +226,7 @@ func (s Session) Comments(h *Submission) ([]*Comment, error) {
// CaptchaImage gets the png corresponding to the captcha iden and decodes it
func (s Session) CaptchaImage(iden string) (image.Image, error) {
req := &request{
- url: fmt.Sprintf("http://www.reddit.com/captcha/%s", iden),
+ url: fmt.Sprintf("https://www.reddit.com/captcha/%s", iden),
useragent: s.useragent,
}
diff --git a/submission.go b/submission.go
index e077e5e..a929a03 100644
--- a/submission.go
+++ b/submission.go
@@ -41,7 +41,7 @@ func (h Submission) replyID() string { return h.FullID }
// FullPermalink returns the full URL of a submission.
func (h *Submission) FullPermalink() string {
- return "http://reddit.com" + h.Permalink
+ return "https://www.reddit.com" + h.Permalink
}
// String returns the string representation of a submission.