Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM Prep - Use WordPressComRESTAPIInterfacing for all sync GET and POST requests in the Swift code #777

Merged
merged 35 commits into from
Apr 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2024e63
Use `WordPressComRESTAPIInterfacing` in `ActivityServiceRemote`
mokagio Apr 4, 2024
68b7e1b
Use `WordPressComRESTAPIInterfacing` in `AutomatedTransferService`
mokagio Apr 4, 2024
3acacde
Use `WordPressComRESTAPIInterfacing` in `BlogJetpackSettingsServiceRe…
mokagio Apr 4, 2024
00ea99b
Use `WordPressComRESTAPIInterfacing` in `DashboardServiceRemote`
mokagio Apr 4, 2024
5686b20
Use `WordPressComRESTAPIInterfacing` in `AtomicAuthenticationServiceR…
mokagio Apr 4, 2024
fc01a5b
Use `WordPressComRESTAPIInterfacing` in `BloggingPromptsServiceRemote`
mokagio Apr 4, 2024
a2cbce0
Use `WordPressComRESTAPIInterfacing` in `EditorServiceRemote`
mokagio Apr 4, 2024
62628a0
Use `WordPressComRESTAPIInterfacing` in `FeatureFlagRemote`
mokagio Apr 4, 2024
2873779
Use `WordPressComRESTAPIInterfacing` in `HomepageSettingsServiceRemote`
mokagio Apr 4, 2024
8d7b816
Use `WordPressComRESTAPIInterfacing` in `JetpackBackupServiceRemote`
mokagio Apr 4, 2024
1872f2f
Use `WordPressComRESTAPIInterfacing` in `JetpackCapabilitiesServiceRe…
mokagio Apr 4, 2024
d9c58df
Use `WordPressComRESTAPIInterfacing` in `JetpackScanServiceRemote`
mokagio Apr 4, 2024
ffe285d
Use `WordPressComRESTAPIInterfacing` in `JetpackServiceRemote`
mokagio Apr 4, 2024
9990bc8
Use `WordPressComRESTAPIInterfacing` in `JetpackProxyServiceRemote`
mokagio Apr 4, 2024
6363aa0
Use `WordPressComRESTAPIInterfacing` in `NotificationSettingsServiceR…
mokagio Apr 4, 2024
6e93cbd
Use `WordPressComRESTAPIInterfacing` in `NotificationSyncServiceRemote`
mokagio Apr 4, 2024
8c49c9f
Use `WordPressComRESTAPIInterfacing` in `PeopleServiceRemote`
mokagio Apr 4, 2024
0d7b95c
Use `WordPressComRESTAPIInterfacing` in `PlanServiceRemote_ApiVersion…
mokagio Apr 4, 2024
a5cb669
Use `WordPressComRESTAPIInterfacing` in `PlanServiceRemote`
mokagio Apr 4, 2024
19f086d
Use `WordPressComRESTAPIInterfacing` in `PluginServiceRemote`
mokagio Apr 4, 2024
ea2d327
Use `WordPressComRESTAPIInterfacing` in `PostServiceRemoteREST+Revisi…
mokagio Apr 4, 2024
bf66e02
Use `WordPressComRESTAPIInterfacing` in `ProductServiceRemote`
mokagio Apr 4, 2024
e812c17
Use `WordPressComRESTAPIInterfacing` in `PushAuthenticationServiceRem…
mokagio Apr 4, 2024
05efbae
Use `WordPressComRESTAPIInterfacing` in `QRLoginServiceRemote`
mokagio Apr 4, 2024
42326b3
Use `WordPressComRESTAPIInterfacing` in `ReaderPostServiceRemote`
mokagio Apr 4, 2024
ce3627a
Use `WordPressComRESTAPIInterfacing` in `ReaderSiteSearchServiceRemote`
mokagio Apr 4, 2024
3790cb7
Use `WordPressComRESTAPIInterfacing` in `ReaderTopicServiceRemote`
mokagio Apr 4, 2024
de8e0e2
Use `WordPressComRESTAPIInterfacing` in `SharingServiceRemote`
mokagio Apr 4, 2024
b6f7d63
Use `WordPressComRESTAPIInterfacing` in `SiteManagementServiceRemote`
mokagio Apr 4, 2024
2c1aea3
Use `WordPressComRESTAPIInterfacing` in `StatsServiceRemoteV2`
mokagio Apr 4, 2024
75451ba
Use `WordPressComRESTAPIInterfacing` in `TimeZoneServiceRemote`
mokagio Apr 4, 2024
8f1196b
Use `WordPressComRESTAPIInterfacing` in `TransactionsServiceRemote`
mokagio Apr 4, 2024
0285a53
Use `WordPressComRESTAPIInterfacing` in `AtomicSiteServiceRemote`
mokagio Apr 4, 2024
852e042
Use `WordPressComRESTAPIInterfacing` in `WordPressComServiceRemote`
mokagio Apr 4, 2024
cba707d
Use `WordPressComRESTAPIInterfacing` in `RemoteConfigRemote`
mokagio Apr 4, 2024
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
23 changes: 14 additions & 9 deletions Sources/WordPressKit/Services/ActivityServiceRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {

let finalPath = self.path(forEndpoint: endpoint, withVersion: ._2_0)

wordPressComRestApi.GET(finalPath,
wordPressComRESTAPI.get(finalPath,
parameters: nil,
success: { response, _ in
do {
Expand Down Expand Up @@ -105,7 +105,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
parameters["on"] = formatter.string(from: on) as AnyObject
}

wordPressComRestApi.GET(path,
wordPressComRESTAPI.get(path,
parameters: parameters,
success: { response, _ in
do {
Expand Down Expand Up @@ -135,7 +135,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
let endpoint = "sites/\(siteID)/rewind"
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)

wordPressComRestApi.GET(path,
wordPressComRESTAPI.get(path,
parameters: nil,
success: { response, _ in
guard let rewindStatus = response as? [String: AnyObject] else {
Expand All @@ -154,20 +154,25 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
}, failure: { error, _ in
// FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend
// stops returning 412's for those sites.
if error.domain == WordPressComRestApiEndpointError.errorDomain, error.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue {
let status = RewindStatus(state: .unavailable)
success(status)
let nsError = error as NSError
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but IMO it's better to avoid casting to NSError here by using pattern matching.

if let apiError = error as? WordPressAPIError<WordPressRestApiEndpointError>,
    case let .endpointError(endpointError) = apiError,
    endpointError.code == .preconditionFailure {
  // ....
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, right.

I guess you are suggesting to used the better typed error to ensure what we are handling is a legit API error. If the casting fails, we are in a edge case and should act differently.

Under that assumption, I opened #779 to address. Thanks!


guard nsError.domain == WordPressComRestApiEndpointError.errorDomain,
nsError.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue else {
failure(error)
return
}
failure(error)

let status = RewindStatus(state: .unavailable)
success(status)
return
})
}

}

private extension ActivityServiceRemote {

func mapActivitiesResponse(_ response: AnyObject) throws -> ([Activity], Int) {
func mapActivitiesResponse(_ response: Any) throws -> ([Activity], Int) {

guard let json = response as? [String: AnyObject],
let totalItems = json["totalItems"] as? Int else {
Expand Down Expand Up @@ -196,7 +201,7 @@ private extension ActivityServiceRemote {
}
}

func mapActivityGroupsResponse(_ response: AnyObject) throws -> ([ActivityGroup]) {
func mapActivityGroupsResponse(_ response: Any) throws -> ([ActivityGroup]) {
guard let json = response as? [String: AnyObject],
let totalItems = json["totalItems"] as? Int, totalItems > 0 else {
return []
Expand Down