Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions native/swift/Example/Example/ExampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Combine

private let userListParams = UserListParams(perPage: 5)
private let postListParams = PostListParams(perPage: 5)
private let mediaListParams = MediaListParams(perPage: 5)

@main
struct ExampleApp: App {
Expand Down Expand Up @@ -35,6 +36,10 @@ struct ExampleApp: App {
let sequence = try WordPressAPI.globalInstance.posts.sequenceWithEditContext(params: postListParams)
return ListViewSequence(underlyingSequence: sequence)
}),
RootListData(name: "Media", sequence: {
let sequence = try WordPressAPI.globalInstance.media.sequenceWithEditContext(params: mediaListParams)
return ListViewSequence(underlyingSequence: sequence)
}),
RootListData(name: "Site Health Tests", callback: {
let items: [any ListViewDataConvertable] = [
try await WordPressAPI.globalInstance.siteHealthTests.authorizationHeader().data,
Expand Down
16 changes: 16 additions & 0 deletions native/swift/Example/Example/ListViewData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,28 @@ extension PostWithEditContext: ListViewDataConvertable {
}
}

extension MediaWithEditContext: @retroactive Identifiable, ListViewDataConvertable {
public var id: String {
self.slug
}

var asListViewData: ListViewData {
ListViewData(id: self.id, title: self.title.raw, subtitle: String(describing: self.mediaDetails), fields: [:])
}
}

extension [PostWithEditContext] {
func asListViewData() -> [ListViewData] {
self.map { $0.asListViewData }
}
}

extension [MediaWithEditContext] {
func asListViewData() -> [ListViewData] {
self.map { $0.asListViewData }
}
}

extension [ListViewDataConvertable] {
func asListViewData() -> [ListViewData] {
self.map { $0.asListViewData }
Expand Down
12 changes: 12 additions & 0 deletions native/swift/Sources/wordpress-api/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ public typealias PostsRequestListWithEditContextResponse = WordPressAPIInternal.
public typealias PostsRequestListWithViewContextResponse = WordPressAPIInternal.PostsRequestListWithViewContextResponse
public typealias PostsRequestListWithEmbedContextResponse = WordPressAPIInternal.PostsRequestListWithEmbedContextResponse

// MARK: - Media
public typealias SparseMedia = WordPressAPIInternal.SparseMedia
public typealias MediaWithEditContext = WordPressAPIInternal.MediaWithEditContext
public typealias MediaWithViewContext = WordPressAPIInternal.MediaWithViewContext
public typealias MediaWithEmbedContext = WordPressAPIInternal.MediaWithEmbedContext
public typealias MediaListParams = WordPressAPIInternal.MediaListParams
public typealias MediaRequestExecutor = WordPressAPIInternal.MediaRequestExecutor

public typealias MediaRequestListWithEditContextResponse = WordPressAPIInternal.MediaRequestListWithEditContextResponse
public typealias MediaRequestListWithViewContextResponse = WordPressAPIInternal.MediaRequestListWithViewContextResponse
public typealias MediaRequestListWithEmbedContextResponse = WordPressAPIInternal.MediaRequestListWithEmbedContextResponse

// MARK: – Site Settings
public typealias SparseSiteSettings = WordPressAPIInternal.SparseSiteSettings
public typealias SiteSettingsWithEditContext = WordPressAPIInternal.SiteSettingsWithEditContext
Expand Down
22 changes: 22 additions & 0 deletions native/swift/Sources/wordpress-api/Pagination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,28 @@ extension PostsRequestExecutor: PaginationAwareExecutor {
public typealias EmbedContextResponseType = PostsRequestListWithEmbedContextResponse
}

// MARK: - Media
extension MediaRequestListWithEditContextResponse: PaginatableResponse, @unchecked Sendable {
public typealias ParamsType = MediaListParams
public typealias DataType = MediaWithEditContext
}

extension MediaRequestListWithViewContextResponse: PaginatableResponse, @unchecked Sendable {
public typealias ParamsType = MediaListParams
public typealias DataType = MediaWithViewContext
}

extension MediaRequestListWithEmbedContextResponse: PaginatableResponse, @unchecked Sendable {
public typealias ParamsType = MediaListParams
public typealias DataType = MediaWithEmbedContext
}

extension MediaRequestExecutor: PaginationAwareExecutor {
public typealias EditContextResponseType = MediaRequestListWithEditContextResponse
public typealias ViewContextResponseType = MediaRequestListWithViewContextResponse
public typealias EmbedContextResponseType = MediaRequestListWithEmbedContextResponse
}

// MARK: - Users
extension UsersRequestListWithEditContextResponse: PaginatableResponse, @unchecked Sendable {
public typealias ParamsType = UserListParams
Expand Down
4 changes: 4 additions & 0 deletions native/swift/Sources/wordpress-api/WordPressAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public struct WordPressAPI {
self.requestBuilder.posts()
}

public var media: MediaRequestExecutor {
self.requestBuilder.media()
}

public var siteSettings: SiteSettingsRequestExecutor {
self.requestBuilder.siteSettings()
}
Expand Down
4 changes: 4 additions & 0 deletions native/swift/Tests/wordpress-api/SendableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import WordPressAPI
struct SendableTests {

private static let sendables: [Sendable] = [
MediaRequestListWithEditContextResponse.empty,
MediaRequestListWithViewContextResponse.empty,
MediaRequestListWithEmbedContextResponse.empty,

PostsRequestListWithEditContextResponse.empty,
PostsRequestListWithViewContextResponse.empty,
PostsRequestListWithEmbedContextResponse.empty,
Expand Down