commit | author | age
|
655e66
|
1 |
/* |
H |
2 |
* Copyright (C) 2017 Twitter, Inc. |
|
3 |
* |
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 |
* you may not use this file except in compliance with the License. |
|
6 |
* You may obtain a copy of the License at |
|
7 |
* |
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
9 |
* |
|
10 |
* Unless required by applicable law or agreed to in writing, software |
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 |
* See the License for the specific language governing permissions and |
|
14 |
* limitations under the License. |
|
15 |
* |
|
16 |
*/ |
a0a843
|
17 |
|
7be7ad
|
18 |
#import <UIKit/UIKit.h> |
H |
19 |
|
a0a843
|
20 |
@class TWTRUser; |
H |
21 |
@class TWTRTweet; |
|
22 |
@class TWTRAuthConfig; |
|
23 |
@class TWTRGuestSession; |
|
24 |
@protocol TWTRAuthSession; |
|
25 |
@protocol TWTRSessionStore; |
|
26 |
|
|
27 |
NS_ASSUME_NONNULL_BEGIN |
|
28 |
|
655e66
|
29 |
FOUNDATION_EXTERN NSString *const TWTRTweetsNotLoadedKey; |
a0a843
|
30 |
|
H |
31 |
/** |
|
32 |
* @name Completion Block Types |
|
33 |
*/ |
|
34 |
|
|
35 |
/** |
|
36 |
* Completion block called when the load user request succeeds or fails. |
|
37 |
* |
|
38 |
* @param user The Twitter User. |
|
39 |
* @param error Error that will be set if the API request failed. |
|
40 |
*/ |
|
41 |
typedef void (^TWTRLoadUserCompletion)(TWTRUser *_Nullable user, NSError *_Nullable error); |
|
42 |
|
|
43 |
/** |
|
44 |
* Completion block called when the load Tweet request succeeds or fails. |
|
45 |
* |
|
46 |
* @param tweet The Twitter Tweet. |
|
47 |
* @param error Error that will be set if the API request failed. |
|
48 |
*/ |
|
49 |
typedef void (^TWTRLoadTweetCompletion)(TWTRTweet *_Nullable tweet, NSError *_Nullable error); |
|
50 |
|
|
51 |
/** |
|
52 |
* Completion block called when the load Tweets request succeeds or fails. |
|
53 |
* |
|
54 |
* @param tweets Tweets that were successfully retrieved. |
|
55 |
* @param error Error that will be set if the API request failed. |
|
56 |
*/ |
|
57 |
typedef void (^TWTRLoadTweetsCompletion)(NSArray<TWTRTweet *> *_Nullable tweets, NSError *_Nullable error); |
|
58 |
|
|
59 |
/** |
|
60 |
* Completion block called when the network request succeeds or fails. |
|
61 |
* |
|
62 |
* @param response Metadata associated with the response to a URL load request. |
|
63 |
* @param data Content data of the response. |
|
64 |
* @param connectionError Error object describing the network error that occurred. |
|
65 |
*/ |
|
66 |
typedef void (^TWTRNetworkCompletion)(NSURLResponse *_Nullable response, NSData *_Nullable data, NSError *_Nullable connectionError); |
|
67 |
|
|
68 |
/** |
|
69 |
* Completion block called when a JSON request to the Twitter API succeeds or fails. |
|
70 |
* |
|
71 |
* @param response Metadata associated with the response to a URL load request. |
|
72 |
* @param responseObject Content data of the response. |
|
73 |
* @param error Error object describing the network error that occurred. |
|
74 |
*/ |
|
75 |
typedef void (^TWTRJSONRequestCompletion)(NSURLResponse *_Nullable response, id _Nullable responseObject, NSError *_Nullable error); |
|
76 |
|
|
77 |
/** |
|
78 |
* Completion block called when a Tweet action (favorite/retweet) is performed. |
|
79 |
* |
|
80 |
* @param tweet The Tweet object representing the new state of this Tweet from |
|
81 |
* the perspective of the currently-logged in user. |
|
82 |
* @param error Error object describing the error that occurred. This will be either a |
|
83 |
* network error or an NSError with an errorCode corresponding to |
|
84 |
* TWTRAPIErrorCodeAlreadyFavorited or TWTRAPIErrorCodeAlreadyRetweeted |
|
85 |
* for an attempted action that has already been taken from the servers |
|
86 |
* point of view for this logged-in user. |
|
87 |
*/ |
|
88 |
typedef void (^TWTRTweetActionCompletion)(TWTRTweet *_Nullable tweet, NSError *_Nullable error); |
|
89 |
|
|
90 |
/** |
|
91 |
* Completion block called when a media upload request to the Twitter API succeeds or fails. |
|
92 |
* |
|
93 |
* @param mediaID The media ID of the object that was uploaded which can be used when tweeting. |
|
94 |
* @param error Error object describing the network error that occurred. |
|
95 |
*/ |
|
96 |
typedef void (^TWTRMediaUploadResponseCompletion)(NSString *_Nullable mediaID, NSError *_Nullable error); |
|
97 |
|
|
98 |
/** |
|
99 |
* Completion block called when the send Tweet request succeeds or fails. |
|
100 |
* |
|
101 |
* @param tweet The Twitter Tweet created. |
|
102 |
* @param error Error that will be set if the API request failed. |
|
103 |
*/ |
|
104 |
typedef void (^TWTRSendTweetCompletion)(TWTRTweet *_Nullable tweet, NSError *_Nullable error); |
|
105 |
|
|
106 |
/** |
|
107 |
* Completion block called when a request for the user's email succeeds or fails. |
|
108 |
* |
|
109 |
* @param email The email of the user |
|
110 |
* @param error Error object describing the error that occurred. |
|
111 |
*/ |
|
112 |
typedef void (^TWTRRequestEmailCompletion)(NSString *_Nullable email, NSError *_Nullable error); |
|
113 |
|
|
114 |
/** |
|
115 |
* Client for consuming the Twitter REST API. Provides methods for common API requests, as well as the ability to create and send custom requests. |
|
116 |
*/ |
|
117 |
@interface TWTRAPIClient : NSObject |
|
118 |
|
|
119 |
/** |
|
120 |
* The Twitter user ID this client is making API requests on behalf of or |
|
121 |
* nil if it is a guest user. |
|
122 |
*/ |
|
123 |
@property (nonatomic, copy, readonly, nullable) NSString *userID; |
|
124 |
|
|
125 |
/** |
|
126 |
* Constructs a `TWTRAPIClient` object to perform authenticated API requests with user authentication. |
|
127 |
* |
|
128 |
* @param userID (optional) ID of the user to make requests on behalf of. If the ID is nil requests will be made using guest authentication. |
|
129 |
* |
|
130 |
* @return Fully initialized API client to make authenticated requests against the Twitter REST API. |
|
131 |
*/ |
|
132 |
- (instancetype)initWithUserID:(nullable NSString *)userID; |
|
133 |
|
|
134 |
/** |
|
135 |
* Constructs a `TWTRAPIClient` with the last logged-in user. If no user has been |
|
136 |
* logged in yet this falls back to Guest authentication. |
|
137 |
* |
|
138 |
* @return Fully initialized API client to make Guest or User authenticated requests to the Twitter REST API. |
|
139 |
*/ |
|
140 |
+ (instancetype)clientWithCurrentUser; |
|
141 |
|
|
142 |
/** |
|
143 |
* @name Making Requests |
|
144 |
*/ |
|
145 |
|
|
146 |
/** |
|
147 |
* Returns a signed URL request. |
|
148 |
* |
|
149 |
* @param method Request method, GET, POST, PUT, DELETE, etc. |
|
150 |
* @param URLString Request URL. This is the full Twitter API URL. E.g. https://api.twitter.com/1.1/statuses/user_timeline.json |
|
151 |
* @param parameters Request parameters. |
|
152 |
* @param error Error that will be set if there was an error signing the request. |
|
153 |
* |
|
154 |
* @note If the request is not sent with the -[TWTRAPIClient sendTwitterRequest:completion:] method it is the developers responsibility to ensure that there is a valid guest session before this method is called. |
|
155 |
*/ |
655e66
|
156 |
- (NSURLRequest *)URLRequestWithMethod:(NSString *)method URLString:(NSString *)URLString parameters:(nullable NSDictionary *)parameters error:(NSError **)error; |
a0a843
|
157 |
|
H |
158 |
/** |
|
159 |
* Sends a Twitter request. |
|
160 |
* |
|
161 |
* @param request The request that will be sent asynchronously. |
|
162 |
* @param completion Completion block to be called on response. Called on main queue. |
|
163 |
* @return an NSProgress object which can be used to cancel the request. |
|
164 |
*/ |
|
165 |
- (NSProgress *)sendTwitterRequest:(NSURLRequest *)request completion:(TWTRNetworkCompletion)completion; |
|
166 |
|
|
167 |
/** |
|
168 |
* @name Common API Actions |
|
169 |
*/ |
|
170 |
|
|
171 |
/** |
|
172 |
* Loads a Twitter User. |
|
173 |
* |
|
174 |
* @param userID (required) The Twitter user ID of the desired user. |
|
175 |
* @param completion Completion block to be called on response. Called on main queue. |
|
176 |
*/ |
|
177 |
- (void)loadUserWithID:(NSString *)userID completion:(TWTRLoadUserCompletion)completion; |
|
178 |
|
|
179 |
/** |
|
180 |
* Loads a single Tweet from the network or cache. |
|
181 |
* |
|
182 |
* @param tweetID (required) The ID of the desired Tweet. |
|
183 |
* @param completion Completion bock to be called on response. Called on main queue. |
|
184 |
*/ |
|
185 |
- (void)loadTweetWithID:(NSString *)tweetID completion:(TWTRLoadTweetCompletion)completion; |
|
186 |
|
|
187 |
/** |
|
188 |
* Loads a series of Tweets in a batch. The completion block will be passed an array of zero or more |
|
189 |
* Tweets that loaded successfully. If some Tweets fail to load the array will contain less Tweets than |
|
190 |
* number of requested IDs. If any Tweets fail to load, the IDs of the Tweets that did not load will |
|
191 |
* be provided in the userInfo dictionary property of the error parameter under `TWTRTweetsNotLoadedKey`. |
|
192 |
* |
|
193 |
* @param tweetIDStrings (required) An array of Tweet IDs. |
|
194 |
* @param completion Completion block to be called on response. Called on main queue. |
|
195 |
*/ |
|
196 |
- (void)loadTweetsWithIDs:(NSArray *)tweetIDStrings completion:(TWTRLoadTweetsCompletion)completion; |
|
197 |
|
|
198 |
/** |
|
199 |
* Uploads media to the media server. Returns a media ID to be used when tweeting. |
|
200 |
* |
|
201 |
* @param media The media to upload |
|
202 |
* @param contentType The HTTP content type of the media that you are uploading. |
|
203 |
* @param completion The completion handler to invoke. |
|
204 |
*/ |
|
205 |
- (void)uploadMedia:(NSData *)media contentType:(NSString *)contentType completion:(TWTRMediaUploadResponseCompletion)completion; |
|
206 |
|
|
207 |
/** |
|
208 |
* Create and send a Tweet. |
|
209 |
* |
|
210 |
* @param tweetText (required) The text for a Tweet |
|
211 |
* @param completion Completion block to be called on response. Called on main queue. |
|
212 |
*/ |
|
213 |
- (void)sendTweetWithText:(NSString *)tweetText completion:(TWTRSendTweetCompletion)completion; |
|
214 |
|
|
215 |
/** |
|
216 |
* Upload media and create a Tweet. Returns TWTRTweet to be used when debugging. |
|
217 |
* |
|
218 |
* @param tweetText The text for a Tweet |
|
219 |
* @param image UIImage to upload |
|
220 |
* @param completion The completion handler to invoke. |
|
221 |
*/ |
|
222 |
- (void)sendTweetWithText:(NSString *)tweetText image:(UIImage *)image completion:(TWTRSendTweetCompletion)completion; |
|
223 |
|
|
224 |
/** |
|
225 |
* Create a Tweet with a video. Returns TWTRTweet to be used when debugging. |
|
226 |
* |
|
227 |
* Note: there are several requirements of the video being uploaded: |
|
228 |
* - Duration should be between 0.5 seconds and 30 seconds |
|
229 |
* - File size should not exceed 15 mb |
|
230 |
* - Dimensions should be between 32x32 and 1280x1024 |
|
231 |
* - Aspect ratio should be between 1:3 and 3:1 |
|
232 |
* - Frame rate should be 40fps or less |
|
233 |
* |
|
234 |
* @param tweetText The text for a Tweet |
|
235 |
* @param videoData The video to be uploaded. Please follow guideline https://dev.twitter.com/rest/media/uploading-media |
|
236 |
* @param completion The completion handler to invoke. |
|
237 |
*/ |
|
238 |
- (void)sendTweetWithText:(NSString *)tweetText videoData:(NSData *)videoData completion:(TWTRSendTweetCompletion)completion; |
|
239 |
|
|
240 |
/** |
|
241 |
* Requests the email for the user id which the API client was instantiated with. |
|
242 |
* This method requires that you are using an API Client which was instantiated with |
|
243 |
* a logged in user otherwise you will receive a "Request failed: forbidden (403)" error. |
|
244 |
* |
|
245 |
* @param completion A completion block to invoke when the request completes. The email address may |
|
246 |
* be a nil if the user does not have an email address, the email address |
|
247 |
* is unverified or you do not have the correct permissions to request the email address. |
|
248 |
* |
|
249 |
* @note Requesting a user’s email address requires your application to be whitelisted by Twitter. |
655e66
|
250 |
* To request access, please visit the "Permissions" section for your app at https://apps.twitter.com/ |
a0a843
|
251 |
*/ |
H |
252 |
- (void)requestEmailForCurrentUser:(TWTRRequestEmailCompletion)completion; |
|
253 |
|
|
254 |
@end |
|
255 |
|
|
256 |
NS_ASSUME_NONNULL_END |