Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
  •  
  •  
  •  
38 changes: 34 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.1

import PackageDescription

Expand All @@ -8,11 +8,41 @@ let package = Package(
products: [
.library(name: "WordPressKit", targets: ["WordPressKit"]),
],
dependencies: [
.package(url: "https://github.com/wordpress-mobile/NSObject-SafeExpectations", from: "0.0.6"),
.package(url: "https://github.com/wordpress-mobile/wpxmlrpc", from: "0.9.0"),
],
targets: [
.binaryTarget(
.target(
name: "WordPressKitObjCUtils",
),
.target(
name: "WordPressKitModels",
dependencies: [
"NSObject-SafeExpectations",
"WordPressKitObjCUtils",
]
),
.target(
name: "WordPressKitObjC",
dependencies: [
"NSObject-SafeExpectations",
"wpxmlrpc",
"WordPressKitModels",
"WordPressKitObjCUtils",
],
publicHeadersPath: "include"
),
.target(
name: "WordPressKit",
url: "https://github.com/user-attachments/files/21582269/WordPressKit.zip",
checksum: "cbfe79d7a4244302d308027ff329f1ccdfd1c604d990871359764eca567ea86f"
dependencies: [
"WordPressKitObjC",
"WordPressKitModels",
"WordPressKitObjCUtils",
"NSObject-SafeExpectations",
"wpxmlrpc",
],
swiftSettings: [.swiftLanguageMode(.v5)]
),
]
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class AccountSettingsRemote: ServiceRemoteWordPressComREST {
@objc public static let remotes = NSMapTable<AnyObject, AnyObject>(keyOptions: NSPointerFunctions.Options(), valueOptions: NSPointerFunctions.Options.weakMemory)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitModels

public struct Activity: Decodable {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

open class ActivityServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Foundation
import WordPressKitObjC

@objc public class ActivityServiceRemote_ApiVersion1_0: ServiceRemoteWordPressComREST {

public enum ResponseError: Error {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

/// Retrieves feature announcements from the related endpoint
open class AnnouncementServiceRemote: ServiceRemoteWordPressComREST {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST {
/// - parameter scrollID: Pass the scroll ID from the previous response to
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

/// Class encapsualting all requests related to performing Automated Transfer operations.
public class AutomatedTransferService: ServiceRemoteWordPressComREST {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

open class BlazeServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Foundation
import WordPressKitObjC

/// Encapsulates logic to fetch blogging prompts from the remote endpoint.
///
open class BloggingPromptsServiceRemote: ServiceRemoteWordPressComREST {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
public extension CommentServiceRemoteREST {
/// Lists the available keys for the request parameter.
enum RequestKeys: String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
open func fetch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
struct JSONCodingKeys: CodingKey {
var stringValue: String

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

/// Allows the construction of a request for domain suggestions.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class EditorServiceRemote: ServiceRemoteWordPressComREST {
public func postDesignateMobileEditor(_ siteID: Int, editor: EditorSettings.Mobile, success: @escaping (EditorSettings) -> Void, failure: @escaping (Error) -> Void) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
private struct RemoteEditorSettings: Codable {
let editorMobile: String
let editorWeb: String
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
/// Allows automatic defaulting to `unknown` for any Enum that conforms to `UnknownCaseRepresentable`
/// Credits: https://www.latenightswift.com/2019/02/04/unknown-enum-cases/
protocol UnknownCaseRepresentable: RawRepresentable, CaseIterable where RawValue: Equatable {
Expand Down
15 changes: 15 additions & 0 deletions Sources/WordPressKit/Exports.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@_exported import WordPressKitModels
@_exported import WordPressKitObjC
@_exported import WordPressKitObjCUtils

extension ServiceRemoteWordPressComREST {
public var wordPressComRestApi: WordPressComRestApi {
self.wordPressComRESTAPI as! WordPressComRestApi
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have to use an interface type in the ServiceRemoteWordPressComREST.h, because the implementation is in the Swift WordPressKit module.

In practice, WordPressComRestApi is the only acceptable instance to create ServiceRemoteWordPressComREST, so, we'll do a little bit hack here to force cast in runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as the WordPressOrgXMLRPCApi property below.

}

extension ServiceRemoteWordPressXMLRPC {
public var xmlrpcApi: WordPressOrgXMLRPCApi {
self.api as! WordPressOrgXMLRPCApi
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Foundation
import UIKit
import WordPressKitObjC

open class FeatureFlagRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
@_implementationOnly import wpxmlrpc
import wpxmlrpc

/// A builder type that appends HTTP request data to a URL.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class HomepageSettingsServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
24 changes: 0 additions & 24 deletions Sources/WordPressKit/Info.plist

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

open class JetpackBackupServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

/// A service that returns the Jetpack Capabilities for a set of blogs
open class JetpackCapabilitiesServiceRemote: ServiceRemoteWordPressComREST {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Foundation
public class JetpackPluginManagementClient: PluginManagementClient {
private let siteID: Int
private let remote: PluginServiceRemote
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Foundation
import WordPressKitObjC

/// Encapsulates Jetpack Proxy requests.
public class JetpackProxyServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST {
// MARK: - Scanning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public struct JetpackInstallError: LocalizedError, Equatable {
public enum ErrorType: String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Foundation
import WordPressKitObjC

/// Encapsulates remote service logic related to Jetpack Social.
public class JetpackSocialServiceRemote: ServiceRemoteWordPressComREST {

Expand Down
15 changes: 0 additions & 15 deletions Sources/WordPressKit/Models/RemoteUser.h

This file was deleted.

5 changes: 0 additions & 5 deletions Sources/WordPressKit/Models/RemoteUser.m

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import Foundation
import WordPressKitObjC

/// The purpose of this class is to encapsulate all of the interaction with the Notifications REST endpoints.
/// Here we'll deal mostly with the Settings / Push Notifications API.
///
open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST {
/// Designated Initializer. Fails if the remoteApi is nil.
///
/// - Parameter wordPressComRestApi: A Reference to the WordPressComRestApi that should be used to interact with WordPress.com
///
public override init(wordPressComRestApi: WordPressComRestApi) {
super.init(wordPressComRestApi: wordPressComRestApi)
}

/// Retrieves all of the Notification Settings
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

// MARK: - NotificationSyncServiceRemote
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

/// Encapsulates all of the People Management WordPress.com Methods
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

open class PlanServiceRemote: ServiceRemoteWordPressComREST {
public typealias AvailablePlans = (plans: [RemoteWpcomPlan], groups: [RemotePlanGroup], features: [RemotePlanFeature])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

@objc public class PlanServiceRemote_ApiVersion1_3: ServiceRemoteWordPressComREST {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WordPressKitObjC

public class PluginServiceRemote: ServiceRemoteWordPressComREST {
public enum ResponseError: Error {
Expand Down
56 changes: 56 additions & 0 deletions Sources/WordPressKit/PostServiceRemoteREST.swift
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to translate this function to Swift, because it's used in a Swift module. I'll explain a little bit more of why this is needed in the upcoming app PR (which would provide a full context).

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good. We'll just need to make sure we test the features that needed rewrite.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import WordPressKitObjC
import NSObject_SafeExpectations

extension PostServiceRemoteREST {

/// Requests a list of users that liked the post with the specified ID.
///
/// Due to the API limitation, up to 90 users will be returned from the endpoint.
///
/// - Parameters:
/// - postID: The ID for the post. Cannot be nil.
/// - count: Number of records to retrieve. Cannot be nil. If 0, will default to endpoint max.
/// - before: Filter results to Likes before this date/time string. Can be nil.
/// - excludeUserIDs: Array of user IDs to exclude from response. Can be nil.
/// - success: The block that will be executed on success. Can be nil.
/// - failure: The block that will be executed on failure. Can be nil.
@objc(getLikesForPostID:count:before:excludeUserIDs:success:failure:)
public func getLikesForPostID(
_ postID: NSNumber,
count: NSNumber,
before: String?,
excludeUserIDs: [NSNumber]?,
success: (([RemoteLikeUser], NSNumber) -> Void)?,
failure: ((Error?) -> Void)?
) {
let path = "sites/\(siteID)/posts/\(postID)/likes"
let requestUrl = self.path(forEndpoint: path, withVersion: ._1_2)
let siteID = self.siteID

// If no count provided, default to endpoint max.
var parameters: [String: Any] = ["number": count == 0 ? 90 : count]

if let before {
parameters["before"] = before
}

if let excludeUserIDs {
parameters["exclude"] = excludeUserIDs
}

wordPressComRESTAPI.get(requestUrl,
parameters: parameters,
success: { (responseObject, httpResponse) in
if let success {
let responseDict = responseObject as? [String: Any] ?? [:]
let jsonUsers = responseDict["likes"] as? [[String: Any]] ?? []
let users = jsonUsers.map { RemoteLikeUser(dictionary: $0, postID: postID, siteID: siteID) }
let found = responseDict["found"] as? NSNumber ?? 0
success(users, found)
}
}, failure: { (error, _) in
failure?(error)
})
}

}
Loading