Skip to content

Commit f43f8e6

Browse files
authored
/pages endpoints (#885)
1 parent 9b35706 commit f43f8e6

File tree

21 files changed

+2178
-11
lines changed

21 files changed

+2178
-11
lines changed

native/swift/Example/Example/ExampleApp.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Combine
44

55
private let userListParams = UserListParams(perPage: 5)
66
private let postListParams = PostListParams(perPage: 5)
7+
private let pageListParams = PageListParams(perPage: 5)
78
private let mediaListParams = MediaListParams(perPage: 5)
89

910
@main
@@ -38,6 +39,10 @@ struct ExampleApp: App {
3839
let sequence = try await WordPressAPI.globalInstance.posts.sequenceWithEditContext(params: postListParams)
3940
return ListViewSequence(underlyingSequence: sequence)
4041
}),
42+
RootListData(name: "Pages", sequence: {
43+
let sequence = try await WordPressAPI.globalInstance.pages.sequenceWithEditContext(params: pageListParams)
44+
return ListViewSequence(underlyingSequence: sequence)
45+
}),
4146
RootListData(name: "Media", sequence: {
4247
let sequence = try await WordPressAPI.globalInstance.media.sequenceWithEditContext(params: mediaListParams)
4348
return ListViewSequence(underlyingSequence: sequence)

native/swift/Example/Example/ListViewData.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ extension PostWithEditContext: ListViewDataConvertable {
137137
}
138138
}
139139

140+
extension PageWithEditContext: ListViewDataConvertable {
141+
var asListViewData: ListViewData {
142+
ListViewData(id: self.slug, title: self.title.rendered, subtitle: "", fields: [:])
143+
}
144+
}
145+
140146
extension MediaWithEditContext: ListViewDataConvertable {
141147
var asListViewData: ListViewData {
142148
let details = self.mediaDetails.parseAsMimeType(mimeType: self.mimeType)

native/swift/Sources/wordpress-api/Exports.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ public typealias PostsRequestListWithEditContextResponse = WordPressAPIInternal.
105105
public typealias PostsRequestListWithViewContextResponse = WordPressAPIInternal.PostsRequestListWithViewContextResponse
106106
public typealias PostsRequestListWithEmbedContextResponse = WordPressAPIInternal.PostsRequestListWithEmbedContextResponse
107107

108+
// MARK: - Pages
109+
public typealias SparsePage = WordPressAPIInternal.SparsePage
110+
public typealias PageWithEditContext = WordPressAPIInternal.PageWithEditContext
111+
public typealias PageWithViewContext = WordPressAPIInternal.PageWithViewContext
112+
public typealias PageWithEmbedContext = WordPressAPIInternal.PageWithEmbedContext
113+
public typealias PageListParams = WordPressAPIInternal.PageListParams
114+
public typealias PagesRequestExecutor = WordPressAPIInternal.PagesRequestExecutor
115+
116+
public typealias PagesRequestListWithEditContextResponse = WordPressAPIInternal.PagesRequestListWithEditContextResponse
117+
public typealias PagesRequestListWithViewContextResponse = WordPressAPIInternal.PagesRequestListWithViewContextResponse
118+
public typealias PagesRequestListWithEmbedContextResponse = WordPressAPIInternal.PagesRequestListWithEmbedContextResponse
119+
108120
// MARK: - Media
109121
public typealias SparseMedia = WordPressAPIInternal.SparseMedia
110122
public typealias MediaUploadRequest = WordPressAPIInternal.MediaUploadRequest

native/swift/Sources/wordpress-api/Pagination.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ extension PostsRequestExecutor: PaginationAwareExecutor {
205205
public typealias EmbedContextResponseType = PostsRequestListWithEmbedContextResponse
206206
}
207207

208+
// MARK: - Pages
209+
extension PagesRequestListWithEditContextResponse: PaginatableResponse {
210+
public typealias ParamsType = PageListParams
211+
public typealias DataType = PageWithEditContext
212+
}
213+
214+
extension PagesRequestListWithViewContextResponse: PaginatableResponse {
215+
public typealias ParamsType = PageListParams
216+
public typealias DataType = PageWithViewContext
217+
}
218+
219+
extension PagesRequestListWithEmbedContextResponse: PaginatableResponse {
220+
public typealias ParamsType = PageListParams
221+
public typealias DataType = PageWithEmbedContext
222+
}
223+
224+
extension PagesRequestExecutor: PaginationAwareExecutor {
225+
public typealias EditContextResponseType = PagesRequestListWithEditContextResponse
226+
public typealias ViewContextResponseType = PagesRequestListWithViewContextResponse
227+
public typealias EmbedContextResponseType = PagesRequestListWithEmbedContextResponse
228+
}
229+
208230
// MARK: - Media
209231
extension MediaRequestListWithEditContextResponse: PaginatableResponse, @unchecked Sendable {
210232
public typealias ParamsType = MediaListParams

native/swift/Sources/wordpress-api/WordPressAPI.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public actor WordPressAPI {
117117
self.requestBuilder.posts()
118118
}
119119

120+
public var pages: PagesRequestExecutor {
121+
self.requestBuilder.pages()
122+
}
123+
120124
public var comments: CommentsRequestExecutor {
121125
self.requestBuilder.comments()
122126
}

scripts/setup-test-site.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ create_test_credentials () {
131131
PASSWORD_PROTECTED_POST_ID="$(wp post create --post_type=post --post_password=INTEGRATION_TEST --post_title=Password_Protected --porcelain)"
132132
TRASHED_POST_ID="$(wp post create --post_type=post --post_title=Trashed_Post --porcelain)"
133133

134+
# Create test pages
135+
PASSWORD_PROTECTED_PAGE_ID="$(wp post create --post_type=page --post_password=INTEGRATION_TEST --post_title=Password_Protected_Page --porcelain)"
136+
TRASHED_PAGE_ID="$(wp post create --post_type=page --post_title=Trashed_Page --porcelain)"
137+
FIRST_PAGE_ID="$(wp post list --post_type=page --posts_per_page=1 --orderby=ID --order=ASC --format=ids)"
138+
134139
PASSWORD_PROTECTED_COMMENT_AUTHOR="setup-test-site.sh"
135140
PASSWORD_PROTECTED_COMMENT_ID="$(wp comment create --comment_post_ID="$PASSWORD_PROTECTED_POST_ID" --comment_content="test_comment_for_password_protected_post" --comment_author="$PASSWORD_PROTECTED_COMMENT_AUTHOR" --porcelain)"
136141

@@ -140,8 +145,9 @@ create_test_credentials () {
140145

141146
INTEGRATION_TEST_CUSTOM_TEMPLATE_SLUG="integration_test_custom_template"
142147

143-
# Trash the post
148+
# Trash the post and page
144149
wp post delete "$TRASHED_POST_ID"
150+
wp post delete "$TRASHED_PAGE_ID"
145151

146152
echo "Creating a custom template for integration tests.."
147153
curl --silent --user "$ADMIN_USERNAME":"$ADMIN_PASSWORD" -H "Content-Type: application/json" -d '{"slug":"INTEGRATION_TEST_CUSTOM_TEMPLATE", "content": "Integration test custom template content"}' http://localhost/wp-json/wp/v2/templates > /dev/null
@@ -193,6 +199,11 @@ create_test_credentials () {
193199
revision_id_for_revisioned_post_id="$REVISION_ID_FOR_REVISIONED_POST_ID" \
194200
autosaved_post_id="$AUTOSAVED_POST_ID" \
195201
autosave_id_for_autosaved_post_id="$AUTOSAVE_ID_FOR_AUTOSAVED_POST_ID" \
202+
password_protected_page_id="$PASSWORD_PROTECTED_PAGE_ID" \
203+
password_protected_page_password="INTEGRATION_TEST" \
204+
password_protected_page_title="Password_Protected_Page" \
205+
trashed_page_id="$TRASHED_PAGE_ID" \
206+
first_page_id="$FIRST_PAGE_ID" \
196207
> /app/test_credentials.json
197208
}
198209
create_test_credentials

wp_api/src/api_client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
categories_endpoint::{CategoriesRequestBuilder, CategoriesRequestExecutor},
1414
comments_endpoint::{CommentsRequestBuilder, CommentsRequestExecutor},
1515
media_endpoint::{MediaRequestBuilder, MediaRequestExecutor},
16+
pages_endpoint::{PagesRequestBuilder, PagesRequestExecutor},
1617
plugins_endpoint::{PluginsRequestBuilder, PluginsRequestExecutor},
1718
post_autosaves_endpoint::{AutosavesRequestBuilder, AutosavesRequestExecutor},
1819
post_revisions_endpoint::{PostRevisionsRequestBuilder, PostRevisionsRequestExecutor},
@@ -59,6 +60,7 @@ pub struct WpApiRequestBuilder {
5960
categories: Arc<CategoriesRequestBuilder>,
6061
comments: Arc<CommentsRequestBuilder>,
6162
media: Arc<MediaRequestBuilder>,
63+
pages: Arc<PagesRequestBuilder>,
6264
plugins: Arc<PluginsRequestBuilder>,
6365
post_revisions: Arc<PostRevisionsRequestBuilder>,
6466
post_types: Arc<PostTypesRequestBuilder>,
@@ -88,6 +90,7 @@ impl WpApiRequestBuilder {
8890
categories,
8991
comments,
9092
media,
93+
pages,
9194
plugins,
9295
post_revisions,
9396
post_types,
@@ -127,6 +130,7 @@ pub struct WpApiClient {
127130
categories: Arc<CategoriesRequestExecutor>,
128131
comments: Arc<CommentsRequestExecutor>,
129132
media: Arc<MediaRequestExecutor>,
133+
pages: Arc<PagesRequestExecutor>,
130134
plugins: Arc<PluginsRequestExecutor>,
131135
post_revisions: Arc<PostRevisionsRequestExecutor>,
132136
post_types: Arc<PostTypesRequestExecutor>,
@@ -153,6 +157,7 @@ impl WpApiClient {
153157
categories,
154158
comments,
155159
media,
160+
pages,
156161
plugins,
157162
post_revisions,
158163
post_types,
@@ -189,6 +194,7 @@ api_client_generate_endpoint_impl!(WpApi, autosaves);
189194
api_client_generate_endpoint_impl!(WpApi, categories);
190195
api_client_generate_endpoint_impl!(WpApi, comments);
191196
api_client_generate_endpoint_impl!(WpApi, media);
197+
api_client_generate_endpoint_impl!(WpApi, pages);
192198
api_client_generate_endpoint_impl!(WpApi, plugins);
193199
api_client_generate_endpoint_impl!(WpApi, post_revisions);
194200
api_client_generate_endpoint_impl!(WpApi, post_types);

wp_api/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub mod date;
1919
pub mod login;
2020
pub mod media;
2121
pub mod middleware;
22+
pub mod pages;
2223
pub mod parsed_url;
2324
pub mod plugins;
2425
pub mod post_revisions;

0 commit comments

Comments
 (0)