Skip to content

Commit d149306

Browse files
authored
Isolate API version enum and convert to modern Objective-C (#778)
2 parents 966b6e5 + ee3d90b commit d149306

25 files changed

+151
-165
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ _None._
3434

3535
### Breaking Changes
3636

37-
_None._
37+
- Removed `anonymousWordPressComRestApiWithUserAgent` method from `ServiceRemoteWordPressComREST` [#778]
38+
- Renamed `ServiceRemoteWordPressComRESTApiVersion` to `WordPressComRestAPIVersion` [#778]
3839

3940
### New Features
4041

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#import <Foundation/Foundation.h>
2+
3+
typedef NS_ENUM(NSInteger, WordPressComRESTAPIVersion) {
4+
WordPressComRESTAPIVersion_1_0 = 1000,
5+
WordPressComRESTAPIVersion_1_1 = 1001,
6+
WordPressComRESTAPIVersion_1_2 = 1002,
7+
WordPressComRESTAPIVersion_1_3 = 1003,
8+
WordPressComRESTAPIVersion_2_0 = 2000
9+
};

Sources/WordPressKit/Services/AccountServiceRemoteREST.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ - (void)getAccountDetailsWithSuccess:(void (^)(RemoteUser *remoteUser))success
5454
failure:(void (^)(NSError *error))failure
5555
{
5656
NSString *requestUrl = [self pathForEndpoint:@"me"
57-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
57+
withVersion:WordPressComRESTAPIVersion_1_1];
5858

5959
[self.wordPressComRESTAPI get:requestUrl
6060
parameters:nil
@@ -107,7 +107,7 @@ - (void)updateBlogsVisibility:(NSDictionary *)blogs
107107
@"sites": sites
108108
};
109109
NSString *path = [self pathForEndpoint:@"me/sites"
110-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
110+
withVersion:WordPressComRESTAPIVersion_1_1];
111111
[self.wordPressComRESTAPI post:path
112112
parameters:parameters
113113
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
@@ -126,7 +126,7 @@ - (void)isPasswordlessAccount:(NSString *)identifier success:(void (^)(BOOL pass
126126
NSString *encodedIdentifier = [identifier stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathRFC3986AllowedCharacterSet];
127127

128128
NSString *path = [self pathForEndpoint:[NSString stringWithFormat:@"users/%@/auth-options", encodedIdentifier]
129-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
129+
withVersion:WordPressComRESTAPIVersion_1_1];
130130
[self.wordPressComRESTAPI get:path
131131
parameters:nil
132132
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
@@ -249,7 +249,7 @@ - (void)requestWPComAuthLinkForEmail:(NSString *)email
249249
failure:(void (^)(NSError *error))failure
250250
{
251251
NSString *path = [self pathForEndpoint:@"auth/send-login-email"
252-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_3];
252+
withVersion:WordPressComRESTAPIVersion_1_3];
253253

254254
NSDictionary *extraParams = @{
255255
MagicLinkParameterFlow: MagicLinkFlowLogin,
@@ -275,7 +275,7 @@ - (void)requestWPComSignupLinkForEmail:(NSString *)email
275275
{
276276

277277
NSString *path = [self pathForEndpoint:@"auth/send-signup-email"
278-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
278+
withVersion:WordPressComRESTAPIVersion_1_1];
279279

280280
NSDictionary *extraParams = @{
281281
@"signup_flow_name": @"mobile-ios",
@@ -334,7 +334,7 @@ - (void)requestVerificationEmailWithSucccess:(void (^)(void))success
334334
failure:(void (^)(NSError *))failure
335335
{
336336
NSString *path = [self pathForEndpoint:@"me/send-verification-email"
337-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
337+
withVersion:WordPressComRESTAPIVersion_1_1];
338338

339339
[self.wordPressComRESTAPI post:path parameters:nil success:^(id _Nonnull responseObject, NSHTTPURLResponse * _Nullable httpResponse) {
340340
if (success) {
@@ -354,7 +354,7 @@ - (void)getBlogsWithParameters:(NSDictionary *)parameters
354354
failure:(void (^)(NSError *))failure
355355
{
356356
NSString *requestUrl = [self pathForEndpoint:@"me/sites"
357-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_2];
357+
withVersion:WordPressComRESTAPIVersion_1_2];
358358
[self.wordPressComRESTAPI get:requestUrl
359359
parameters:parameters
360360
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {

Sources/WordPressKit/Services/BlogServiceRemoteREST.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers
104104

105105
NSString *path = [self pathForUsers];
106106
NSString *requestUrl = [self pathForEndpoint:path
107-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
107+
withVersion:WordPressComRESTAPIVersion_1_1];
108108

109109
[self.wordPressComRESTAPI get:requestUrl
110110
parameters:parameters
@@ -136,7 +136,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success
136136
{
137137
NSString *path = [self pathForPostTypes];
138138
NSString *requestUrl = [self pathForEndpoint:path
139-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
139+
withVersion:WordPressComRESTAPIVersion_1_1];
140140
NSDictionary *parameters = @{@"context": @"edit"};
141141
[self.wordPressComRESTAPI get:requestUrl
142142
parameters:parameters
@@ -166,7 +166,7 @@ - (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success
166166
{
167167
NSString *path = [self pathForPostFormats];
168168
NSString *requestUrl = [self pathForEndpoint:path
169-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
169+
withVersion:WordPressComRESTAPIVersion_1_1];
170170

171171
[self.wordPressComRESTAPI get:requestUrl
172172
parameters:nil
@@ -187,7 +187,7 @@ - (void)syncBlogWithSuccess:(BlogDetailsHandler)success
187187
{
188188
NSString *path = [self pathForSite];
189189
NSString *requestUrl = [self pathForEndpoint:path
190-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
190+
withVersion:WordPressComRESTAPIVersion_1_1];
191191

192192
[self.wordPressComRESTAPI get:requestUrl
193193
parameters:nil
@@ -208,7 +208,7 @@ - (void)syncBlogSettingsWithSuccess:(SettingsHandler)success
208208
failure:(void (^)(NSError *error))failure
209209
{
210210
NSString *path = [self pathForSettings];
211-
NSString *requestUrl = [self pathForEndpoint:path withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
211+
NSString *requestUrl = [self pathForEndpoint:path withVersion:WordPressComRESTAPIVersion_1_1];
212212

213213
[self.wordPressComRESTAPI get:requestUrl
214214
parameters:nil
@@ -238,7 +238,7 @@ - (void)updateBlogSettings:(RemoteBlogSettings *)settings
238238

239239
NSDictionary *parameters = [self remoteSettingsToDictionary:settings];
240240
NSString *path = [NSString stringWithFormat:@"sites/%@/settings?context=edit", self.siteID];
241-
NSString *requestUrl = [self pathForEndpoint:path withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
241+
NSString *requestUrl = [self pathForEndpoint:path withVersion:WordPressComRESTAPIVersion_1_1];
242242

243243
[self.wordPressComRESTAPI post:requestUrl
244244
parameters:parameters
@@ -270,7 +270,7 @@ - (void)fetchSiteInfoForAddress:(NSString *)siteAddress
270270
{
271271
NSString *path = [NSString stringWithFormat:@"sites/%@", siteAddress];
272272
NSString *requestUrl = [self pathForEndpoint:path
273-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
273+
withVersion:WordPressComRESTAPIVersion_1_1];
274274

275275
[self.wordPressComRESTAPI get:requestUrl
276276
parameters:nil
@@ -290,7 +290,7 @@ - (void)fetchUnauthenticatedSiteInfoForAddress:(NSString *)siteAddress
290290
success:(void(^)(NSDictionary *siteInfoDict))success
291291
failure:(void (^)(NSError *error))failure
292292
{
293-
NSString *path = [self pathForEndpoint:@"connect/site-info" withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
293+
NSString *path = [self pathForEndpoint:@"connect/site-info" withVersion:WordPressComRESTAPIVersion_1_1];
294294
NSURL *siteURL = [NSURL URLWithString:siteAddress];
295295

296296
[self.wordPressComRESTAPI get:path

Sources/WordPressKit/Services/CommentServiceRemoteREST.m

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ - (void)getCommentsWithMaximumCount:(NSInteger)maximumComments
2626
{
2727
NSString *path = [NSString stringWithFormat:@"sites/%@/comments", self.siteID];
2828
NSString *requestUrl = [self pathForEndpoint:path
29-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
29+
withVersion:WordPressComRESTAPIVersion_1_1];
3030

3131
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{
3232
@"force": @"wpcom", // Force fetching data from shadow site on Jetpack sites
@@ -82,7 +82,7 @@ - (void)getCommentWithID:(NSNumber *)commentID
8282
{
8383
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, commentID];
8484
NSString *requestUrl = [self pathForEndpoint:path
85-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
85+
withVersion:WordPressComRESTAPIVersion_1_1];
8686

8787
[self.wordPressComRESTAPI get:requestUrl
8888
parameters:nil
@@ -110,7 +110,7 @@ - (void)createComment:(RemoteComment *)comment
110110
}
111111

112112
NSString *requestUrl = [self pathForEndpoint:path
113-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
113+
withVersion:WordPressComRESTAPIVersion_1_1];
114114

115115
NSDictionary *parameters = @{
116116
@"content": comment.content,
@@ -137,7 +137,7 @@ - (void)updateComment:(RemoteComment *)comment
137137
{
138138
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, comment.commentID];
139139
NSString *requestUrl = [self pathForEndpoint:path
140-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
140+
withVersion:WordPressComRESTAPIVersion_1_1];
141141

142142
NSDictionary *parameters = @{
143143
@"content": comment.content,
@@ -168,7 +168,7 @@ - (void)moderateComment:(RemoteComment *)comment
168168
{
169169
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, comment.commentID];
170170
NSString *requestUrl = [self pathForEndpoint:path
171-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
171+
withVersion:WordPressComRESTAPIVersion_1_1];
172172

173173
NSDictionary *parameters = @{
174174
@"status": [self remoteStatusWithStatus:comment.status],
@@ -195,7 +195,7 @@ - (void)trashComment:(RemoteComment *)comment
195195
{
196196
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/delete", self.siteID, comment.commentID];
197197
NSString *requestUrl = [self pathForEndpoint:path
198-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
198+
withVersion:WordPressComRESTAPIVersion_1_1];
199199

200200
[self.wordPressComRESTAPI post:requestUrl
201201
parameters:nil
@@ -221,7 +221,7 @@ - (void)syncHierarchicalCommentsForPost:(NSNumber *)postID
221221
{
222222
NSString *path = [NSString stringWithFormat:@"sites/%@/posts/%@/replies?order=ASC&hierarchical=1&page=%lu&number=%lu", self.siteID, postID, (unsigned long)page, (unsigned long)number];
223223
NSString *requestUrl = [self pathForEndpoint:path
224-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
224+
withVersion:WordPressComRESTAPIVersion_1_1];
225225

226226
NSDictionary *parameters = @{
227227
@"force": @"wpcom" // Force fetching data from shadow site on Jetpack sites
@@ -252,7 +252,7 @@ - (void)updateCommentWithID:(NSNumber *)commentID
252252
{
253253
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, commentID];
254254
NSString *requestUrl = [self pathForEndpoint:path
255-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
255+
withVersion:WordPressComRESTAPIVersion_1_1];
256256

257257
NSDictionary *parameters = @{
258258
@"content": content,
@@ -278,7 +278,7 @@ - (void)replyToPostWithID:(NSNumber *)postID
278278
{
279279
NSString *path = [NSString stringWithFormat:@"sites/%@/posts/%@/replies/new", self.siteID, postID];
280280
NSString *requestUrl = [self pathForEndpoint:path
281-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
281+
withVersion:WordPressComRESTAPIVersion_1_1];
282282

283283
NSDictionary *parameters = @{@"content": content};
284284

@@ -304,7 +304,7 @@ - (void)replyToCommentWithID:(NSNumber *)commentID
304304
{
305305
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/replies/new", self.siteID, commentID];
306306
NSString *requestUrl = [self pathForEndpoint:path
307-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
307+
withVersion:WordPressComRESTAPIVersion_1_1];
308308

309309
NSDictionary *parameters = @{
310310
@"content": content,
@@ -332,7 +332,7 @@ - (void)moderateCommentWithID:(NSNumber *)commentID
332332
{
333333
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, commentID];
334334
NSString *requestUrl = [self pathForEndpoint:path
335-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
335+
withVersion:WordPressComRESTAPIVersion_1_1];
336336

337337
NSDictionary *parameters = @{
338338
@"status" : status,
@@ -358,7 +358,7 @@ - (void)trashCommentWithID:(NSNumber *)commentID
358358
{
359359
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/delete", self.siteID, commentID];
360360
NSString *requestUrl = [self pathForEndpoint:path
361-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
361+
withVersion:WordPressComRESTAPIVersion_1_1];
362362

363363
[self.wordPressComRESTAPI post:requestUrl
364364
parameters:nil
@@ -379,7 +379,7 @@ - (void)likeCommentWithID:(NSNumber *)commentID
379379
{
380380
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/likes/new", self.siteID, commentID];
381381
NSString *requestUrl = [self pathForEndpoint:path
382-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
382+
withVersion:WordPressComRESTAPIVersion_1_1];
383383

384384
[self.wordPressComRESTAPI post:requestUrl
385385
parameters:nil
@@ -400,7 +400,7 @@ - (void)unlikeCommentWithID:(NSNumber *)commentID
400400
{
401401
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/likes/mine/delete", self.siteID, commentID];
402402
NSString *requestUrl = [self pathForEndpoint:path
403-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
403+
withVersion:WordPressComRESTAPIVersion_1_1];
404404

405405
[self.wordPressComRESTAPI post:requestUrl
406406
parameters:nil
@@ -426,7 +426,7 @@ - (void)getLikesForCommentID:(NSNumber *)commentID
426426

427427
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/likes", self.siteID, commentID];
428428
NSString *requestUrl = [self pathForEndpoint:path
429-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_2];
429+
withVersion:WordPressComRESTAPIVersion_1_2];
430430
NSNumber *siteID = self.siteID;
431431

432432
// If no count provided, default to endpoint max.

Sources/WordPressKit/Services/MediaServiceRemoteREST.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ - (void)getMediaWithID:(NSNumber *)mediaID
1414
{
1515
NSString *apiPath = [NSString stringWithFormat:@"sites/%@/media/%@", self.siteID, mediaID];
1616
NSString *requestUrl = [self pathForEndpoint:apiPath
17-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
17+
withVersion:WordPressComRESTAPIVersion_1_1];
1818

1919
NSDictionary * parameters = @{};
2020

@@ -58,7 +58,7 @@ - (void)getMediaLibraryPage:(NSString *)pageHandle
5858
}
5959

6060
NSString *requestUrl = [self pathForEndpoint:path
61-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
61+
withVersion:WordPressComRESTAPIVersion_1_1];
6262

6363
[self.wordPressComRESTAPI get:requestUrl
6464
parameters:[NSDictionary dictionaryWithDictionary:parameters]
@@ -97,7 +97,7 @@ - (void)getMediaLibraryCountForType:(NSString *)mediaType
9797
{
9898
NSString *path = [NSString stringWithFormat:@"sites/%@/media", self.siteID];
9999
NSString *requestUrl = [self pathForEndpoint:path
100-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
100+
withVersion:WordPressComRESTAPIVersion_1_1];
101101

102102
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{ @"number" : @1 }];
103103
if (mediaType) {
@@ -129,7 +129,7 @@ - (void)uploadMedia:(NSArray *)mediaItems
129129

130130
NSString *apiPath = [NSString stringWithFormat:@"sites/%@/media/new", self.siteID];
131131
NSString *requestUrl = [self pathForEndpoint:apiPath
132-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
132+
withVersion:WordPressComRESTAPIVersion_1_1];
133133
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithDictionary:@{}];
134134
NSMutableArray *fileParts = [NSMutableArray array];
135135

@@ -190,7 +190,7 @@ - (void)uploadMedia:(RemoteMedia *)media
190190

191191
NSString *apiPath = [NSString stringWithFormat:@"sites/%@/media/new", self.siteID];
192192
NSString *requestUrl = [self pathForEndpoint:apiPath
193-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
193+
withVersion:WordPressComRESTAPIVersion_1_1];
194194

195195
NSDictionary *parameters = [self parametersForUploadMedia:media];
196196

@@ -257,7 +257,7 @@ - (void)updateMedia:(RemoteMedia *)media
257257

258258
NSString *path = [NSString stringWithFormat:@"sites/%@/media/%@", self.siteID, media.mediaID];
259259
NSString *requestUrl = [self pathForEndpoint:path
260-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
260+
withVersion:WordPressComRESTAPIVersion_1_1];
261261

262262
NSDictionary *parameters = [self parametersFromRemoteMedia:media];
263263

@@ -283,7 +283,7 @@ - (void)deleteMedia:(RemoteMedia *)media
283283

284284
NSString *path = [NSString stringWithFormat:@"sites/%@/media/%@/delete", self.siteID, media.mediaID];
285285
NSString *requestUrl = [self pathForEndpoint:path
286-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
286+
withVersion:WordPressComRESTAPIVersion_1_1];
287287

288288
[self.wordPressComRESTAPI post:requestUrl
289289
parameters:nil
@@ -316,7 +316,7 @@ -(void)getMetadataFromVideoPressID:(NSString *)videoPressID
316316
{
317317
NSString *path = [NSString stringWithFormat:@"videos/%@", videoPressID];
318318
NSString *requestUrl = [self pathForEndpoint:path
319-
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
319+
withVersion:WordPressComRESTAPIVersion_1_1];
320320

321321
[self.wordPressComRESTAPI get:requestUrl
322322
parameters:nil
@@ -356,7 +356,7 @@ -(void)getVideoPressToken:(NSString *)videoPressID
356356

357357
NSString *path = [NSString stringWithFormat:@"sites/%@/media/videopress-playback-jwt/%@", self.siteID, videoPressID];
358358
NSString *requestUrl = [self pathForEndpoint:path
359-
withVersion:ServiceRemoteWordPressComRESTApiVersion_2_0];
359+
withVersion:WordPressComRESTAPIVersion_2_0];
360360

361361
[self.wordPressComRESTAPI post:requestUrl
362362
parameters:nil

0 commit comments

Comments
 (0)