Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit fae09dd

Browse files
committed
Define WordPressComRESTAPIInterfacing abstraction with GET method
Use it in one call withing `AccountServiceRemoteREST`. The tests verify it works as expected.
1 parent 118fd9a commit fae09dd

File tree

7 files changed

+61
-2
lines changed

7 files changed

+61
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@import Foundation;
2+
3+
@protocol WordPressComRESTAPIInterfacing
4+
5+
- (void)get:(NSString * _Nonnull)URLString
6+
parameters:(NSDictionary<NSString *, NSObject *> * _Nullable)parameters
7+
success:(void (^ _Nonnull)(id _Nonnull, NSHTTPURLResponse * _Nullable))success
8+
failure:(void (^ _Nonnull)(NSError * _Nonnull, NSHTTPURLResponse * _Nullable))failure;
9+
10+
@end

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
3FFCC04B2BABA5220051D229 /* DateFormatter+WordPressComTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC04A2BABA5220051D229 /* DateFormatter+WordPressComTests.swift */; };
7878
3FFCC04D2BABA6980051D229 /* NSDate+WordPressComTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC04C2BABA6980051D229 /* NSDate+WordPressComTests.swift */; };
7979
3FFCC04F2BABA6E60051D229 /* Date+WordPressCom.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFCC04E2BABA6E60051D229 /* Date+WordPressCom.swift */; };
80+
3FFCC0572BABC7E00051D229 /* WordPressComRESTAPIInterfacing.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FFCC0552BABC78B0051D229 /* WordPressComRESTAPIInterfacing.h */; settings = {ATTRIBUTES = (Public, ); }; };
8081
40247DFA2120D8E100AE1C3C /* AutomatedTransferService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */; };
8182
40247DFC2120E69600AE1C3C /* AutomatedTransferStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */; };
8283
404057C5221B30400060250C /* StatsSearchTermTimeIntervalData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 404057C4221B30400060250C /* StatsSearchTermTimeIntervalData.swift */; };
@@ -808,6 +809,7 @@
808809
3FFCC04A2BABA5220051D229 /* DateFormatter+WordPressComTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+WordPressComTests.swift"; sourceTree = "<group>"; };
809810
3FFCC04C2BABA6980051D229 /* NSDate+WordPressComTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSDate+WordPressComTests.swift"; sourceTree = "<group>"; };
810811
3FFCC04E2BABA6E60051D229 /* Date+WordPressCom.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+WordPressCom.swift"; sourceTree = "<group>"; };
812+
3FFCC0552BABC78B0051D229 /* WordPressComRESTAPIInterfacing.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WordPressComRESTAPIInterfacing.h; sourceTree = "<group>"; };
811813
40247DF92120D8E100AE1C3C /* AutomatedTransferService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferService.swift; sourceTree = "<group>"; };
812814
40247DFB2120E69600AE1C3C /* AutomatedTransferStatus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomatedTransferStatus.swift; sourceTree = "<group>"; };
813815
404057C4221B30400060250C /* StatsSearchTermTimeIntervalData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsSearchTermTimeIntervalData.swift; sourceTree = "<group>"; };
@@ -1558,6 +1560,30 @@
15581560
path = Plans;
15591561
sourceTree = "<group>";
15601562
};
1563+
3FFCC0532BABC75F0051D229 /* Sources */ = {
1564+
isa = PBXGroup;
1565+
children = (
1566+
3FFCC0542BABC7680051D229 /* APIInterface */,
1567+
);
1568+
path = Sources;
1569+
sourceTree = "<group>";
1570+
};
1571+
3FFCC0542BABC7680051D229 /* APIInterface */ = {
1572+
isa = PBXGroup;
1573+
children = (
1574+
3FFCC0562BABC7D20051D229 /* include */,
1575+
);
1576+
path = APIInterface;
1577+
sourceTree = "<group>";
1578+
};
1579+
3FFCC0562BABC7D20051D229 /* include */ = {
1580+
isa = PBXGroup;
1581+
children = (
1582+
3FFCC0552BABC78B0051D229 /* WordPressComRESTAPIInterfacing.h */,
1583+
);
1584+
path = include;
1585+
sourceTree = "<group>";
1586+
};
15611587
404057C3221B30140060250C /* Time Interval */ = {
15621588
isa = PBXGroup;
15631589
children = (
@@ -1939,6 +1965,7 @@
19391965
9368C7711EC5EF1B0092CE8E = {
19401966
isa = PBXGroup;
19411967
children = (
1968+
3FFCC0532BABC75F0051D229 /* Sources */,
19421969
FFE247CD20CB1245002DF3A2 /* LICENSE */,
19431970
FFE247CC20CB118A002DF3A2 /* README.md */,
19441971
0C3A2A412A2E7BA500FD91D6 /* CHANGELOG.md */,
@@ -2811,6 +2838,7 @@
28112838
93BD276F1EE737A8002BB00B /* ServiceRemoteWordPressComREST.h in Headers */,
28122839
93BD273B1EE73282002BB00B /* AccountServiceRemote.h in Headers */,
28132840
93BD27691EE736A8002BB00B /* RemoteUser.h in Headers */,
2841+
3FFCC0572BABC7E00051D229 /* WordPressComRESTAPIInterfacing.h in Headers */,
28142842
74B5F0DC1EF829B800B411E7 /* BlogServiceRemote.h in Headers */,
28152843
74B5F0D71EF8299B00B411E7 /* BlogServiceRemoteREST.h in Headers */,
28162844
74B5F0E61EF8699C00B411E7 /* RemotePostType.h in Headers */,

WordPressKit/AccountServiceRemoteREST.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ - (void)getAccountDetailsWithSuccess:(void (^)(RemoteUser *remoteUser))success
5656
NSString *requestUrl = [self pathForEndpoint:@"me"
5757
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
5858

59-
[self.wordPressComRestApi GET:requestUrl
59+
[self.wordPressComRESTAPI get:requestUrl
6060
parameters:nil
6161
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
6262
if (!success) {

WordPressKit/ServiceRemoteWordPressComREST.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import <Foundation/Foundation.h>
2+
#import <WordPressKit/WordPressComRESTAPIInterfacing.h>
23

34
@class WordPressComRestApi;
45

@@ -23,6 +24,8 @@ NS_ASSUME_NONNULL_BEGIN
2324
*/
2425
@property (nonatomic, strong, readonly) WordPressComRestApi *wordPressComRestApi;
2526

27+
@property (nonatomic, strong, readonly) id<WordPressComRESTAPIInterfacing> wordPressComRESTAPI;
28+
2629
/**
2730
* @brief Designated initializer.
2831
*

WordPressKit/ServiceRemoteWordPressComREST.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ - (instancetype)initWithWordPressComRestApi:(WordPressComRestApi *)wordPressComR
2626
self = [super init];
2727
if (self) {
2828
_wordPressComRestApi = wordPressComRestApi;
29+
_wordPressComRESTAPI = wordPressComRestApi;
2930
}
3031
return self;
3132
}

WordPressKit/WordPressComRestApi.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,20 @@ extension WordPressAPIError<WordPressComRestApiEndpointError> {
620620
return self as NSError
621621
}
622622
}
623+
624+
extension WordPressComRestApi: WordPressComRESTAPIInterfacing {
625+
626+
// A note on the naming: Even if defined as `GET` in Objective-C, then method gets converted to Swift as `get`.
627+
//
628+
// Also, there is no Objective-C direct equivalent of `AnyObject`, which here is used in `parameters: [String: AnyObject]?`.
629+
//
630+
// For those reasons, we can't immediately conform to `WordPressComRESTAPIInterfacing` and need instead to use this kind of wrapping.
631+
public func get(
632+
_ URLString: String,
633+
parameters: [String: NSObject]?,
634+
success: @escaping (Any, HTTPURLResponse?) -> Void,
635+
failure: @escaping (any Error, HTTPURLResponse?) -> Void
636+
) {
637+
GET(URLString, parameters: parameters, success: success, failure: failure)
638+
}
639+
}

WordPressKit/WordPressKit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FOUNDATION_EXPORT double WordPressKitVersionNumber;
66
//! Project version string for WordPressKit.
77
FOUNDATION_EXPORT const unsigned char WordPressKitVersionString[];
88

9-
// In this header, you should import all the public headers of your framework using statements like #import <WordPressKit/PublicHeader.h>
9+
#import <WordPressKit/WordPressComRESTAPIInterfacing.h>
1010
#import <WordPressKit/ServiceRemoteWordPressComREST.h>
1111
#import <WordPressKit/ServiceRemoteWordPressXMLRPC.h>
1212
#import <WordPressKit/SiteServiceRemoteWordPressComREST.h>

0 commit comments

Comments
 (0)