forked from Awful/Awful.app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AwfulHTTPClient.h
317 lines (287 loc) · 14.4 KB
/
AwfulHTTPClient.h
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
//
// AwfulHTTPClient.h
// Awful
//
// Created by Sean Berry on 5/26/12.
// Copyright (c) 2012 Regular Berry Software LLC. All rights reserved.
//
#import "AFNetworking.h"
#import "AwfulThreadPage.h"
@class AwfulPrivateMessage;
@class AwfulUser;
@interface AwfulHTTPClient : AFHTTPClient
// Singleton instance.
+ (AwfulHTTPClient *)client;
// Returns YES if the forums are reachable through current network settings.
@property (readonly, getter=isReachable, nonatomic) BOOL reachable;
// Returns YES if someone is currently logged in to the SA Forums.
@property (readonly, getter=isLoggedIn, nonatomic) BOOL loggedIn;
// Gets the threads in a forum on a given page.
//
// forumID - The ID of the forum with the threads.
// page - Which page to get.
// callback - A block to call after listing the threads, which takes as parameters:
// error - An error on failure, or nil on success.
// threads - A list of AwfulThread on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listThreadsInForumWithID:(NSString *)forumID
onPage:(NSInteger)page
andThen:(void (^)(NSError *error, NSArray *threads))callback;
// Gets the bookmarked threads on a given page.
//
// page - Which page to get.
// callback - A block to call after listing the threads, which takes as parameters:
// error - An error on failure, or nil on success.
// threads - A list of AwfulThread on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listBookmarkedThreadsOnPage:(NSInteger)page
andThen:(void (^)(NSError *error, NSArray *threads))callback;
// Gets the posts in a thread on a given page.
//
// threadID - Which thread to list.
// page - Which page to get. First page is 1; AwfulPageNextUnread and AwfulPageLast are also
// available.
// callback - A block to call after listing the posts, which takes as parameters:
// error - An error on failure, or nil on success.
// posts - The posts gleaned from the page.
// firstUnreadPost - Which post in the posts array is the first unread.
// Only set if the page requested was AwfulPageNextUnread.
// advertisementHTML - The ad at the bottom of the page.
//
// N.B. If you've never read a thread before (or marked it unread), the "next unread" page is the
// last page of the thread. (It's an SA thing, I don't get it either.)
//
// Returns the enqueued network operation.
- (NSOperation *)listPostsInThreadWithID:(NSString *)threadID
onPage:(AwfulThreadPage)page
andThen:(void (^)(NSError *error,
NSArray *posts,
NSUInteger firstUnreadPost,
NSString *advertisementHTML))callback;
// Get the logged-in user's name and ID.
//
// callback - A block to call after getting the user's info, which takes as parameters:
// error - An error on failure, or nil on success.
// userInfo - A dictionary with keys "userID", "username" on success, or nil on
// failure.
//
// Returns the enqueued network operation.
- (NSOperation *)learnUserInfoAndThen:(void (^)(NSError *error, NSDictionary *userInfo))callback;
// Add or remove a thread from the user's bookmarks.
//
// threadID - The ID of the thread to add.
// isBookmarked - YES if the thread should be added to the user's bookmarks, or NO otherwise.
// callback - A block to call after removing the thread, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)setThreadWithID:(NSString *)threadID
isBookmarked:(BOOL)isBookmarked
andThen:(void (^)(NSError *error))callback;
// Get the forum hierarchy.
//
// callback - A block to call after updating all forums and subforums, which takes as parameters:
// error - An error on failure, or nil on succes.
// forums - A list of AwfulForum on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listForumsAndThen:(void (^)(NSError *error, NSArray *forums))callback;
// Posts a new reply to a thread.
//
// threadID - The ID of the thread to reply to.
// text - The bbcode-formatted reply.
// callback - A block to call after sending the reply, which takes as parameters:
// error - An error on failure, or nil on success.
// postID - The ID of the new post, or nil if it's the last post in the thread.
//
// Returns the enqueued network operation.
- (NSOperation *)replyToThreadWithID:(NSString *)threadID
text:(NSString *)text
andThen:(void (^)(NSError *error, NSString *postID))callback;
// Get the text of a post, for editing.
//
// postID - The ID of the post.
// callback - A block to call after getting the text of the post, which takes as parameters:
// error - An error on failure, or nil on success.
// text - The text content of the post, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)getTextOfPostWithID:(NSString *)postID
andThen:(void (^)(NSError *error, NSString *text))callback;
// Get the text of a post, for quoting.
//
// postID - The ID of the post.
// callback - A block to call after getting the quoted text of the post, which takes as parameters:
// error - An error on failure, or nil on success.
// quotedText - The quoted text content of the post, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)quoteTextOfPostWithID:(NSString *)postID
andThen:(void (^)(NSError *error, NSString *quotedText))callback;
// Edit a post's content.
//
// postID - The post to edit.
// text - The new content for the post.
// callback - A block to call after editing the post, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)editPostWithID:(NSString *)postID
text:(NSString *)text
andThen:(void (^)(NSError *error))callback;
// Rate a thread.
//
// threadID - Which thread to rate.
// rating - A rating from 1 to 5, inclusive.
// callback - A block to call after voting, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)rateThreadWithID:(NSString *)threadID
rating:(NSInteger)rating
andThen:(void (^)(NSError *error))callback;
// Mark a thread as read up to a point.
//
// threadID - Which thread to mark.
// index - How many posts to mark as read.
// callback - A block to call after marking, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)markThreadWithID:(NSString *)threadID
readUpToPostAtIndex:(NSString *)index
andThen:(void (^)(NSError *error))callback;
// Mark an entire thread as unread.
//
// threadID - Which thread to mark.
// callback - A block to call after marking, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)forgetReadPostsInThreadWithID:(NSString *)threadID
andThen:(void (^)(NSError *error))callback;
// Logs in to the Forums, setting a cookie for future requests.
//
// username - Who to log in as.
// password - Their password.
// callback - A block to call after logging in, which takes as parameters:
// error - An error on failure, or nil on success.
// userInfo - A dictionary with keys "userID" and "username" on success, or nil on
// failure.
//
// Returns the enqueued network operation.
- (NSOperation *)logInAsUsername:(NSString *)username
withPassword:(NSString *)password
andThen:(void (^)(NSError *error, NSDictionary *userInfo))callback;
// Finds the thread and page where a post appears.
//
// postID - The ID of the post to locate.
// callback - A block to call after locating the post, which takes as parameters:
// error - An error on failure, or nil on success.
// threadID - The ID of the thread containing the post, or nil on failure.
// page - The page number where the post appears, or NSIntegerMax if the post
// appears on the last page, or 0 on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)locatePostWithID:(NSString *)postID
andThen:(void (^)(NSError *error, NSString *threadID, AwfulThreadPage page))callback;
// Find a user's profile.
//
// userID - The ID of the user to update with their profile info.
// callback - A block to call after updating the user info, which takes as parameters:
// error - An error on failure, or nil on success.
// user - The updated user on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)profileUserWithID:(NSString *)userID
andThen:(void (^)(NSError *error, AwfulUser *user))callback;
// List probations, bans, and permabans from the Leper's Colony.
//
// page - Which page of the Leper's Colony to list. First page is page 1.
// callback - A block to call after listing punishment, which takes as parameters:
// error - An error on failure, or nil on success.
// bans - An array of BanParsedInfo instances on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listBansOnPage:(NSInteger)page
andThen:(void (^)(NSError *error, NSArray *bans))callback;
// Attempt to access dev.forums.somethingawful.com.
//
// callback - A block to call after the access attempt, which takes as parameters:
// error - An error on failure, or nil on success.
// success - YES if dev.forums was accessible, or NO on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)tryAccessingDevDotForumsAndThen:(void (^)(NSError *error, BOOL success))callback;
// List private messages in the logged-in user's Inbox.
//
// callback - A block to call after listing messages, which takes as parameters:
// error - An error on failure, or nil on success.
// messages - An array of PrivateMessageParsedInfo instances on success, or nil on
// failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listPrivateMessagesAndThen:(void (^)(NSError *error, NSArray *messages))callback;
// Delete a private message.
//
// messageID - The ID of the message to delete.
// callback - A block to call after deleting the message, which takes as parameters:
// error - An error on failure, or nil on success.
//
// Returns the enqueued network operation.
- (NSOperation *)deletePrivateMessageWithID:(NSString *)messageID
andThen:(void (^)(NSError *error))callback;
// Read a private message.
//
// messageID - The ID of the message to read.
// callback - A block to call after reading the message, which takes as parameters:
// error - An error on failure, or nil on success.
// message - The message on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)readPrivateMessageWithID:(NSString *)messageID
andThen:(void (^)(NSError *error,
AwfulPrivateMessage *message))callback;
// Quote a private message.
//
// messageID - The ID of the message to quote.
// callback - A block to call after quoting the message, which takes as parameters:
// error - An error on failure, or nil on success.
// bbcode - The quoted message on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)quotePrivateMessageWithID:(NSString *)messageID
andThen:(void (^)(NSError *error, NSString *bbcode))callback;
// List post icons usable for private messages.
//
// callback - A block to call after listing post icons, which takes as parameters:
// error - An error on failure, or nil on success.
// postIcons - A dictionary mapping icon IDs to URLs on success, or nil on failure.
// postIconIDs - An ordered list of icon IDs on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)listAvailablePrivateMessagePostIconsAndThen:(void (^)(NSError *error, NSDictionary *postIcons, NSArray *postIconIDs))callback;
// Send a private message.
//
// username - The user who will receive the message.
// subject - The subject of the message.
// iconID - The ID of the post icon to use, or nil for no icon.
// text - The BBCode text of the message.
// replyMessageID - The message ID of the message this is regarding, or nil if not a reply.
// forwardMessageID - The message ID of the message this is a forward of, or nil of not a forward.
// callback - A block to call after sending the message, which takes as parameters:
// error - An error on failure, or nil on success.
// message - The sent message on success, or nil on failure.
//
// Returns the enqueued network operation.
- (NSOperation *)sendPrivateMessageTo:(NSString *)username
subject:(NSString *)subject
icon:(NSString *)iconID
text:(NSString *)text
asReplyToMessageWithID:(NSString *)replyMessageID
forwardedFromMessageWithID:(NSString *)forwardMessageID
andThen:(void (^)(NSError *error,
AwfulPrivateMessage *message))callback;
@end