@@ -2,6 +2,8 @@ import Foundation
22
33/// The parameters required to create a post or a page.
44public struct RemotePostCreateParameters : Equatable {
5+ public var type : String
6+
57 public var status : String
68 public var date : Date ?
79 public var authorID : Int ?
@@ -21,7 +23,8 @@ public struct RemotePostCreateParameters: Equatable {
2123 public var tags : [ String ] = [ ]
2224 public var categoryIDs : [ Int ] = [ ]
2325
24- public init ( status: String ) {
26+ public init ( type: String , status: String ) {
27+ self . type = type
2528 self . status = status
2629 }
2730}
@@ -155,6 +158,7 @@ extension RemotePostCreateParameters {
155158
156159private enum RemotePostWordPressComCodingKeys : String , CodingKey {
157160 case ifNotModifiedSince = " if_not_modified_since "
161+ case type
158162 case status
159163 case date
160164 case authorID = " author "
@@ -178,6 +182,7 @@ struct RemotePostCreateParametersWordPressComEncoder: Encodable {
178182
179183 func encode( to encoder: Encoder ) throws {
180184 var container = encoder. container ( keyedBy: RemotePostWordPressComCodingKeys . self)
185+ try container. encodeIfPresent ( parameters. type, forKey: . type)
181186 try container. encodeIfPresent ( parameters. status, forKey: . status)
182187 try container. encodeIfPresent ( parameters. date, forKey: . date)
183188 try container. encodeIfPresent ( parameters. authorID, forKey: . authorID)
@@ -243,8 +248,8 @@ struct RemotePostUpdateParametersWordPressComEncoder: Encodable {
243248
244249private enum RemotePostXMLRPCCodingKeys : String , CodingKey {
245250 case ifNotModifiedSince = " if_not_modified_since "
251+ case type = " post_type "
246252 case postStatus = " post_status "
247- case pageStatus = " page_status "
248253 case date = " date_created_gmt "
249254 case authorID = " wp_author_id "
250255 case title
@@ -262,22 +267,13 @@ private enum RemotePostXMLRPCCodingKeys: String, CodingKey {
262267 static let postTags = " post_tag "
263268}
264269
265- enum RemotePostEncodingPostType {
266- case post, page
267- }
268-
269270struct RemotePostCreateParametersXMLRPCEncoder : Encodable {
270271 let parameters : RemotePostCreateParameters
271- let type : RemotePostEncodingPostType
272272
273273 func encode( to encoder: Encoder ) throws {
274274 var container = encoder. container ( keyedBy: RemotePostXMLRPCCodingKeys . self)
275- switch type {
276- case . post:
277- try container. encodeIfPresent ( parameters. status, forKey: . postStatus)
278- case . page:
279- try container. encodeIfPresent ( parameters. status, forKey: . pageStatus)
280- }
275+ try container. encode ( parameters. type, forKey: . type)
276+ try container. encodeIfPresent ( parameters. status, forKey: . postStatus)
281277 try container. encodeIfPresent ( parameters. date, forKey: . date)
282278 try container. encodeIfPresent ( parameters. authorID, forKey: . authorID)
283279 try container. encodeIfPresent ( parameters. title, forKey: . title)
@@ -308,17 +304,11 @@ struct RemotePostCreateParametersXMLRPCEncoder: Encodable {
308304
309305struct RemotePostUpdateParametersXMLRPCEncoder : Encodable {
310306 let parameters : RemotePostUpdateParameters
311- let type : RemotePostEncodingPostType
312307
313308 func encode( to encoder: Encoder ) throws {
314309 var container = encoder. container ( keyedBy: RemotePostXMLRPCCodingKeys . self)
315310 try container. encodeIfPresent ( parameters. ifNotModifiedSince, forKey: . ifNotModifiedSince)
316- switch type {
317- case . post:
318- try container. encodeIfPresent ( parameters. status, forKey: . postStatus)
319- case . page:
320- try container. encodeIfPresent ( parameters. status, forKey: . pageStatus)
321- }
311+ try container. encodeIfPresent ( parameters. status, forKey: . postStatus)
322312 try container. encodeIfPresent ( parameters. date, forKey: . date)
323313 try container. encodeIfPresent ( parameters. authorID, forKey: . authorID)
324314 try container. encodeIfPresent ( parameters. title, forKey: . title)
0 commit comments