This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Change Swift package to provide source code #846
Closed
Closed
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0fa20af
Reorgnize files
crazytonyli 6c469a1
Delete Info.plist
crazytonyli 666dff0
Replace `#import <WordPressKit/*.h>` statements
crazytonyli ddc54d5
Remove WPKit-Swift.h
crazytonyli 6b696bc
Translate RemoteUser to Swift
crazytonyli 19585fb
Rearrange files
crazytonyli c8b0bb0
Fix imports
crazytonyli ba19dee
Remove _implementationOnly imports
crazytonyli 3133cba
Minor syntactical changes
crazytonyli 388b86c
Remove WordPressKit.h
crazytonyli e93e791
Translate PostServiceRemoteREST.getLikesForPostID to Swift
crazytonyli abaf0ec
Add Package.swift
crazytonyli 6a8e615
Convert the Objective-C protocol to a Swift concrete type
crazytonyli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.