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

Commit ff85847

Browse files
committed
Merge remote-tracking branch 'origin/develop'
# Conflicts: # WordPressKit.podspec
2 parents d38b00b + 05a4a52 commit ff85847

File tree

6 files changed

+95
-8
lines changed

6 files changed

+95
-8
lines changed

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugin 'cocoapods-repo-update'
99
def wordpresskit_pods
1010
pod 'Alamofire', '~> 4.7.3'
1111
pod 'CocoaLumberjack', '3.4.2'
12-
pod 'WordPressShared', '~> 1.4'
12+
pod 'WordPressShared', '~> 1.8.0-beta'
1313
pod 'NSObject-SafeExpectations', '~> 0.0.3'
1414
pod 'wpxmlrpc', '0.8.4'
1515
pod 'UIDeviceIdentifier', '~> 1.1.4'
@@ -30,5 +30,5 @@ target 'WordPressKitTests' do
3030
pod 'OHHTTPStubs', '6.1.0'
3131
pod 'OHHTTPStubs/Swift', '6.1.0'
3232
pod 'OCMock', '~> 3.4.2'
33-
pod 'WordPressShared', '~> 1.4'
33+
pod 'WordPressShared', '~> 1.8.0-beta'
3434
end

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ PODS:
2727
- OHHTTPStubs/Swift (6.1.0):
2828
- OHHTTPStubs/Default
2929
- UIDeviceIdentifier (1.1.4)
30-
- WordPressShared (1.7.3):
30+
- WordPressShared (1.8.0-beta.1):
3131
- CocoaLumberjack (~> 3.4)
3232
- FormatterKit/TimeIntervalFormatter (= 1.8.2)
3333
- wpxmlrpc (0.8.4)
@@ -40,7 +40,7 @@ DEPENDENCIES:
4040
- OHHTTPStubs (= 6.1.0)
4141
- OHHTTPStubs/Swift (= 6.1.0)
4242
- UIDeviceIdentifier (~> 1.1.4)
43-
- WordPressShared (~> 1.4)
43+
- WordPressShared (~> 1.8.0-beta)
4444
- wpxmlrpc (= 0.8.4)
4545

4646
SPEC REPOS:
@@ -63,9 +63,9 @@ SPEC CHECKSUMS:
6363
OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab
6464
OHHTTPStubs: 1e21c7d2c084b8153fc53d48400d8919d2d432d0
6565
UIDeviceIdentifier: 8f8a24b257a4d978c8d40ad1e7355b944ffbfa8c
66-
WordPressShared: 0853172642668b0fbf5c8d56e743896ebf9aae01
66+
WordPressShared: c77c0fc4840d5694a1a684f8c541224dfdb147f2
6767
wpxmlrpc: 6ba55c773cfa27083ae4a2173e69b19f46da98e2
6868

69-
PODFILE CHECKSUM: 2d40a9a3484ab5030d6ddd135b604a0be90271c8
69+
PODFILE CHECKSUM: db3bdf0c001097977876ad82d356303ac06e4c81
7070

7171
COCOAPODS: 1.6.1

WordPressKit.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressKit"
3-
s.version = "4.1.0"
3+
s.version = "4.1.1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
2121

2222
s.dependency 'Alamofire', '~> 4.7.3'
2323
s.dependency 'CocoaLumberjack', '~> 3.4'
24-
s.dependency 'WordPressShared', '~> 1.4'
24+
s.dependency 'WordPressShared', '~> 1.8.0'
2525
s.dependency 'NSObject-SafeExpectations', '0.0.3'
2626
s.dependency 'wpxmlrpc', '0.8.4'
2727
s.dependency 'UIDeviceIdentifier', '~> 1.1.4'

WordPressKit/PostServiceRemoteREST.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@
2424
success:(void (^)(RemotePost *))success
2525
failure:(void (^)(NSError *))failure;
2626

