-
Notifications
You must be signed in to change notification settings - Fork 16
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
Use URLSession to send WP.com REST API requests #720
Conversation
3dd50a3
to
e30ba27
Compare
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.
Only a couple of nitpicks.
@@ -612,6 +639,38 @@ open class WordPressComRestApi: NSObject { | |||
} | |||
} | |||
|
|||
public func upload( | |||
_ URLString: String, |
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.
Nitpick. Value names should start with lowercase letters.
_ URLString: String, | |
_ urlString: String, |
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 have updated this part in a3c19a9. which probably made it worse, in terms of the name... I used URLString
because that's the term used throughout this class...
completion( | ||
result | ||
.map { ($0.body, $0.response) } | ||
.mapError { error -> Error in error } |
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.
It wasn't obvious to me why this mapError
was necessary.
What to you think of adding a line such as
.mapError { error -> Error in error } | |
// The completion expects a result with any Error. | |
// We need to "downcast" the WordPressComRestApiEndpointError error in the APIResult. | |
.mapError { error -> Error in error } |
Also, using $0
would work, too. But, having the explicit function signature with Error
might be clearer for the reader in this unusual scenario.
Description
This PR updates the WP.com REST API client to send HTTP requests using URLSession, when
useURLSession
is set to true (it's false by default).Note
I'd recommend reviewing this PR commit-by-commit.
Testing Details
The unit test suite passes with
useURLSession
set to ture. I had to updated one test case to make it pass, because the new URLSession API does not return AFError.In theory, all the new code in this PR are dead code at the moment. I will update the apps to enable
useURLSession
as in-development feature flag, and we can see how the new implementation work out in the app.wordpress-mobile/WordPress-iOS#22540 can be used to get an app build which enables
useURLSession
by default.CHANGELOG.md
if necessary.