Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM Prep - Isolate API version enum and convert to modern Objective-C #778

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ _None._

### Breaking Changes

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

### New Features

Expand Down
9 changes: 9 additions & 0 deletions Sources/APIInterface/include/WordPressComRESTAPIVersion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, WordPressComRESTAPIVersion) {
WordPressComRESTAPIVersion_1_0 = 1000,
WordPressComRESTAPIVersion_1_1 = 1001,
WordPressComRESTAPIVersion_1_2 = 1002,
WordPressComRESTAPIVersion_1_3 = 1003,
WordPressComRESTAPIVersion_2_0 = 2000
};
14 changes: 7 additions & 7 deletions Sources/WordPressKit/Services/AccountServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ - (void)getAccountDetailsWithSuccess:(void (^)(RemoteUser *remoteUser))success
failure:(void (^)(NSError *error))failure
{
NSString *requestUrl = [self pathForEndpoint:@"me"
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
Expand Down Expand Up @@ -107,7 +107,7 @@ - (void)updateBlogsVisibility:(NSDictionary *)blogs
@"sites": sites
};
NSString *path = [self pathForEndpoint:@"me/sites"
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];
[self.wordPressComRESTAPI post:path
parameters:parameters
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand All @@ -126,7 +126,7 @@ - (void)isPasswordlessAccount:(NSString *)identifier success:(void (^)(BOOL pass
NSString *encodedIdentifier = [identifier stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLPathRFC3986AllowedCharacterSet];

NSString *path = [self pathForEndpoint:[NSString stringWithFormat:@"users/%@/auth-options", encodedIdentifier]
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];
[self.wordPressComRESTAPI get:path
parameters:nil
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand Down Expand Up @@ -249,7 +249,7 @@ - (void)requestWPComAuthLinkForEmail:(NSString *)email
failure:(void (^)(NSError *error))failure
{
NSString *path = [self pathForEndpoint:@"auth/send-login-email"
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_3];
withVersion:WordPressComRESTAPIVersion_1_3];

NSDictionary *extraParams = @{
MagicLinkParameterFlow: MagicLinkFlowLogin,
Expand All @@ -275,7 +275,7 @@ - (void)requestWPComSignupLinkForEmail:(NSString *)email
{

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

NSDictionary *extraParams = @{
@"signup_flow_name": @"mobile-ios",
Expand Down Expand Up @@ -334,7 +334,7 @@ - (void)requestVerificationEmailWithSucccess:(void (^)(void))success
failure:(void (^)(NSError *))failure
{
NSString *path = [self pathForEndpoint:@"me/send-verification-email"
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI post:path parameters:nil success:^(id _Nonnull responseObject, NSHTTPURLResponse * _Nullable httpResponse) {
if (success) {
Expand All @@ -354,7 +354,7 @@ - (void)getBlogsWithParameters:(NSDictionary *)parameters
failure:(void (^)(NSError *))failure
{
NSString *requestUrl = [self pathForEndpoint:@"me/sites"
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_2];
withVersion:WordPressComRESTAPIVersion_1_2];
[self.wordPressComRESTAPI get:requestUrl
parameters:parameters
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
Expand Down
16 changes: 8 additions & 8 deletions Sources/WordPressKit/Services/BlogServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ - (void)getAllAuthorsWithRemoteUsers:(NSMutableArray <RemoteUser *>*)remoteUsers

NSString *path = [self pathForUsers];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:parameters
Expand Down Expand Up @@ -136,7 +136,7 @@ - (void)syncPostTypesWithSuccess:(PostTypesHandler)success
{
NSString *path = [self pathForPostTypes];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];
NSDictionary *parameters = @{@"context": @"edit"};
[self.wordPressComRESTAPI get:requestUrl
parameters:parameters
Expand Down Expand Up @@ -166,7 +166,7 @@ - (void)syncPostFormatsWithSuccess:(PostFormatsHandler)success
{
NSString *path = [self pathForPostFormats];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
Expand All @@ -187,7 +187,7 @@ - (void)syncBlogWithSuccess:(BlogDetailsHandler)success
{
NSString *path = [self pathForSite];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
Expand Down Expand Up @@ -238,7 +238,7 @@ - (void)updateBlogSettings:(RemoteBlogSettings *)settings

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

[self.wordPressComRESTAPI post:requestUrl
parameters:parameters
Expand Down Expand Up @@ -270,7 +270,7 @@ - (void)fetchSiteInfoForAddress:(NSString *)siteAddress
{
NSString *path = [NSString stringWithFormat:@"sites/%@", siteAddress];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

[self.wordPressComRESTAPI get:path
Expand Down
30 changes: 15 additions & 15 deletions Sources/WordPressKit/Services/CommentServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (void)getCommentsWithMaximumCount:(NSInteger)maximumComments
{
NSString *path = [NSString stringWithFormat:@"sites/%@/comments", self.siteID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
Expand Down Expand Up @@ -110,7 +110,7 @@ - (void)createComment:(RemoteComment *)comment
}

NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

NSDictionary *parameters = @{
@"content": comment.content,
Expand Down Expand Up @@ -168,7 +168,7 @@ - (void)moderateComment:(RemoteComment *)comment
{
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, comment.commentID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

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

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

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

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

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

NSDictionary *parameters = @{
@"content": content,
Expand Down Expand Up @@ -332,7 +332,7 @@ - (void)moderateCommentWithID:(NSNumber *)commentID
{
NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, commentID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

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

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

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

NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@/likes", self.siteID, commentID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_2];
withVersion:WordPressComRESTAPIVersion_1_2];
NSNumber *siteID = self.siteID;

// If no count provided, default to endpoint max.
Expand Down
18 changes: 9 additions & 9 deletions Sources/WordPressKit/Services/MediaServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ - (void)getMediaWithID:(NSNumber *)mediaID
{
NSString *apiPath = [NSString stringWithFormat:@"sites/%@/media/%@", self.siteID, mediaID];
NSString *requestUrl = [self pathForEndpoint:apiPath
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

NSDictionary * parameters = @{};

Expand Down Expand Up @@ -58,7 +58,7 @@ - (void)getMediaLibraryPage:(NSString *)pageHandle
}

NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:[NSDictionary dictionaryWithDictionary:parameters]
Expand Down Expand Up @@ -97,7 +97,7 @@ - (void)getMediaLibraryCountForType:(NSString *)mediaType
{
NSString *path = [NSString stringWithFormat:@"sites/%@/media", self.siteID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

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

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

Expand Down Expand Up @@ -190,7 +190,7 @@ - (void)uploadMedia:(RemoteMedia *)media

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

NSDictionary *parameters = [self parametersForUploadMedia:media];

Expand Down Expand Up @@ -257,7 +257,7 @@ - (void)updateMedia:(RemoteMedia *)media

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

NSDictionary *parameters = [self parametersFromRemoteMedia:media];

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

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

[self.wordPressComRESTAPI post:requestUrl
parameters:nil
Expand Down Expand Up @@ -316,7 +316,7 @@ -(void)getMetadataFromVideoPressID:(NSString *)videoPressID
{
NSString *path = [NSString stringWithFormat:@"videos/%@", videoPressID];
NSString *requestUrl = [self pathForEndpoint:path
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
withVersion:WordPressComRESTAPIVersion_1_1];

[self.wordPressComRESTAPI get:requestUrl
parameters:nil
Expand Down Expand Up @@ -356,7 +356,7 @@ -(void)getVideoPressToken:(NSString *)videoPressID

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

[self.wordPressComRESTAPI post:requestUrl
parameters:nil
Expand Down
Loading