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

Commit d0ff67a

Browse files
committed
Re-implement a few remote post related types
1 parent fc7d2ab commit d0ff67a

24 files changed

Lines changed: 189 additions & 260 deletions

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 20 additions & 32 deletions
Large diffs are not rendered by default.

WordPressKit/BlogServiceRemoteREST.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import <Foundation/Foundation.h>
22
#import "BlogServiceRemoteREST.h"
33
#import "NSMutableDictionary+Helpers.h"
4-
#import "RemotePostType.h"
54
#import "WPKit-Swift.h"
65
@import NSObject_SafeExpectations;
76
@import WordPressShared;

WordPressKit/BlogServiceRemoteXMLRPC.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#import "BlogServiceRemoteXMLRPC.h"
22
#import "NSMutableDictionary+Helpers.h"
3-
#import "RemotePostType.h"
43
#import "WPKit-Swift.h"
54
@import NSObject_SafeExpectations;
65
@import WordPressShared;

WordPressKit/NSObject+Debug.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extension NSObject {
2+
3+
var allProperties: [String: Any] {
4+
let properties = Mirror(reflecting: self)
5+
.children
6+
.compactMap { child in
7+
if let label = child.label {
8+
return (label, child.value)
9+
} else {
10+
return nil
11+
}
12+
}
13+
return Dictionary(properties) { (_, new) in new }
14+
}
15+
16+
}

WordPressKit/PostServiceRemoteREST.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#import "PostServiceRemoteREST.h"
2-
#import "RemotePost.h"
3-
#import "RemotePostCategory.h"
42
#import "RemoteUser.h"
53
#import "WPKit-Swift.h"
64
@import WordPressShared;

WordPressKit/PostServiceRemoteXMLRPC.m

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#import "PostServiceRemoteXMLRPC.h"
2-
#import "RemotePost.h"
3-
#import "RemotePostCategory.h"
42
#import "NSMutableDictionary+Helpers.h"
53
#import "WPKit-Swift.h"
64
@import NSObject_SafeExpectations;
@@ -54,7 +52,14 @@ - (void)getPostsOfType:(NSString *)postType
5452
options:(NSDictionary *)options
5553
success:(void (^)(NSArray <RemotePost *> *remotePosts))success
5654
failure:(void (^)(NSError *error))failure {
57-
NSArray *statuses = @[PostStatusDraft, PostStatusPending, PostStatusPrivate, PostStatusPublish, PostStatusScheduled, PostStatusTrash];
55+
NSArray *statuses = @[
56+
RemotePost.statusDraft,
57+
RemotePost.statusPending,
58+
RemotePost.statusPrivate,
59+
RemotePost.statusPublish,
60+
RemotePost.statusScheduled,
61+
RemotePost.statusTrash
62+
];
5863
NSString *postStatus = [statuses componentsJoinedByString:@","];
5964
NSDictionary *extraParameters = @{
6065
@"number": @40,
@@ -343,8 +348,8 @@ - (NSString *)statusForPostStatus:(NSString *)status andDate:(NSDate *)date
343348
{
344349
// Scheduled posts are synced with a post_status of 'publish' but we want to
345350
// work with a status of 'future' from within the app.
346-
if ([status isEqualToString:PostStatusPublish] && date == [date laterDate:[NSDate date]]) {
347-
return PostStatusScheduled;
351+
if ([status isEqualToString:RemotePost.statusPublish] && date == [date laterDate:[NSDate date]]) {
352+
return RemotePost.statusScheduled;
348353
}
349354
return status;
350355
}
@@ -426,8 +431,8 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
426431
// This is an apparent inconsistency in the XML-RPC API as 'future' should
427432
// be a valid status.
428433
// https://codex.wordpress.org/Post_Status_Transitions
429-
if (post.status == nil || [post.status isEqualToString:PostStatusScheduled]) {
430-
post.status = PostStatusPublish;
434+
if (post.status == nil || [post.status isEqualToString:RemotePost.statusScheduled]) {
435+
post.status = RemotePost.statusPublish;
431436
}
432437

433438
// At least as of 5.2.2, Private and/or Password Protected posts can't be stickied.
@@ -439,7 +444,7 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
439444
//
440445
// https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-xmlrpc-server.php
441446
//
442-
BOOL shouldIncludeStickyField = ![post.status isEqualToString:PostStatusPrivate] && post.password == nil;
447+
BOOL shouldIncludeStickyField = ![post.status isEqualToString:RemotePost.statusPrivate] && post.password == nil;
443448

444449
if (post.isStickyPost != nil && shouldIncludeStickyField) {
445450
postParams[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";

WordPressKit/RemotePost.h

Lines changed: 0 additions & 65 deletions
This file was deleted.

WordPressKit/RemotePost.m

Lines changed: 0 additions & 50 deletions
This file was deleted.

WordPressKit/RemotePost.swift

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import Foundation
2+
import ObjectiveC
3+
4+
@objcMembers public class RemotePost: NSObject {
5+
6+
public static let statusDraft = "draft"
7+
public static let statusPending = "pending"
8+
public static let statusPrivate = "private"
9+
public static let statusPublish = "publish"
10+
public static let statusScheduled = "future"
11+
public static let statusTrash = "trash"
12+
public static let statusDeleted = "deleted" // Returned by wpcom REST API when a post is permanently deleted.
13+
14+
public var postID: NSNumber?
15+
public var siteID: NSNumber?
16+
public var authorAvatarURL: String?
17+
public var authorDisplayName: String?
18+
public var authorEmail: String?
19+
public var authorURL: String?
20+
public var authorID: NSNumber?
21+
public var date: NSDate?
22+
public var dateModified: NSDate?
23+
public var title: String?
24+
public var URL: NSURL?
25+
public var shortURL: NSURL?
26+
public var content: String?
27+
public var excerpt: String?
28+
public var slug: String?
29+
public var suggestedSlug: String?
30+
public var status: String?
31+
public var password: String?
32+
public var parentID: NSNumber?
33+
public var postThumbnailID: NSNumber?
34+
public var postThumbnailPath: String?
35+
public var type: String?
36+
public var format: String?
37+
38+
/**
39+
* A snapshot of the post at the last autosave.
40+
*
41+
* This is nullable.
42+
*/
43+
public var autosave: RemotePostAutosave?
44+
45+
public var commentCount: NSNumber?
46+
public var likeCount: NSNumber?
47+
48+
public var categories: NSArray?
49+
public var revisions: NSArray?
50+
public var tags: NSArray?
51+
public var pathForDisplayImage: String?
52+
public var isStickyPost: NSNumber?
53+
public var isFeaturedImageChanged: Bool = false
54+
55+
/**
56+
Array of custom fields. Each value is a dictionary containing {ID, key, value}
57+
*/
58+
public var metadata: [[String: Any]]?
59+
60+
// Featured images?
61+
// Geolocation?
62+
// Attachments?
63+
// Metadata?
64+
65+
public override init() {
66+
super.init()
67+
}
68+
69+
public init(siteID: NSNumber, status: String, title: String?, content: String?) {
70+
super.init()
71+
self.siteID = siteID
72+
self.status = status
73+
self.title = title
74+
self.content = content
75+
}
76+
77+
public override var debugDescription: String {
78+
"\(super.description) (\(allProperties))"
79+
}
80+
81+
}

WordPressKit/RemotePostCategory.h

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)