diff --git a/Sources/APIInterface/WordPressComRESTAPIVersionedPathBuilder.m b/Sources/APIInterface/WordPressComRESTAPIVersionedPathBuilder.m new file mode 100644 index 00000000..6c302ba0 --- /dev/null +++ b/Sources/APIInterface/WordPressComRESTAPIVersionedPathBuilder.m @@ -0,0 +1,55 @@ +#import +#import "WordPressKit/WordPressComRESTAPIVersionedPathBuilder.h" + +static NSString* const WordPressComRESTApiVersionStringInvalid = @"invalid_api_version"; +static NSString* const WordPressComRESTApiVersionString_1_0 = @"rest/v1"; +static NSString* const WordPressComRESTApiVersionString_1_1 = @"rest/v1.1"; +static NSString* const WordPressComRESTApiVersionString_1_2 = @"rest/v1.2"; +static NSString* const WordPressComRESTApiVersionString_1_3 = @"rest/v1.3"; +static NSString* const WordPressComRESTApiVersionString_2_0 = @"wpcom/v2"; + +@implementation WordPressComRESTAPIVersionedPathBuilder + ++ (NSString *)pathForEndpoint:(NSString *)endpoint + withVersion:(WordPressComRESTAPIVersion)apiVersion +{ + NSString *apiVersionString = [self apiVersionStringWithEnumValue:apiVersion]; + + return [NSString stringWithFormat:@"%@/%@", apiVersionString, endpoint]; +} + ++ (NSString *)apiVersionStringWithEnumValue:(WordPressComRESTAPIVersion)apiVersion +{ + NSString *result = nil; + + switch (apiVersion) { + case WordPressComRESTAPIVersion_1_0: + result = WordPressComRESTApiVersionString_1_0; + break; + + case WordPressComRESTAPIVersion_1_1: + result = WordPressComRESTApiVersionString_1_1; + break; + + case WordPressComRESTAPIVersion_1_2: + result = WordPressComRESTApiVersionString_1_2; + break; + + case WordPressComRESTAPIVersion_1_3: + result = WordPressComRESTApiVersionString_1_3; + break; + + case WordPressComRESTAPIVersion_2_0: + result = WordPressComRESTApiVersionString_2_0; + break; + + default: + NSAssert(NO, @"This should never by executed"); + result = WordPressComRESTApiVersionStringInvalid; + break; + } + + return result; +} + +@end diff --git a/Sources/APIInterface/include/WordPressComRESTAPIVersionedPathBuilder.h b/Sources/APIInterface/include/WordPressComRESTAPIVersionedPathBuilder.h new file mode 100644 index 00000000..a6d04819 --- /dev/null +++ b/Sources/APIInterface/include/WordPressComRESTAPIVersionedPathBuilder.h @@ -0,0 +1,10 @@ +#import +#import + +@interface WordPressComRESTAPIVersionedPathBuilder: NSObject + ++ (NSString *)pathForEndpoint:(NSString *)endpoint + withVersion:(WordPressComRESTAPIVersion)apiVersion +NS_SWIFT_NAME(path(forEndpoint:withVersion:)); + +@end diff --git a/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.h b/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.h index 9e37c5c2..6d7ad96a 100644 --- a/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.h +++ b/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.h @@ -49,12 +49,4 @@ NS_SWIFT_NAME(path(forEndpoint:withVersion:)); @end -@interface WordPressComRESTVersionedPathBuilder: NSObject - -+ (NSString *)pathForEndpoint:(NSString *)endpoint - withVersion:(WordPressComRESTAPIVersion)apiVersion -NS_SWIFT_NAME(path(forEndpoint:withVersion:)); - -@end - NS_ASSUME_NONNULL_END diff --git a/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.m b/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.m index 716075da..b3f1f359 100644 --- a/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.m +++ b/Sources/BasicBlogAPIObjc/ServiceRemoteWordPressComREST.m @@ -22,59 +22,8 @@ - (NSString *)pathForEndpoint:(NSString *)resourceUrl { NSParameterAssert([resourceUrl isKindOfClass:[NSString class]]); - return [WordPressComRESTVersionedPathBuilder pathForEndpoint:resourceUrl - withVersion:apiVersion]; + return [WordPressComRESTAPIVersionedPathBuilder pathForEndpoint:resourceUrl + withVersion:apiVersion]; } @end - -static NSString* const ServiceRemoteWordPressComRESTApiVersionStringInvalid = @"invalid_api_version"; -static NSString* const ServiceRemoteWordPressComRESTApiVersionString_1_0 = @"rest/v1"; -static NSString* const ServiceRemoteWordPressComRESTApiVersionString_1_1 = @"rest/v1.1"; -static NSString* const ServiceRemoteWordPressComRESTApiVersionString_1_2 = @"rest/v1.2"; -static NSString* const ServiceRemoteWordPressComRESTApiVersionString_1_3 = @"rest/v1.3"; -static NSString* const ServiceRemoteWordPressComRESTApiVersionString_2_0 = @"wpcom/v2"; - -@implementation WordPressComRESTVersionedPathBuilder - -+ (NSString *)pathForEndpoint:(NSString *)endpoint withVersion:(WordPressComRESTAPIVersion)apiVersion -{ - NSString *apiVersionString = [self apiVersionStringWithEnumValue:apiVersion]; - - return [NSString stringWithFormat:@"%@/%@", apiVersionString, endpoint]; -} - -+ (NSString *)apiVersionStringWithEnumValue:(WordPressComRESTAPIVersion)apiVersion -{ - NSString *result = nil; - - switch (apiVersion) { - case WordPressComRESTAPIVersion_1_0: - result = ServiceRemoteWordPressComRESTApiVersionString_1_0; - break; - - case WordPressComRESTAPIVersion_1_1: - result = ServiceRemoteWordPressComRESTApiVersionString_1_1; - break; - - case WordPressComRESTAPIVersion_1_2: - result = ServiceRemoteWordPressComRESTApiVersionString_1_2; - break; - - case WordPressComRESTAPIVersion_1_3: - result = ServiceRemoteWordPressComRESTApiVersionString_1_3; - break; - - case WordPressComRESTAPIVersion_2_0: - result = ServiceRemoteWordPressComRESTApiVersionString_2_0; - break; - - default: - NSAssert(NO, @"This should never by executed"); - result = ServiceRemoteWordPressComRESTApiVersionStringInvalid; - break; - } - - return result; -} -@end diff --git a/Sources/WordPressKit/WordPressKit.h b/Sources/WordPressKit/WordPressKit.h index 3e879584..aa763b73 100644 --- a/Sources/WordPressKit/WordPressKit.h +++ b/Sources/WordPressKit/WordPressKit.h @@ -9,6 +9,7 @@ FOUNDATION_EXPORT const unsigned char WordPressKitVersionString[]; #import #import #import +#import #import #import diff --git a/WordPressKit.xcodeproj/project.pbxproj b/WordPressKit.xcodeproj/project.pbxproj index 76275c1d..8270f2e3 100644 --- a/WordPressKit.xcodeproj/project.pbxproj +++ b/WordPressKit.xcodeproj/project.pbxproj @@ -79,6 +79,8 @@ 3FD634FA2BC3AE6800CEDF5E /* AppTransportSecuritySettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46ABD0E9262EEE0400C7FF24 /* AppTransportSecuritySettingsTests.swift */; }; 3FD634FB2BC3AE6C00CEDF5E /* Bundle+SPMSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FD634E92BC3A6BA00CEDF5E /* Bundle+SPMSupport.swift */; }; 3FD634FF2BC3B3D400CEDF5E /* WordPressComRestApiErrorDomain.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FD634FE2BC3B3D400CEDF5E /* WordPressComRestApiErrorDomain.swift */; }; + 3FD635042BC3F05400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FD635032BC3F03200CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3FD635062BC3F08400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FD635052BC3F08400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.m */; }; 3FE2E94F2BB29A1B002CA2E1 /* FilePart.m in Sources */ = {isa = PBXBuildFile; fileRef = 3FE2E94D2BB29A1B002CA2E1 /* FilePart.m */; }; 3FE2E9502BB29A1B002CA2E1 /* FilePart.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FE2E94E2BB29A1B002CA2E1 /* FilePart.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3FE2E9672BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FE2E9662BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -824,6 +826,8 @@ 3FD634F02BC3AD6200CEDF5E /* WebauthChallengeInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebauthChallengeInfo.swift; sourceTree = ""; }; 3FD634F12BC3AD6200CEDF5E /* StringEncoding+IANA.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StringEncoding+IANA.swift"; sourceTree = ""; }; 3FD634FE2BC3B3D400CEDF5E /* WordPressComRestApiErrorDomain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordPressComRestApiErrorDomain.swift; sourceTree = ""; }; + 3FD635032BC3F03200CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WordPressComRESTAPIVersionedPathBuilder.h; sourceTree = ""; }; + 3FD635052BC3F08400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WordPressComRESTAPIVersionedPathBuilder.m; sourceTree = ""; }; 3FE2E94D2BB29A1B002CA2E1 /* FilePart.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FilePart.m; sourceTree = ""; }; 3FE2E94E2BB29A1B002CA2E1 /* FilePart.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FilePart.h; sourceTree = ""; }; 3FE2E9662BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WordPressComRESTAPIVersion.h; sourceTree = ""; }; @@ -2092,6 +2096,7 @@ 3FE2E94E2BB29A1B002CA2E1 /* FilePart.h */, 3FFCC0552BABC78B0051D229 /* WordPressComRESTAPIInterfacing.h */, 3FE2E9662BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h */, + 3FD635032BC3F03200CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.h */, ); path = include; sourceTree = ""; @@ -2101,6 +2106,7 @@ children = ( 3FE2E9522BB3F4ED002CA2E1 /* include */, 3FE2E94D2BB29A1B002CA2E1 /* FilePart.m */, + 3FD635052BC3F08400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.m */, ); path = APIInterface; sourceTree = ""; @@ -2670,6 +2676,7 @@ 9368C78C1EC5EF1B0092CE8E /* WordPressKit.h in Headers */, 93C674F11EE8351E00BFAF05 /* NSMutableDictionary+Helpers.h in Headers */, 93BD273C1EE73282002BB00B /* AccountServiceRemoteREST.h in Headers */, + 3FD635042BC3F05400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.h in Headers */, 93BD27711EE737A8002BB00B /* ServiceRemoteWordPressXMLRPC.h in Headers */, 3FE2E9672BBEB8D2002CA2E1 /* WordPressComRESTAPIVersion.h in Headers */, 93BD276F1EE737A8002BB00B /* ServiceRemoteWordPressComREST.h in Headers */, @@ -3463,6 +3470,7 @@ 32FC20CE255DCC6100CD0A7B /* JetpackScanThreat.swift in Sources */, FE50965F2A2E42A500DDD071 /* JetpackSocialServiceRemote.swift in Sources */, 3F3195AD266FF94B00397EE7 /* ZendeskMetadata.swift in Sources */, + 3FD635062BC3F08400CEDF5E /* WordPressComRESTAPIVersionedPathBuilder.m in Sources */, 40A71C6E220E1D8E002E3D25 /* StatsServiceRemoteV2.swift in Sources */, 82FFBF521F45F04100F4573F /* RemoteBlogJetpackMonitorSettings.swift in Sources */, 462422292548B98A002B8A12 /* SiteDesignServiceRemote.swift in Sources */,