27+
/**
28+
* @brief Saves a post.
29+
*
30+
*
31+
* @discussion Drafts and auto-drafts are just overwritten by autosave for the same
32+
user if the post is not locked.
33+
* Non drafts or other users drafts are not overwritten.
34+
* @param post The post to save. Cannot be nil.
35+
* @param success The block that will be executed on success. Can be nil.
36+
* @param failure The block that will be executed on failure. Can be nil.
37+
*/
38+
- (void)autoSave:(RemotePost *)post
39+
success:(void (^)(RemotePost *post, NSString *previewURL))success
40+
failure:(void (^)(NSError *error))failure;
41+
2742
@end

WordPressKit/PostServiceRemoteREST.m

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,33 @@ - (void)updatePost:(RemotePost *)post
183183
}];
184184
}
185185

186+
- (void)autoSave:(RemotePost *)post
187+
success:(void (^)(RemotePost *, NSString *))success
188+
failure:(void (^)(NSError *))failure
189+
{
190+
NSParameterAssert([post isKindOfClass:[RemotePost class]]);
191+
192+
NSString *path = [NSString stringWithFormat:@"sites/%@/posts/%@/autosave", self.siteID, post.postID];
193+
NSString *requestUrl = [self pathForEndpoint:path
194+
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
195+
196+
NSDictionary *parameters = [self parametersWithRemotePost:post];
197+
198+
[self.wordPressComRestApi POST:requestUrl
199+
parameters:parameters
200+
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
201+
RemotePost *post = [self remotePostFromJSONDictionary:responseObject];
202+
NSString *previewURL = responseObject[@"preview_URL"];
203+
if (success) {
204+
success(post, previewURL);
205+
}
206+
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
207+
if (failure) {
208+
failure(error);
209+
}
210+
}];
211+
}
212+
186213
- (void)deletePost:(RemotePost *)post
187214
success:(void (^)(void))success
188215
failure:(void (^)(NSError *))failure

WordPressKitTests/PostServiceRemoteRESTTests.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,51 @@ - (void)testThatUpdatePostThrowsExceptionWithoutPost
218218
failure:^(NSError *error) {}]);
219219
}
220220

221+
#pragma mark - Autosaving posts
222+
223+
- (void)testThatAutoSavePostWorks
224+
{
225+
NSNumber *dotComID = @10;
226+
WordPressComRestApi *api = OCMStrictClassMock([WordPressComRestApi class]);
227+
PostServiceRemoteREST *service = nil;
228+
229+
RemotePost *post = OCMClassMock([RemotePost class]);
230+
OCMStub([post postID]).andReturn(@1);
231+
OCMStub([post title]).andReturn(@"Title");
232+
OCMStub([post content]).andReturn(@"Content");
233+
OCMStub([post status]).andReturn(@"Status");
234+
OCMStub([post password]).andReturn(@"Password");
235+
OCMStub([post type]).andReturn(@"Type");
236+
OCMStub([post metadata]).andReturn(@[]);
237+
OCMStub([post isStickyPost]).andReturn(@0);
238+
OCMStub([post parentID]).andReturn(nil);
239+
240+
XCTAssertNoThrow(service = [[PostServiceRemoteREST alloc] initWithWordPressComRestApi:api siteID:dotComID]);
241+
242+
NSString *endpoint = [NSString stringWithFormat:@"sites/%@/posts/%@/autosave", dotComID, post.postID];
243+
NSString *url = [service pathForEndpoint:endpoint
244+
withVersion:ServiceRemoteWordPressComRESTApiVersion_1_1];
245+
246+
OCMStub([api POST:[OCMArg isEqual:url]
247+
parameters:[OCMArg isKindOfClass:[NSDictionary class]]
248+
success:[OCMArg isNotNil]
249+
failure:[OCMArg isNotNil]]);
250+
251+
[service autoSave:post
252+
success:^(RemotePost *post, NSString *previewURL) {}
253+
failure:^(NSError *error) {}];
254+
}
255+
256+
- (void)testThatAutoSavePostThrowsExceptionWithoutPost
257+
{
258+
PostServiceRemoteREST *service = nil;
259+
260+
XCTAssertNoThrow(service = [self service]);
261+
XCTAssertThrows([service autoSave:nil
262+
success:^(RemotePost *post, NSString *previewURL) {}
263+
failure:^(NSError *error) {}]);
264+
}
265+
221266
#pragma mark - Deleting posts
222267

223268
- (void)testThatDeletePostWorks

0 commit comments

Comments
 (0)