-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move
WordPressComRESTAPIVersionedPathBuilder
to APIInterface/
- Loading branch information
Showing
6 changed files
with
76 additions
and
61 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
Sources/APIInterface/WordPressComRESTAPIVersionedPathBuilder.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#import <Foundation/Foundation.h> | ||
#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 |
10 changes: 10 additions & 0 deletions
10
Sources/APIInterface/include/WordPressComRESTAPIVersionedPathBuilder.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <WordPressKit/WordPressComRESTAPIVersion.h> | ||
|
||
@interface WordPressComRESTAPIVersionedPathBuilder: NSObject | ||
|
||
+ (NSString *)pathForEndpoint:(NSString *)endpoint | ||
withVersion:(WordPressComRESTAPIVersion)apiVersion | ||
NS_SWIFT_NAME(path(forEndpoint:withVersion:)); | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters