Integrated locale handling changes in WordPressKit#10950
Conversation
| let api: WordPressComRestApi | ||
| if let wpcomApi = accountService.defaultWordPressComAccount()?.wordPressComRestApi { | ||
| api = wpcomApi | ||
| if let account = accountService.defaultWordPressComAccount(), let token = account.authToken { |
There was a problem hiding this comment.
How about creating a method on the Account object called wordPressComRestV2APi and that will return the API object set to the correct v2 locale?
There was a problem hiding this comment.
I like this suggestion – it would remove a bit of duplication 👍
There was a problem hiding this comment.
Thanks for this suggestion! I considered it during the initial implementation; it didn't seem to help as much as I had hoped.
Because AccountService.defaultWordPressComAccount() is optional, you still have some duplication in the event that returns nil. For example:
let api: WordPressComRestApi
if let account = accountService.defaultWordPressComAccount() {
api = account.wordPressComRestV2Api
} else {
api = WordPressComRestApi.anonymousApi(userAgent: WPUserAgent.wordPress(), localeKey: WordPressComRestApi.LocaleKeyV2)
}
In any case, I'll proceed to make this change.
frosty
left a comment
There was a problem hiding this comment.
✅ Reviewed the changes
✅ Built and ran tests
✅ Smoke-tested site creation and a few other areas
Looking good, I'd just echo Sergio's suggestion for a possible improvement.
|
Thanks for the feedback, @SergioEstevao! I have pushed a commit that incorporates your feedback. Would you be willing to take another look? |
SergioEstevao
left a comment
There was a problem hiding this comment.
Looking good! Thanks for all your patience!
Description
Fixes #78, which exposes the ability to inject different locale keys into
WordPressComRestApi.The code can be reviewed as-is; I have only affixed the
DO NOT MERGElabel to reflect the fact that it is dependent on the review, approval, merge, & versioning of this PR inWordPressKit.Note: A separate issue has been created in
WordPressKitto transition the existing service methods to leverage this implicit locale-handling behavior.To test:
ActivityServiceRemote.Update release notes:
RELEASE-NOTES.txt.