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

Commit 86234f8

Browse files
committed
Add remaining parameters to RemotePostUpdateParameters
1 parent f186175 commit 86234f8

File tree

6 files changed

+75
-12
lines changed

6 files changed

+75
-12
lines changed

WordPressKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
0152100C28EDA9E400DD6783 /* StatsAnnualAndMostPopularTimeInsightDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0152100B28EDA9E400DD6783 /* StatsAnnualAndMostPopularTimeInsightDecodingTests.swift */; };
1616
0847B92C2A4442730044D32F /* IPLocationRemote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0847B92B2A4442730044D32F /* IPLocationRemote.swift */; };
1717
08C7493E2A45EA11000DA0E2 /* IPLocationRemoteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08C7493D2A45EA11000DA0E2 /* IPLocationRemoteTests.swift */; };
18+
0C1C08382B9B675400E52F8C /* StringCodingKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C1C08372B9B675400E52F8C /* StringCodingKey.swift */; };
1819
0C9CD7992B9A107E0045BE03 /* RemotePostUpdateParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0C9CD7982B9A107E0045BE03 /* RemotePostUpdateParameters.swift */; };
1920
0CB1905E2A2A5E83004D3E80 /* BlazeCampaign.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CB1905D2A2A5E83004D3E80 /* BlazeCampaign.swift */; };
2021
0CB190612A2A6A13004D3E80 /* blaze-campaigns-search.json in Resources */ = {isa = PBXBuildFile; fileRef = 0CB1905F2A2A6943004D3E80 /* blaze-campaigns-search.json */; };
@@ -736,6 +737,7 @@
736737
0152100B28EDA9E400DD6783 /* StatsAnnualAndMostPopularTimeInsightDecodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsAnnualAndMostPopularTimeInsightDecodingTests.swift; sourceTree = "<group>"; };
737738
0847B92B2A4442730044D32F /* IPLocationRemote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPLocationRemote.swift; sourceTree = "<group>"; };
738739
08C7493D2A45EA11000DA0E2 /* IPLocationRemoteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPLocationRemoteTests.swift; sourceTree = "<group>"; };
740+
0C1C08372B9B675400E52F8C /* StringCodingKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringCodingKey.swift; sourceTree = "<group>"; };
739741
0C3A2A412A2E7BA500FD91D6 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
740742
0C9CD7982B9A107E0045BE03 /* RemotePostUpdateParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemotePostUpdateParameters.swift; sourceTree = "<group>"; };
741743
0CB1905D2A2A5E83004D3E80 /* BlazeCampaign.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlazeCampaign.swift; sourceTree = "<group>"; };
@@ -2526,6 +2528,7 @@
25262528
4AE278432B2FAF6200E4D9B1 /* HTTPProtocolHelpers.swift */,
25272529
3F391E192B50F3EB007975C4 /* Result+Callback.swift */,
25282530
4A5BC1A72B59DE6600C7D037 /* Either.swift */,
2531+
0C1C08372B9B675400E52F8C /* StringCodingKey.swift */,
25292532
4A57A6852B54C68C008D0660 /* Constants.h */,
25302533
4A57A6862B54C68C008D0660 /* Constants.m */,
25312534
);
@@ -3464,6 +3467,7 @@
34643467
40819778221F00E600A298E4 /* StatsSummaryTimeIntervalData.swift in Sources */,
34653468
7430C9A81F1927180051B8E6 /* ReaderTopicServiceRemote.m in Sources */,
34663469
17CE77F120C6EB41001DEA5A /* ReaderFeed.swift in Sources */,
3470+
0C1C08382B9B675400E52F8C /* StringCodingKey.swift in Sources */,
34673471
93C674F21EE8351E00BFAF05 /* NSMutableDictionary+Helpers.m in Sources */,
34683472
4624222D2548BA0F002B8A12 /* RemoteSiteDesign.swift in Sources */,
34693473
74D67F061F1528470010C5ED /* PeopleServiceRemote.swift in Sources */,

WordPressKit/PostServiceRemoteREST.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ - (void)patchPostWithID:(NSNumber *)postID
217217
NSString *path = [NSString stringWithFormat:@"sites/%@/posts/%@?context=edit", self.siteID, postID];
218218
NSString *requestUrl = [self pathForEndpoint:path withVersion:ServiceRemoteWordPressComRESTApiVersion_1_2];
219219

220-
NSDictionary *parameters = [postUpdateParameters makeRESTParameters];
220+
NSDictionary *parameters = [postUpdateParameters makeWordPressCOMParameters];
221221

222222
[self.wordPressComRestApi POST:requestUrl
223223
parameters:parameters
@@ -564,9 +564,6 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
564564
// safety net. An existing post with no create date should publish immediately
565565
parameters[@"date"] = [[NSDate date] WordPressComJSONString];
566566
}
567-
if (post.ifNotModifiedSince) {
568-
parameters[@"if_not_modified_since"] = [post.ifNotModifiedSince WordPressComJSONString];
569-
}
570567
if (post.excerpt) {
571568
parameters[@"excerpt"] = post.excerpt;
572569
}

