author | Mikael Berthe <mikael@lilotux.net> |
Thu, 13 Apr 2017 19:03:09 +0200 | |
changeset 108 | 3f21113728f4 |
parent 106 | 356507eb8db6 |
child 110 | 0ee4bfc17cc8 |
permissions | -rw-r--r-- |
8 | 1 |
package gondole |
103 | 2 |
|
3 |
import ( |
|
4 |
"encoding/json" |
|
5 |
"fmt" |
|
6 |
"strconv" |
|
7 |
||
8 |
"github.com/sendgrid/rest" |
|
9 |
) |
|
10 |
||
108 | 11 |
// updateStatusOptions contains option fields for POST and DELETE API calls |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
12 |
type updateStatusOptions struct { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
13 |
// The ID is used for most commands |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
14 |
ID int |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
15 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
16 |
// The following fields are used for posting a new status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
17 |
Status string |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
18 |
InReplyToID int |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
19 |
MediaIDs []int |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
20 |
Sensitive bool |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
21 |
SpoilerText string |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
22 |
Visibility string // "direct", "private", "unlisted" or "public" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
23 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
24 |
|
103 | 25 |
// queryStatusData queries the statuses API |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
26 |
// The subquery can be empty or "status" (the status itself), "context", |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
27 |
// "card", "reblogged_by", "favourited_by". |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
28 |
// The data argument will receive the object(s) returned by the API server. |
103 | 29 |
func (g *Client) queryStatusData(statusID int, subquery string, data interface{}) error { |
30 |
endPoint := "statuses/" + strconv.Itoa(statusID) |
|
31 |
||
32 |
if statusID < 1 { |
|
33 |
return ErrInvalidID |
|
34 |
} |
|
35 |
||
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
36 |
if subquery != "" && subquery != "status" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
37 |
switch subquery { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
38 |
case "context", "card", "reblogged_by", "favourited_by": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
39 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
40 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
41 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
42 |
|
103 | 43 |
endPoint += "/" + subquery |
44 |
} |
|
45 |
req := g.prepareRequest(endPoint) |
|
46 |
r, err := rest.API(req) |
|
47 |
if err != nil { |
|
48 |
return fmt.Errorf("status/%s API query: %s", subquery, err.Error()) |
|
49 |
} |
|
50 |
||
106
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
51 |
// Check for error reply |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
52 |
var errorResult Error |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
53 |
if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil { |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
54 |
// The empty object is not an error |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
55 |
if errorResult.Text != "" { |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
56 |
return fmt.Errorf("%s", errorResult.Text) |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
57 |
} |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
58 |
} |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
59 |
|
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
60 |
// Not an error reply; let's unmarshal the data |
103 | 61 |
err = json.Unmarshal([]byte(r.Body), &data) |
62 |
if err != nil { |
|
63 |
return fmt.Errorf("status/%s API: %s", subquery, err.Error()) |
|
64 |
} |
|
65 |
return nil |
|
66 |
} |
|
67 |
||
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
68 |
// updateStatusData updates the statuses |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
69 |
// The subquery can be empty or "status" (to post a status), "delete" (for |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
70 |
// deleting a status), "reblog", "unreblog", "favourite", "unfavourite". |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
71 |
// The data argument will receive the object(s) returned by the API server. |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
72 |
func (g *Client) updateStatusData(subquery string, opts updateStatusOptions, data interface{}) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
73 |
method := rest.Post |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
74 |
endPoint := "statuses" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
75 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
76 |
switch subquery { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
77 |
case "", "status": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
78 |
subquery = "status" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
79 |
if opts.Status == "" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
80 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
81 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
82 |
switch opts.Visibility { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
83 |
case "", "direct", "private", "unlisted", "public": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
84 |
// Okay |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
85 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
86 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
87 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
88 |
if len(opts.MediaIDs) > 4 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
89 |
return fmt.Errorf("too many (>4) media IDs") |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
90 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
91 |
case "delete": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
92 |
method = rest.Delete |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
93 |
if opts.ID < 1 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
94 |
return ErrInvalidID |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
95 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
96 |
endPoint += "/" + strconv.Itoa(opts.ID) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
97 |
case "reblog", "unreblog", "favourite", "unfavourite": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
98 |
if opts.ID < 1 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
99 |
return ErrInvalidID |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
100 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
101 |
endPoint += "/" + strconv.Itoa(opts.ID) + "/" + subquery |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
102 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
103 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
104 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
105 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
106 |
req := g.prepareRequest(endPoint) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
107 |
req.Method = method |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
108 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
109 |
// Form items for a new toot |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
110 |
if subquery == "status" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
111 |
req.QueryParams["status"] = opts.Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
112 |
if opts.InReplyToID > 0 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
113 |
req.QueryParams["in_reply_to_id"] = strconv.Itoa(opts.InReplyToID) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
114 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
115 |
for i, id := range opts.MediaIDs { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
116 |
qID := fmt.Sprintf("media_ids[%d]", i+1) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
117 |
req.QueryParams[qID] = strconv.Itoa(id) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
118 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
119 |
if opts.Sensitive { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
120 |
req.QueryParams["sensitive"] = "true" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
121 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
122 |
if opts.SpoilerText != "" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
123 |
req.QueryParams["spoiler_text"] = opts.SpoilerText |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
124 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
125 |
if opts.Visibility != "" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
126 |
req.QueryParams["visibility"] = opts.Visibility |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
127 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
128 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
129 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
130 |
r, err := rest.API(req) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
131 |
if err != nil { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
132 |
return fmt.Errorf("status/%s API query: %s", subquery, err.Error()) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
133 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
134 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
135 |
// Check for error reply |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
136 |
var errorResult Error |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
137 |
if err := json.Unmarshal([]byte(r.Body), &errorResult); err == nil { |
106
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
138 |
// The empty object is not an error |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
139 |
if errorResult.Text != "" { |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
140 |
return fmt.Errorf("%s", errorResult.Text) |
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
141 |
} |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
142 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
143 |
|
106
356507eb8db6
Fix the check for API error result
Mikael Berthe <mikael@lilotux.net>
parents:
105
diff
changeset
|
144 |
// Not an error reply; let's unmarshal the data |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
145 |
err = json.Unmarshal([]byte(r.Body), &data) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
146 |
if err != nil { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
147 |
return fmt.Errorf("status/%s API: %s", subquery, err.Error()) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
148 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
149 |
return nil |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
150 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
151 |
|
103 | 152 |
// GetStatus returns a status |
153 |
// The returned status can be nil if there is an error or if the |
|
154 |
// requested ID does not exist. |
|
155 |
func (g *Client) GetStatus(id int) (*Status, error) { |
|
156 |
var status Status |
|
157 |
||
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
158 |
if err := g.queryStatusData(id, "status", &status); err != nil { |
103 | 159 |
return nil, err |
160 |
} |
|
161 |
||
162 |
if status.ID == 0 { |
|
163 |
return nil, ErrEntityNotFound |
|
164 |
} |
|
165 |
||
166 |
return &status, nil |
|
167 |
} |
|
168 |
||
169 |
// GetStatusContext returns a status context |
|
170 |
func (g *Client) GetStatusContext(id int) (*Context, error) { |
|
171 |
var context Context |
|
172 |
||
173 |
if err := g.queryStatusData(id, "context", &context); err != nil { |
|
174 |
return nil, err |
|
175 |
} |
|
176 |
||
177 |
return &context, nil |
|
178 |
} |
|
179 |
||
180 |
// GetStatusCard returns a status card |
|
181 |
func (g *Client) GetStatusCard(id int) (*Card, error) { |
|
182 |
var card Card |
|
183 |
||
184 |
if err := g.queryStatusData(id, "card", &card); err != nil { |
|
185 |
return nil, err |
|
186 |
} |
|
187 |
||
188 |
return &card, nil |
|
189 |
} |
|
190 |
||
191 |
// GetStatusRebloggedBy returns a list of the accounts who reblogged a status |
|
192 |
func (g *Client) GetStatusRebloggedBy(id int) ([]Account, error) { |
|
193 |
var accounts []Account |
|
194 |
err := g.queryStatusData(id, "reblogged_by", &accounts) |
|
195 |
return accounts, err |
|
196 |
} |
|
197 |
||
198 |
// GetStatusFavouritedBy returns a list of the accounts who favourited a status |
|
199 |
func (g *Client) GetStatusFavouritedBy(id int) ([]Account, error) { |
|
200 |
var accounts []Account |
|
201 |
err := g.queryStatusData(id, "favourited_by", &accounts) |
|
202 |
return accounts, err |
|
203 |
} |
|
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
204 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
205 |
// PostStatus posts a new "toot" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
206 |
// All parameters but "text" can be empty. |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
207 |
// Visibility must be empty, or one of "direct", "private", "unlisted" and "public". |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
208 |
func (g *Client) PostStatus(text string, inReplyTo int, mediaIDs []int, sensitive bool, spoilerText string, visibility string) (*Status, error) { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
209 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
210 |
o := updateStatusOptions{ |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
211 |
Status: text, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
212 |
InReplyToID: inReplyTo, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
213 |
MediaIDs: mediaIDs, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
214 |
Sensitive: sensitive, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
215 |
SpoilerText: spoilerText, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
216 |
Visibility: visibility, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
217 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
218 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
219 |
err := g.updateStatusData("status", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
220 |
if err != nil { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
221 |
return nil, err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
222 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
223 |
if status.ID == 0 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
224 |
return nil, ErrEntityNotFound // TODO Change error message |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
225 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
226 |
return &status, err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
227 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
228 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
229 |
// DeleteStatus deletes a status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
230 |
func (g *Client) DeleteStatus(id int) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
231 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
232 |
o := updateStatusOptions{ID: id} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
233 |
err := g.updateStatusData("delete", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
234 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
235 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
236 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
237 |
// ReblogStatus reblogs a status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
238 |
func (g *Client) ReblogStatus(id int) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
239 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
240 |
o := updateStatusOptions{ID: id} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
241 |
err := g.updateStatusData("reblog", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
242 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
243 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
244 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
245 |
// UnreblogStatus unreblogs a status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
246 |
func (g *Client) UnreblogStatus(id int) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
247 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
248 |
o := updateStatusOptions{ID: id} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
249 |
err := g.updateStatusData("unreblog", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
250 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
251 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
252 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
253 |
// FavouriteStatus favourites a status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
254 |
func (g *Client) FavouriteStatus(id int) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
255 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
256 |
o := updateStatusOptions{ID: id} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
257 |
err := g.updateStatusData("favourite", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
258 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
259 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
260 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
261 |
// UnfavouriteStatus unfavourites a status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
262 |
func (g *Client) UnfavouriteStatus(id int) error { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
263 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
264 |
o := updateStatusOptions{ID: id} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
265 |
err := g.updateStatusData("unfavourite", o, &status) |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
266 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
267 |
} |