@@ -20,11 +20,11 @@ import WordPressAPI
20
20
public func createCategory( _ category: RemotePostCategory , success: ( ( RemotePostCategory ) -> Void ) ? , failure: ( ( any Error ) -> Void ) ? = nil ) {
21
21
Task { @MainActor in
22
22
do {
23
- let params = CategoryCreateParams (
23
+ let params = TermCreateParams (
24
24
name: category. name ?? " " ,
25
25
parent: category. parentID? . int64Value
26
26
)
27
- let response = try await client. api. categories . create ( params: params)
27
+ let response = try await client. api. terms . create ( termEndpointType : . categories , params: params)
28
28
let remoteCategory = RemotePostCategory ( category: response. data)
29
29
success ? ( remoteCategory)
30
30
} catch {
@@ -36,7 +36,10 @@ import WordPressAPI
36
36
public func getCategoriesWithSuccess( _ success: @escaping ( [ RemotePostCategory ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
37
37
Task { @MainActor in
38
38
do {
39
- let sequence = await client. api. categories. sequenceWithEditContext ( params: CategoryListParams ( perPage: 100 ) )
39
+ let sequence = await client. api. terms. sequenceWithEditContext (
40
+ type: . categories,
41
+ params: TermListParams ( perPage: 100 )
42
+ )
40
43
let categories : [ RemotePostCategory ] = try await sequence. reduce ( into: [ ] ) {
41
44
let page = $1. map ( RemotePostCategory . init ( category: ) )
42
45
$0. append ( contentsOf: page)
@@ -51,14 +54,17 @@ import WordPressAPI
51
54
public func getCategoriesWith( _ paging: RemoteTaxonomyPaging , success: @escaping ( [ RemotePostCategory ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
52
55
Task { @MainActor in
53
56
do {
54
- let params = CategoryListParams (
57
+ let params = TermListParams (
55
58
page: paging. page? . uint32Value,
56
59
perPage: paging. number? . uint32Value,
57
60
offset: paging. offset? . uint32Value,
58
- order: . init( paging. order) ,
59
- orderby: . init( paging. orderBy)
61
+ order: WpApiParamOrder ( paging. order) ,
62
+ orderby: WpApiParamTermsOrderBy ( paging. orderBy)
63
+ )
64
+ let response = try await client. api. terms. listWithEditContext (
65
+ termEndpointType: . categories,
66
+ params: params
60
67
)
61
- let response = try await client. api. categories. listWithEditContext ( params: params)
62
68
let categories = response. data. map ( RemotePostCategory . init ( category: ) )
63
69
success ( categories)
64
70
} catch {
@@ -70,8 +76,11 @@ import WordPressAPI
70
76
public func searchCategories( withName nameQuery: String , success: @escaping ( [ RemotePostCategory ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
71
77
Task { @MainActor in
72
78
do {
73
- let params = CategoryListParams ( search: nameQuery)
74
- let response = try await client. api. categories. listWithEditContext ( params: params)
79
+ let params = TermListParams ( search: nameQuery)
80
+ let response = try await client. api. terms. listWithEditContext (
81
+ termEndpointType: . categories,
82
+ params: params
83
+ )
75
84
let categories = response. data. map ( RemotePostCategory . init ( category: ) )
76
85
success ( categories)
77
86
} catch {
@@ -83,12 +92,15 @@ import WordPressAPI
83
92
public func createTag( _ tag: RemotePostTag , success: ( ( RemotePostTag ) -> Void ) ? , failure: ( ( any Error ) -> Void ) ? = nil ) {
84
93
Task { @MainActor in
85
94
do {
86
- let params = TagCreateParams (
95
+ let params = TermCreateParams (
87
96
name: tag. name ?? " " ,
88
97
description: tag. tagDescription,
89
98
slug: tag. slug
90
99
)
91
- let response = try await client. api. tags. create ( params: params)
100
+ let response = try await client. api. terms. create (
101
+ termEndpointType: . tags,
102
+ params: params
103
+ )
92
104
let remoteTag = RemotePostTag ( tag: response. data)
93
105
success ? ( remoteTag)
94
106
} catch {
@@ -105,12 +117,16 @@ import WordPressAPI
105
117
106
118
Task { @MainActor in
107
119
do {
108
- let params = TagUpdateParams (
120
+ let params = TermUpdateParams (
109
121
name: tag. name,
110
122
description: tag. tagDescription,
111
123
slug: tag. slug
112
124
)
113
- let response = try await client. api. tags. update ( tagId: TagId ( tagID. int64Value) , params: params)
125
+ let response = try await client. api. terms. update (
126
+ termEndpointType: . tags,
127
+ termId: tagID. int64Value,
128
+ params: params
129
+ )
114
130
let remoteTag = RemotePostTag ( tag: response. data)
115
131
success ? ( remoteTag)
116
132
} catch {
@@ -127,7 +143,7 @@ import WordPressAPI
127
143
128
144
Task { @MainActor in
129
145
do {
130
- let _ = try await client. api. tags . delete ( tagId : TagId ( tagID. int64Value) )
146
+ let _ = try await client. api. terms . delete ( termEndpointType : . tags , termId : tagID. int64Value)
131
147
success ? ( )
132
148
} catch {
133
149
failure ? ( error)
@@ -138,7 +154,10 @@ import WordPressAPI
138
154
public func getTagsWithSuccess( _ success: @escaping ( [ RemotePostTag ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
139
155
Task { @MainActor in
140
156
do {
141
- let response = try await client. api. tags. listWithEditContext ( params: TagListParams ( ) )
157
+ let response = try await client. api. terms. listWithEditContext (
158
+ termEndpointType: . tags,
159
+ params: TermListParams ( )
160
+ )
142
161
let tags = response. data. map ( RemotePostTag . init ( tag: ) )
143
162
success ( tags)
144
163
} catch {
@@ -150,14 +169,17 @@ import WordPressAPI
150
169
public func getTagsWith( _ paging: RemoteTaxonomyPaging , success: @escaping ( [ RemotePostTag ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
151
170
Task { @MainActor in
152
171
do {
153
- let params = TagListParams (
172
+ let params = TermListParams (
154
173
page: paging. page? . uint32Value,
155
174
perPage: paging. number? . uint32Value,
156
175
offset: paging. offset? . uint32Value,
157
- order: . init( paging. order) ,
158
- orderby: . init( paging. orderBy)
176
+ order: WpApiParamOrder ( paging. order) ,
177
+ orderby: WpApiParamTermsOrderBy ( paging. orderBy)
178
+ )
179
+ let response = try await client. api. terms. listWithEditContext (
180
+ termEndpointType: . tags,
181
+ params: params
159
182
)
160
- let response = try await client. api. tags. listWithEditContext ( params: params)
161
183
let tags = response. data. map ( RemotePostTag . init ( tag: ) )
162
184
success ( tags)
163
185
} catch {
@@ -169,7 +191,10 @@ import WordPressAPI
169
191
public func searchTags( withName nameQuery: String , success: @escaping ( [ RemotePostTag ] ) -> Void , failure: ( ( any Error ) -> Void ) ? = nil ) {
170
192
Task { @MainActor in
171
193
do {
172
- let response = try await client. api. tags. listWithEditContext ( params: TagListParams ( search: nameQuery) )
194
+ let response = try await client. api. terms. listWithEditContext (
195
+ termEndpointType: . tags,
196
+ params: TermListParams ( search: nameQuery)
197
+ )
173
198
let tags = response. data. map ( RemotePostTag . init ( tag: ) )
174
199
success ( tags)
175
200
} catch {
@@ -180,16 +205,16 @@ import WordPressAPI
180
205
}
181
206
182
207
private extension RemotePostCategory {
183
- convenience init ( category: CategoryWithEditContext ) {
208
+ convenience init ( category: AnyTermWithEditContext ) {
184
209
self . init ( )
185
210
self . categoryID = NSNumber ( value: category. id)
186
211
self . name = category. name
187
- self . parentID = NSNumber ( value: category. parent)
212
+ self . parentID = NSNumber ( value: category. parent ?? 0 )
188
213
}
189
214
}
190
215
191
216
private extension RemotePostTag {
192
- convenience init ( tag: TagWithEditContext ) {
217
+ convenience init ( tag: AnyTermWithEditContext ) {
193
218
self . init ( )
194
219
self . tagID = NSNumber ( value: tag. id)
195
220
self . name = tag. name
@@ -212,20 +237,7 @@ private extension WpApiParamOrder {
212
237
}
213
238
}
214
239
215
- private extension WpApiParamCategoriesOrderBy {
216
- init ( _ other: RemoteTaxonomyPagingResultsOrdering ) {
217
- switch other {
218
- case . byName:
219
- self = . name
220
- case . byCount:
221
- self = . count
222
- @unknown default :
223
- self = . name
224
- }
225
- }
226
- }
227
-
228
- private extension WpApiParamTagsOrderBy {
240
+ private extension WpApiParamTermsOrderBy {
229
241
init ( _ other: RemoteTaxonomyPagingResultsOrdering ) {
230
242
switch other {
231
243
case . byName:
0 commit comments