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

Commit cd75f34

Browse files
authored
Merge pull request #57 from wordpress-mobile/fix/xmlrpc-sticky-post
Fix/xmlrpc sticky post
2 parents c0259a8 + b2d5ec2 commit cd75f34

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

Podfile.lock

Lines changed: 2 additions & 2 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 (0.5.0)
30-
- WordPressKit (1.5.0-beta.2):
30+
- WordPressKit (1.5.1.beta.1):
3131
- Alamofire (~> 4.7.3)
3232
- CocoaLumberjack (= 3.4.2)
3333
- NSObject-SafeExpectations (= 0.0.3)
@@ -70,7 +70,7 @@ SPEC CHECKSUMS:
7070
OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab
7171
OHHTTPStubs: 1e21c7d2c084b8153fc53d48400d8919d2d432d0
7272
UIDeviceIdentifier: a959a6d4f51036b4180dd31fb26483a820f1cc46
73-
WordPressKit: dd63cde48c272cbb4786dd2958adbc0a9e28a95b
73+
WordPressKit: c149fcf74fc37836349f825d4ef1771079243ed3
7474
WordPressShared: f55be10963c8f6dbbc8e896450805ba1dd5353f7
7575
wpxmlrpc: bfc572f62ce7ee897f6f38b098d2ba08732ecef4
7676

WordPressKit.podspec

Lines changed: 1 addition & 1 deletion
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 = "1.5.0"
3+
s.version = "1.5.1.beta.1"
44
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."
55

66
s.description = <<-DESC

WordPressKit/PostServiceRemoteREST.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ - (RemotePost *)remotePostFromJSONDictionary:(NSDictionary *)jsonPost {
363363
post.commentCount = [jsonPost numberForKeyPath:@"discussion.comment_count"] ?: @0;
364364
post.likeCount = [jsonPost numberForKeyPath:@"like_count"] ?: @0;
365365

366-
NSNumber *stickyPost = [jsonPost numberForKeyPath:@"sticky"] ?: @0;
367-
post.isStickyPost = stickyPost.boolValue;
366+
post.isStickyPost = [jsonPost numberForKeyPath:@"sticky"];
368367

369368
// FIXME: remove conversion once API is fixed #38-io
370369
// metadata should always be an array but it's returning false when there are no custom fields
@@ -440,7 +439,9 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
440439
parameters[@"featured_image"] = post.postThumbnailID ? [post.postThumbnailID stringValue] : @"";
441440
parameters[@"metadata"] = [self metadataForPost:post];
442441

443-
parameters[@"sticky"] = post.isStickyPost ? @"true" : @"false";
442+
if (post.isStickyPost != nil) {
443+
parameters[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";
444+
}
444445

445446
// Scheduled posts need to sync with a status of 'publish'.
446447
// Passing a status of 'future' will set the post status to 'draft'

WordPressKit/PostServiceRemoteXMLRPC.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ - (RemotePost *)remotePostFromXMLRPCDictionary:(NSDictionary *)xmlrpcDictionary
320320
post.tags = [self tagsFromXMLRPCTermsArray:terms];
321321
post.categories = [self remoteCategoriesFromXMLRPCTermsArray:terms];
322322

323-
NSNumber *stickyPost = [xmlrpcDictionary numberForKeyPath:@"sticky"] ?: @0;
324-
post.isStickyPost = stickyPost.boolValue;
323+
post.isStickyPost = [xmlrpcDictionary numberForKeyPath:@"sticky"];
325324

326325
// Pick an image to use for display
327326
if (post.postThumbnailPath) {
@@ -412,8 +411,11 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
412411
if ([post.metadata count] > 0) {
413412
postParams[@"custom_fields"] = post.metadata;
414413
}
415-
416-
postParams[@"sticky"] = post.isStickyPost ? @"true" : @"false";
414+
415+
if (post.isStickyPost != nil) {
416+
postParams[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";
417+
}
418+
417419
postParams[@"wp_page_parent_id"] = post.parentID ? post.parentID.stringValue : @"0";
418420

419421
// Scheduled posts need to sync with a status of 'publish'.

WordPressKit/RemotePost.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ extern NSString * const PostStatusDeleted;
4242
@property (nonatomic, strong) NSArray *revisions;
4343
@property (nonatomic, strong) NSArray *tags;
4444
@property (nonatomic, strong) NSString *pathForDisplayImage;
45+
@property (nonatomic, assign) NSNumber *isStickyPost;
4546
@property (nonatomic, assign) BOOL isFeaturedImageChanged;
46-
@property (nonatomic, assign) BOOL isStickyPost;
4747

4848
/**
4949
Array of custom fields. Each value is a dictionary containing {ID, key, value}

WordPressKitTests/PostServiceRemoteRESTTests.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ - (void)testThatCreatePostWorks
144144
OCMStub([post password]).andReturn(@"Password");
145145
OCMStub([post type]).andReturn(@"Type");
146146
OCMStub([post metadata]).andReturn(@[]);
147-
OCMStub([post isStickyPost]).andReturn(YES);
147+
OCMStub([post isStickyPost]).andReturn(@1);
148148
OCMStub([post parentID]).andReturn(@38);
149149

150150
XCTAssertNoThrow(service = [[PostServiceRemoteREST alloc] initWithWordPressComRestApi:api siteID:dotComID]);
@@ -189,7 +189,7 @@ - (void)testThatUpdatePostWorks
189189
OCMStub([post password]).andReturn(@"Password");
190190
OCMStub([post type]).andReturn(@"Type");
191191
OCMStub([post metadata]).andReturn(@[]);
192-
OCMStub([post isStickyPost]).andReturn(YES);
192+
OCMStub([post isStickyPost]).andReturn(@0);
193193
OCMStub([post parentID]).andReturn(nil);
194194

195195
XCTAssertNoThrow(service = [[PostServiceRemoteREST alloc] initWithWordPressComRestApi:api siteID:dotComID]);

WordPressKitTests/PostServiceRemoteXMLRPCTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class PostServiceRemoteXMLRPCTests: RemoteTestCase, XMLRPCTestable {
99
let postID: NSNumber = 1
1010
let postTitle = "Hello world!"
1111
let postContent = "Welcome to WordPress."
12-
let postIsSticky = true
12+
let postIsSticky: NSNumber = 1
1313
let postParentId: NSNumber = 2
1414

1515
let getPostSuccessMockFilename = "xmlrpc-wp-getpost-success.xml"

0 commit comments

Comments
 (0)