-
Notifications
You must be signed in to change notification settings - Fork 13
/
actions.go
119 lines (110 loc) · 3.04 KB
/
actions.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package mira
import (
"encoding/json"
"net/http"
"github.com/thecsw/mira/v4/models"
)
// Submit submits a submission to a subreddit.
func (c *Reddit) Submit(title string, text string) (models.Submission, error) {
ret := &models.Submission{}
name, _, err := c.checkType(subredditType)
if err != nil {
return *ret, err
}
target := RedditOauth + "/api/submit"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"title": title,
"sr": name,
"text": text,
"kind": "self",
"resubmit": "true",
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}
// Reply replies to a comment with text.
func (c *Reddit) Reply(text string) (models.CommentWrap, error) {
ret := &models.CommentWrap{}
name, _, err := c.checkType(commentType)
if err != nil {
return *ret, err
}
target := RedditOauth + "/api/comment"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"text": text,
"thing_id": name,
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}
// ReplyWithID is the same as Reply but with explicit passing comment id.
func (c *Reddit) ReplyWithID(name, text string) (models.CommentWrap, error) {
ret := &models.CommentWrap{}
target := RedditOauth + "/api/comment"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"text": text,
"thing_id": name,
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}
// Save posts a comment to a submission.
func (c *Reddit) Save(text string) (models.CommentWrap, error) {
ret := &models.CommentWrap{}
name, _, err := c.checkType(submissionType)
if err != nil {
return *ret, err
}
target := RedditOauth + "/api/comment"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"text": text,
"thing_id": name,
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}
// SaveWithID is the same as Save but with explicitely passing.
func (c *Reddit) SaveWithID(name, text string) (models.CommentWrap, error) {
ret := &models.CommentWrap{}
target := RedditOauth + "/api/comment"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"text": text,
"thing_id": name,
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}
// Delete deletes whatever is next in the queue.
func (c *Reddit) Delete() error {
name, _, err := c.checkType(commentType, submissionType)
if err != nil {
return err
}
target := RedditOauth + "/api/del"
_, err = c.MiraRequest(http.MethodPost, target, map[string]string{
"id": name,
"api_type": JsonAPI,
})
return err
}
// Edit will edit the next queued comment.
func (c *Reddit) Edit(text string) (models.CommentWrap, error) {
ret := &models.CommentWrap{}
name, _, err := c.checkType(commentType, submissionType)
if err != nil {
return *ret, err
}
target := RedditOauth + "/api/editusertext"
ans, err := c.MiraRequest(http.MethodPost, target, map[string]string{
"text": text,
"thing_id": name,
"api_type": JsonAPI,
})
json.Unmarshal(ans, ret)
return *ret, err
}