author | Mikael Berthe <mikael@lilotux.net> |
Tue, 20 Mar 2018 19:20:31 +0100 | |
changeset 214 | 642d690de0ba |
parent 207 | 301d5b94be3f |
child 230 | d13e9a780d91 |
permissions | -rw-r--r-- |
130 | 1 |
/* |
207 | 2 |
Copyright 2017-2018 Mikael Berthe |
130 | 3 |
|
4 |
Licensed under the MIT license. Please see the LICENSE file is this directory. |
|
5 |
*/ |
|
6 |
||
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
7 |
package madon |
103 | 8 |
|
9 |
import ( |
|
10 |
"fmt" |
|
11 |
"strconv" |
|
12 |
||
162
68df3a01e1a7
Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents:
161
diff
changeset
|
13 |
"github.com/pkg/errors" |
103 | 14 |
"github.com/sendgrid/rest" |
15 |
) |
|
16 |
||
108 | 17 |
// 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
|
18 |
type updateStatusOptions struct { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
19 |
// The ID is used for most commands |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
20 |
ID int64 |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
21 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
22 |
// The following fields are used for posting a new status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
23 |
Status string |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
24 |
InReplyToID int64 |
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
25 |
MediaIDs []int64 |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
26 |
Sensitive bool |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
27 |
SpoilerText string |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
28 |
Visibility string // "direct", "private", "unlisted" or "public" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
29 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
30 |
|
160
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
31 |
// getMultipleStatuses returns a list of status entities |
161
6786f169b59f
Refactor getMultipleAccounts
Mikael Berthe <mikael@lilotux.net>
parents:
160
diff
changeset
|
32 |
// If lopt.All is true, several requests will be made until the API server |
160
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
33 |
// has nothing to return. |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
34 |
func (mc *Client) getMultipleStatuses(endPoint string, params apiCallParams, lopt *LimitParams) ([]Status, error) { |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
35 |
var statuses []Status |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
36 |
var links apiLinks |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
37 |
if err := mc.apiCall(endPoint, rest.Get, params, lopt, &links, &statuses); err != nil { |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
38 |
return nil, err |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
39 |
} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
40 |
if lopt != nil { // Fetch more pages to reach our limit |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
41 |
var statusSlice []Status |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
42 |
for (lopt.All || lopt.Limit > len(statuses)) && links.next != nil { |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
43 |
newlopt := links.next |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
44 |
links = apiLinks{} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
45 |
if err := mc.apiCall(endPoint, rest.Get, params, newlopt, &links, &statusSlice); err != nil { |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
46 |
return nil, err |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
47 |
} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
48 |
statuses = append(statuses, statusSlice...) |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
49 |
statusSlice = statusSlice[:0] // Clear struct |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
50 |
} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
51 |
} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
52 |
return statuses, nil |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
53 |
} |
9f7e683b323f
Refactor methods returning a list of statuses
Mikael Berthe <mikael@lilotux.net>
parents:
159
diff
changeset
|
54 |
|
103 | 55 |
// queryStatusData queries the statuses API |
120 | 56 |
// The operation 'op' can be empty or "status" (the status itself), "context", |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
57 |
// "card", "reblogged_by", "favourited_by". |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
58 |
// The data argument will receive the object(s) returned by the API server. |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
59 |
func (mc *Client) queryStatusData(statusID int64, op string, data interface{}) error { |
103 | 60 |
if statusID < 1 { |
61 |
return ErrInvalidID |
|
62 |
} |
|
63 |
||
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
64 |
endPoint := "statuses/" + strconv.FormatInt(statusID, 10) |
120 | 65 |
|
66 |
if op != "" && op != "status" { |
|
67 |
switch op { |
|
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
68 |
case "context", "card", "reblogged_by", "favourited_by": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
69 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
70 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
71 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
72 |
|
120 | 73 |
endPoint += "/" + op |
103 | 74 |
} |
75 |
||
155 | 76 |
return mc.apiCall(endPoint, rest.Get, nil, nil, nil, data) |
103 | 77 |
} |
78 |
||
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
79 |
// updateStatusData updates the statuses |
120 | 80 |
// The operation 'op' can be empty or "status" (to post a status), "delete" |
203
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
81 |
// (for deleting a status), "reblog"/"unreblog", "favourite"/"unfavourite", |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
82 |
// "mute"/"unmute" (for conversations) or "pin"/"unpin". |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
83 |
// The data argument will receive the object(s) returned by the API server. |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
84 |
func (mc *Client) updateStatusData(op string, opts updateStatusOptions, data interface{}) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
85 |
method := rest.Post |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
86 |
endPoint := "statuses" |
120 | 87 |
params := make(apiCallParams) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
88 |
|
120 | 89 |
switch op { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
90 |
case "", "status": |
120 | 91 |
op = "status" |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
92 |
if opts.Status == "" { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
93 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
94 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
95 |
switch opts.Visibility { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
96 |
case "", "direct", "private", "unlisted", "public": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
97 |
// Okay |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
98 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
99 |
return ErrInvalidParameter |
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 |
if len(opts.MediaIDs) > 4 { |
162
68df3a01e1a7
Use github.com/pkg/errors
Mikael Berthe <mikael@lilotux.net>
parents:
161
diff
changeset
|
102 |
return errors.New("too many (>4) media IDs") |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
103 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
104 |
case "delete": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
105 |
method = rest.Delete |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
106 |
if opts.ID < 1 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
107 |
return ErrInvalidID |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
108 |
} |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
109 |
endPoint += "/" + strconv.FormatInt(opts.ID, 10) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
110 |
case "reblog", "unreblog", "favourite", "unfavourite": |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
111 |
if opts.ID < 1 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
112 |
return ErrInvalidID |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
113 |
} |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
114 |
endPoint += "/" + strconv.FormatInt(opts.ID, 10) + "/" + op |
203
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
115 |
case "mute", "unmute", "pin", "unpin": |
188
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
116 |
if opts.ID < 1 { |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
117 |
return ErrInvalidID |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
118 |
} |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
119 |
endPoint += "/" + strconv.FormatInt(opts.ID, 10) + "/" + op |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
120 |
default: |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
121 |
return ErrInvalidParameter |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
122 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
123 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
124 |
// Form items for a new toot |
120 | 125 |
if op == "status" { |
126 |
params["status"] = opts.Status |
|
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
127 |
if opts.InReplyToID > 0 { |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
128 |
params["in_reply_to_id"] = strconv.FormatInt(opts.InReplyToID, 10) |
105
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 |
for i, id := range opts.MediaIDs { |
134
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
132
diff
changeset
|
131 |
if id < 1 { |
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
132
diff
changeset
|
132 |
return ErrInvalidID |
588edbc9e14b
Add checks on ID list values
Mikael Berthe <mikael@lilotux.net>
parents:
132
diff
changeset
|
133 |
} |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
134 |
qID := fmt.Sprintf("media_ids[%d]", i+1) |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
135 |
params[qID] = strconv.FormatInt(id, 10) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
136 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
137 |
if opts.Sensitive { |
120 | 138 |
params["sensitive"] = "true" |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
139 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
140 |
if opts.SpoilerText != "" { |
120 | 141 |
params["spoiler_text"] = opts.SpoilerText |
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 |
if opts.Visibility != "" { |
120 | 144 |
params["visibility"] = opts.Visibility |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
145 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
146 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
147 |
|
155 | 148 |
return mc.apiCall(endPoint, method, params, nil, nil, data) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
149 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
150 |
|
103 | 151 |
// GetStatus returns a status |
152 |
// The returned status can be nil if there is an error or if the |
|
153 |
// requested ID does not exist. |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
154 |
func (mc *Client) GetStatus(statusID int64) (*Status, error) { |
103 | 155 |
var status Status |
156 |
||
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
157 |
if err := mc.queryStatusData(statusID, "status", &status); err != nil { |
103 | 158 |
return nil, err |
159 |
} |
|
160 |
if status.ID == 0 { |
|
161 |
return nil, ErrEntityNotFound |
|
162 |
} |
|
163 |
return &status, nil |
|
164 |
} |
|
165 |
||
166 |
// GetStatusContext returns a status context |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
167 |
func (mc *Client) GetStatusContext(statusID int64) (*Context, error) { |
103 | 168 |
var context Context |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
169 |
if err := mc.queryStatusData(statusID, "context", &context); err != nil { |
103 | 170 |
return nil, err |
171 |
} |
|
172 |
return &context, nil |
|
173 |
} |
|
174 |
||
175 |
// GetStatusCard returns a status card |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
176 |
func (mc *Client) GetStatusCard(statusID int64) (*Card, error) { |
103 | 177 |
var card Card |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
178 |
if err := mc.queryStatusData(statusID, "card", &card); err != nil { |
103 | 179 |
return nil, err |
180 |
} |
|
181 |
return &card, nil |
|
182 |
} |
|
183 |
||
184 |
// GetStatusRebloggedBy returns a list of the accounts who reblogged a status |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
185 |
func (mc *Client) GetStatusRebloggedBy(statusID int64, lopt *LimitParams) ([]Account, error) { |
155 | 186 |
o := &getAccountsOptions{ID: statusID, Limit: lopt} |
161
6786f169b59f
Refactor getMultipleAccounts
Mikael Berthe <mikael@lilotux.net>
parents:
160
diff
changeset
|
187 |
return mc.getMultipleAccountsHelper("reblogged_by", o) |
103 | 188 |
} |
189 |
||
190 |
// GetStatusFavouritedBy returns a list of the accounts who favourited a status |
|
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
191 |
func (mc *Client) GetStatusFavouritedBy(statusID int64, lopt *LimitParams) ([]Account, error) { |
155 | 192 |
o := &getAccountsOptions{ID: statusID, Limit: lopt} |
161
6786f169b59f
Refactor getMultipleAccounts
Mikael Berthe <mikael@lilotux.net>
parents:
160
diff
changeset
|
193 |
return mc.getMultipleAccountsHelper("favourited_by", o) |
103 | 194 |
} |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
195 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
196 |
// PostStatus posts a new "toot" |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
197 |
// All parameters but "text" can be empty. |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
198 |
// Visibility must be empty, or one of "direct", "private", "unlisted" and "public". |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
199 |
func (mc *Client) PostStatus(text string, inReplyTo int64, mediaIDs []int64, sensitive bool, spoilerText string, visibility string) (*Status, error) { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
200 |
var status Status |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
201 |
o := updateStatusOptions{ |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
202 |
Status: text, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
203 |
InReplyToID: inReplyTo, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
204 |
MediaIDs: mediaIDs, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
205 |
Sensitive: sensitive, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
206 |
SpoilerText: spoilerText, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
207 |
Visibility: visibility, |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
208 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
209 |
|
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
210 |
err := mc.updateStatusData("status", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
211 |
if err != nil { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
212 |
return nil, err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
213 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
214 |
if status.ID == 0 { |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
215 |
return nil, ErrEntityNotFound // TODO Change error message |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
216 |
} |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
217 |
return &status, err |
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 |
|
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
220 |
// DeleteStatus deletes a status |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
221 |
func (mc *Client) DeleteStatus(statusID int64) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
222 |
var status Status |
132
639bbcddb4fe
Make identifiers less ambiguous
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
223 |
o := updateStatusOptions{ID: statusID} |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
224 |
err := mc.updateStatusData("delete", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
225 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
226 |
} |
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 |
// ReblogStatus reblogs a status |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
229 |
func (mc *Client) ReblogStatus(statusID int64) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
230 |
var status Status |
132
639bbcddb4fe
Make identifiers less ambiguous
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
231 |
o := updateStatusOptions{ID: statusID} |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
232 |
err := mc.updateStatusData("reblog", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
233 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
234 |
} |
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 |
// UnreblogStatus unreblogs a status |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
237 |
func (mc *Client) UnreblogStatus(statusID int64) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
238 |
var status Status |
132
639bbcddb4fe
Make identifiers less ambiguous
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
239 |
o := updateStatusOptions{ID: statusID} |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
240 |
err := mc.updateStatusData("unreblog", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
241 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
242 |
} |
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 |
// FavouriteStatus favourites a status |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
245 |
func (mc *Client) FavouriteStatus(statusID int64) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
246 |
var status Status |
132
639bbcddb4fe
Make identifiers less ambiguous
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
247 |
o := updateStatusOptions{ID: statusID} |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
248 |
err := mc.updateStatusData("favourite", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
249 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
250 |
} |
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 |
// UnfavouriteStatus unfavourites a status |
159
408aa794d9bb
s/int/int64/ for IDs and time integers
Mikael Berthe <mikael@lilotux.net>
parents:
155
diff
changeset
|
253 |
func (mc *Client) UnfavouriteStatus(statusID int64) error { |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
254 |
var status Status |
132
639bbcddb4fe
Make identifiers less ambiguous
Mikael Berthe <mikael@lilotux.net>
parents:
130
diff
changeset
|
255 |
o := updateStatusOptions{ID: statusID} |
138
23d3a518d0ad
Update package name in source files
Mikael Berthe <mikael@lilotux.net>
parents:
134
diff
changeset
|
256 |
err := mc.updateStatusData("unfavourite", o, &status) |
105
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
257 |
return err |
e2a16e19eb8b
Add missing status commands
Mikael Berthe <mikael@lilotux.net>
parents:
103
diff
changeset
|
258 |
} |
188
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
259 |
|
203
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
260 |
// PinStatus pins a status |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
261 |
func (mc *Client) PinStatus(statusID int64) error { |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
262 |
var status Status |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
263 |
o := updateStatusOptions{ID: statusID} |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
264 |
err := mc.updateStatusData("pin", o, &status) |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
265 |
return err |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
266 |
} |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
267 |
|
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
268 |
// UnpinStatus unpins a status |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
269 |
func (mc *Client) UnpinStatus(statusID int64) error { |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
270 |
var status Status |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
271 |
o := updateStatusOptions{ID: statusID} |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
272 |
err := mc.updateStatusData("unpin", o, &status) |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
273 |
return err |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
274 |
} |
c7b9ddaa41b9
Add PinStatus/UnpinStatus
Mikael Berthe <mikael@lilotux.net>
parents:
188
diff
changeset
|
275 |
|
188
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
276 |
// MuteConversation mutes the conversation containing a status |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
277 |
func (mc *Client) MuteConversation(statusID int64) (*Status, error) { |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
278 |
var status Status |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
279 |
o := updateStatusOptions{ID: statusID} |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
280 |
err := mc.updateStatusData("mute", o, &status) |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
281 |
return &status, err |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
282 |
} |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
283 |
|
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
284 |
// UnmuteConversation unmutes the conversation containing a status |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
285 |
func (mc *Client) UnmuteConversation(statusID int64) (*Status, error) { |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
286 |
var status Status |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
287 |
o := updateStatusOptions{ID: statusID} |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
288 |
err := mc.updateStatusData("unmute", o, &status) |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
289 |
return &status, err |
5f4210c4921a
Add MuteConversation, UnmuteConversation
Mikael Berthe <mikael@lilotux.net>
parents:
162
diff
changeset
|
290 |
} |