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

Conversation

mokagio
Copy link
Contributor

@mokagio mokagio commented Apr 4, 2024

Description

Follows up on #766 applying the same pattern to all the .GET and .POST usages.

I changed each file/group of files with extensions in dedicated commits, in case one wants to review in chunks.

Testing Details

Not all code is covered by unit tests, unfortunately. But, these changes are really about swapping interfaces without changing the implementation. They should be safe—last famous words.


  • Please check here if your pull request includes additional test coverage. — N.A.
  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary. — N.A.

@mokagio mokagio requested a review from crazytonyli April 4, 2024 09:51
@mokagio mokagio enabled auto-merge April 4, 2024 10:37
@mokagio mokagio changed the title Use WordPressComRESTAPIInterfacing for all sync GET and POST requests in the Swift code SPM Prep - Use WordPressComRESTAPIInterfacing for all sync GET and POST requests in the Swift code Apr 4, 2024
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!

if let response = response as? [String: Bool],
let success = response[Constants.status] {
completion(success, nil)
} else {
completion(false, JetpackInstallError(type: .installResponseError))
}
}) { (error: NSError, _: HTTPURLResponse?) in
}) { error, _ in
let error = 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.

Same as above.

@mokagio mokagio merged commit 9930ab2 into trunk Apr 4, 2024
9 checks passed
@mokagio mokagio deleted the mokagio/convert-all-wordpresscomrestapi-swift branch April 4, 2024 22:12
mokagio added a commit that referenced this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants