Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 20 additions & 32 deletions WordPressKit.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion WordPressKit/BlogServiceRemoteREST.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import <Foundation/Foundation.h>
#import "BlogServiceRemoteREST.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WPKit-Swift.h"
@import NSObject_SafeExpectations;
@import WordPressShared;
Expand Down
1 change: 0 additions & 1 deletion WordPressKit/BlogServiceRemoteXMLRPC.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#import "BlogServiceRemoteXMLRPC.h"
#import "NSMutableDictionary+Helpers.h"
#import "RemotePostType.h"
#import "WPKit-Swift.h"
@import NSObject_SafeExpectations;
@import WordPressShared;
Expand Down
16 changes: 16 additions & 0 deletions WordPressKit/NSObject+Debug.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extension NSObject {

var allProperties: [String: Any] {
let properties = Mirror(reflecting: self)
.children
.compactMap { child -> (String, Any)? in
if let label = child.label {
return (label, child.value)
} else {
return nil
}
}
return Dictionary(properties) { (_, new) in new }
}

}
2 changes: 0 additions & 2 deletions WordPressKit/PostServiceRemoteREST.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#import "PostServiceRemoteREST.h"
#import "RemotePost.h"
#import "RemotePostCategory.h"
#import "RemoteUser.h"
#import "WPKit-Swift.h"
@import WordPressShared;
Expand Down
21 changes: 13 additions & 8 deletions WordPressKit/PostServiceRemoteXMLRPC.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#import "PostServiceRemoteXMLRPC.h"
#import "RemotePost.h"
#import "RemotePostCategory.h"
#import "NSMutableDictionary+Helpers.h"
#import "WPKit-Swift.h"
@import NSObject_SafeExpectations;
Expand Down Expand Up @@ -54,7 +52,14 @@ - (void)getPostsOfType:(NSString *)postType
options:(NSDictionary *)options
success:(void (^)(NSArray <RemotePost *> *remotePosts))success
failure:(void (^)(NSError *error))failure {
NSArray *statuses = @[PostStatusDraft, PostStatusPending, PostStatusPrivate, PostStatusPublish, PostStatusScheduled, PostStatusTrash];
NSArray *statuses = @[
RemotePost.statusDraft,
RemotePost.statusPending,
RemotePost.statusPrivate,
RemotePost.statusPublish,
RemotePost.statusScheduled,
RemotePost.statusTrash
];
NSString *postStatus = [statuses componentsJoinedByString:@","];
NSDictionary *extraParameters = @{
@"number": @40,
Expand Down Expand Up @@ -343,8 +348,8 @@ - (NSString *)statusForPostStatus:(NSString *)status andDate:(NSDate *)date
{
// Scheduled posts are synced with a post_status of 'publish' but we want to
// work with a status of 'future' from within the app.
if ([status isEqualToString:PostStatusPublish] && date == [date laterDate:[NSDate date]]) {
return PostStatusScheduled;
if ([status isEqualToString:RemotePost.statusPublish] && date == [date laterDate:[NSDate date]]) {
return RemotePost.statusScheduled;
}
return status;
}
Expand Down Expand Up @@ -426,8 +431,8 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
// This is an apparent inconsistency in the XML-RPC API as 'future' should
// be a valid status.
// https://codex.wordpress.org/Post_Status_Transitions
if (post.status == nil || [post.status isEqualToString:PostStatusScheduled]) {
post.status = PostStatusPublish;
if (post.status == nil || [post.status isEqualToString:RemotePost.statusScheduled]) {
post.status = RemotePost.statusPublish;
}

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

if (post.isStickyPost != nil && shouldIncludeStickyField) {
postParams[@"sticky"] = post.isStickyPost.boolValue ? @"true" : @"false";
Expand Down
65 changes: 0 additions & 65 deletions WordPressKit/RemotePost.h

This file was deleted.

50 changes: 0 additions & 50 deletions WordPressKit/RemotePost.m

This file was deleted.

82 changes: 82 additions & 0 deletions WordPressKit/RemotePost.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import Foundation
import ObjectiveC

@objcMembers public class RemotePost: NSObject {

public static let statusDraft = "draft"
public static let statusPending = "pending"
public static let statusPrivate = "private"
public static let statusPublish = "publish"
public static let statusScheduled = "future"
public static let statusTrash = "trash"
/// Returned by the WordPress.com REST API when a post is permanently deleted.
public static let statusDeleted = "deleted"

public var postID: NSNumber?
public var siteID: NSNumber?
public var authorAvatarURL: String?
public var authorDisplayName: String?
public var authorEmail: String?
public var authorURL: String?
public var authorID: NSNumber?
public var date: NSDate?
public var dateModified: NSDate?
public var title: String?
public var URL: NSURL?
public var shortURL: NSURL?
public var content: String?
public var excerpt: String?
public var slug: String?
public var suggestedSlug: String?
public var status: String?
public var password: String?
public var parentID: NSNumber?
public var postThumbnailID: NSNumber?
public var postThumbnailPath: String?
public var type: String?
public var format: String?

/**
* A snapshot of the post at the last autosave.
*
* This is nullable.
*/
public var autosave: RemotePostAutosave?

public var commentCount: NSNumber?
public var likeCount: NSNumber?

public var categories: NSArray?
public var revisions: NSArray?
public var tags: NSArray?
public var pathForDisplayImage: String?
public var isStickyPost: NSNumber?
public var isFeaturedImageChanged: Bool = false

/**
Array of custom fields. Each value is a dictionary containing {ID, key, value}
*/
public var metadata: [[String: Any]]?

// Featured images?
// Geolocation?
// Attachments?
// Metadata?

public override init() {
super.init()
}

public init(siteID: NSNumber, status: String, title: String?, content: String?) {
super.init()
self.siteID = siteID
self.status = status
self.title = title
self.content = content
}

public override var debugDescription: String {
"\(super.description) (\(allProperties))"
}
Comment on lines +78 to +80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL debugDescription.

The debugger’s po command uses this property to create a textual representation of the object suitable for display in the debugger. The default implemention [sic] returns the same value as description. Override either property to provide custom object descriptions.


}
7 changes: 0 additions & 7 deletions WordPressKit/RemotePostCategory.h

This file was deleted.

18 changes: 0 additions & 18 deletions WordPressKit/RemotePostCategory.m

This file was deleted.

15 changes: 15 additions & 0 deletions WordPressKit/RemotePostCategory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Foundation

@objcMembers public class RemotePostCategory: NSObject {
public var categoryID: NSNumber?
public var name: String?
public var parentID: NSNumber?

public override var debugDescription: String {
"\(super.description) (\(allProperties))"
}

public override var description: String {
return "\(super.description) \(String(describing: name))[\(String(describing: categoryID))]"
}
}
11 changes: 0 additions & 11 deletions WordPressKit/RemotePostTag.h

This file was deleted.

19 changes: 0 additions & 19 deletions WordPressKit/RemotePostTag.m

This file was deleted.

19 changes: 19 additions & 0 deletions WordPressKit/RemotePostTag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Foundation

@objcMembers public class RemotePostTag: NSObject {

public var tagID: NSNumber?
public var name: String?
public var slug: String?
public var tagDescription: String?
public var postCount: NSNumber?

public override var debugDescription: String {
"\(super.description) (\(allProperties))"
}

public override var description: String {
return "\(super.description) \(String(describing: name))[\(String(describing: tagID))]"
}

}
9 changes: 0 additions & 9 deletions WordPressKit/RemotePostType.h

This file was deleted.

Loading