WordPressKit/PostServiceRemoteXMLRPC.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,11 +406,6 @@ - (NSDictionary *)parametersWithRemotePost:(RemotePost *)post
406406
// Pass the current date so the post is updated correctly
407407
postParams[@"date_created_gmt"] = [NSDate date];
408408
}
409-
410-
if (post.ifNotModifiedSince) {
411-
postParams[@"if_not_modified_since"] = post.ifNotModifiedSince;
412-
}
413-
414409
if (post.categories) {
415410
NSArray *categoryNames = [post.categories wp_map:^id(RemotePostCategory *category) {
416411
return category.name;

WordPressKit/RemotePost.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ extern NSString * const PostStatusDeleted;
2121
@property (nonatomic, strong) NSNumber *authorID;
2222
@property (nonatomic, strong) NSDate *date;
2323
@property (nonatomic, strong) NSDate *dateModified;
24-
@property (nonatomic, strong) NSDate *ifNotModifiedSince;
2524
@property (nonatomic, strong) NSString *title;
2625
@property (nonatomic, strong) NSURL *URL;
2726
@property (nonatomic, strong) NSURL *shortURL;

WordPressKit/RemotePostUpdateParameters.swift

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@ import Foundation
33
public final class RemotePostUpdateParameters: NSObject, Encodable {
44
public var ifNotModifiedSince: Date??
55
public var status: String??
6+
public var authorID: String??
67
public var date: Date??
8+
public var title: String??
79
public var content: String??
10+
public var password: String??
11+
public var excerpt: String??
812
public var slug: String??
13+
public var format: String??
14+
public var categoryIDs: [String]?
15+
public var tags: [String]?
16+
public var parentPostID: String??
17+
public var featuredImageID: String??
18+
public var isSticky: Bool?
919

10-
@objc public func makeRESTParameters() -> [String: Any]? {
20+
// Makes it compatible with Objetive-C.
21+
@objc public func makeWordPressCOMParameters() -> [String: Any]? {
1122
let encoder = JSONEncoder()
12-
encoder.keyEncodingStrategy = .convertToSnakeCase
1323
encoder.dateEncodingStrategy = .formatted(NSDate.rfc3339DateFormatter())
1424
guard let data = try? encoder.encode(self),
1525
let object = try? JSONSerialization.jsonObject(with: data) else {
@@ -18,3 +28,34 @@ public final class RemotePostUpdateParameters: NSObject, Encodable {
1828
return object as? [String: Any]
1929
}
2030
}
31+
32+
private struct RemotePostUpdateParametersWordPressComEncoder: Encodable {
33+
let parameters: RemotePostUpdateParameters
34+
35+
func encode(to encoder: Encoder) throws {
36+
var container = encoder.container(keyedBy: StringCodingKey.self)
37+
try container.encodeIfPresent(parameters.ifNotModifiedSince, forKey: "if_not_modified_since")
38+
try container.encodeIfPresent(parameters.status, forKey: "status")
39+
try container.encodeIfPresent(parameters.title, forKey: "title")
40+
try container.encodeIfPresent(parameters.content, forKey: "content")
41+
try container.encodeIfPresent(parameters.date, forKey: "date")
42+
try container.encodeIfPresent(parameters.authorID, forKey: "author")
43+
try container.encodeIfPresent(parameters.password, forKey: "password")
44+
try container.encodeIfPresent(parameters.excerpt, forKey: "excerpt")
45+
try container.encodeIfPresent(parameters.slug, forKey: "slug")
46+
try container.encodeIfPresent(parameters.categoryIDs, forKey: "categories_by_id")
47+
if let tags = parameters.tags {
48+
try container.encode([
49+
"terms": [
50+
"post_tag": tags
51+
]
52+
], forKey: "terms")
53+
}
54+
try container.encodeIfPresent(parameters.format, forKey: "format")
55+
if let parentPostID = parameters.parentPostID {
56+
try container.encodeIfPresent(parentPostID ?? "false", forKey: "parent")
57+
}
58+
try container.encodeIfPresent(parameters.featuredImageID, forKey: "featured_image")
59+
try container.encodeIfPresent(parameters.isSticky, forKey: "sticky")
60+
}
61+
}

WordPressKit/StringCodingKey.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import Foundation
2+
3+
struct StringCodingKey: CodingKey, ExpressibleByStringLiteral {
4+
private let string: String
5+
private var int: Int?
6+
7+
var stringValue: String { return string }
8+
9+
init(string: String) {
10+
self.string = string
11+
}
12+
13+
init?(stringValue: String) {
14+
self.string = stringValue
15+
}
16+
17+
var intValue: Int? { return int }
18+
19+
init?(intValue: Int) {
20+
self.string = String(describing: intValue)
21+
self.int = intValue
22+
}
23+
24+
init(stringLiteral value: String) {
25+
self.string = value
26+
}
27+
}

0 commit comments

Comments
 (0)