Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline Mode: Fix encoding for some fields in the new XMLRPC endpoints #786

Merged
merged 2 commits into from
Apr 16, 2024
Merged
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
23 changes: 15 additions & 8 deletions Sources/WordPressKit/Models/RemotePostParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public struct RemotePostUpdateParameters: Equatable {
public var ifNotModifiedSince: Date?

public var status: String?
public var date: Date??
public var authorID: Int??
public var date: Date?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't remove any of these two fields on existing posts.

public var authorID: Int?
public var title: String??
public var content: String??
public var password: String??
Expand Down Expand Up @@ -396,11 +396,11 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
try container.encodeIfPresent(parameters.status, forKey: .postStatus)
try container.encodeIfPresent(parameters.date, forKey: .date)
try container.encodeIfPresent(parameters.authorID, forKey: .authorID)
try container.encodeIfPresent(parameters.title, forKey: .title)
try container.encodeIfPresent(parameters.content, forKey: .content)
try container.encodeIfPresent(parameters.password, forKey: .password)
try container.encodeIfPresent(parameters.excerpt, forKey: .excerpt)
try container.encodeIfPresent(parameters.slug, forKey: .slug)
try container.encodeStringIfPresent(parameters.title, forKey: .title)
try container.encodeStringIfPresent(parameters.content, forKey: .content)
try container.encodeStringIfPresent(parameters.password, forKey: .password)
try container.encodeStringIfPresent(parameters.excerpt, forKey: .excerpt)
try container.encodeStringIfPresent(parameters.slug, forKey: .slug)
if let value = parameters.featuredImageID {
if let featuredImageID = value {
try container.encode(featuredImageID, forKey: .featuredImageID)
Expand All @@ -420,7 +420,7 @@ struct RemotePostUpdateParametersXMLRPCEncoder: Encodable {
}

// Posts
try container.encodeIfPresent(parameters.format, forKey: .format)
try container.encodeStringIfPresent(parameters.format, forKey: .format)
if let tags = parameters.tags {
try container.encode(tags, forKey: .tags)
}
Expand All @@ -440,3 +440,10 @@ struct RemotePostUpdateParametersXMLRPCMetadata: Encodable {
self.value = item.value
}
}

private extension KeyedEncodingContainer {
mutating func encodeStringIfPresent(_ value: String??, forKey key: Key) throws {
guard let value else { return }
try encode(value ?? "", forKey: key)
}
}