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

Add autosave attributes to RemotePost #192

Merged

Conversation

guarani
Copy link
Contributor

@guarani guarani commented Oct 27, 2019

Description

Post autosave attributes are added to RemotePost - the type that describes a post (or page) fetched from the API. Autosave data is obtained by including autosave in the meta parameter, but at the time of writing this is undocumented.

Issue: wordpress-mobile/WordPress-iOS#12141

REST API

The title, content, excerpt and date of last modification are fetched from the following REST API endpoint:

https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/

⚠️I think autosave is not currently supported on the XML RPC API as it has not been included in the Android changes I've come across (please let me know if this seems incorrect) ⚠️

https://github.com/wordpress-mobile/WordPress-FluxC-Android/pull/1357/files
https://github.com/wordpress-mobile/WordPress-FluxC-Android/pull/1391/files

Testing Details

These changes are best tested alongside the matching WordPress-iOS PR wordpress-mobile/WordPress-iOS#12826

Unit Tests

The new meta parameter uses the existing mechanism for specifying options, PostServiceRemoteOptions. There is already a test that asserts that arbitrary options are correctly set on the request payload (- testThatGetPostsOfTypeWithOptionsWorks), so I think the current tests have this covered.

Autosave metadata is supported through the new `meta` option when
fetching posts. Autosave metadata currently supported are: `title`,
`excerpt`, and `content`.
Simplify the treatment of null values when creating a `RemotePost` from
a dictionary representing its JSON data.
I'm unsure if `meta` is supported in XML-RPC, so removing this comment.
WordPressKit/RemotePost.h Outdated Show resolved Hide resolved
@guarani guarani marked this pull request as ready for review October 27, 2019 20:29
Although a good idea, specifying `nullable` triggers warnings on the other properties of this class. To resolve the warnings we would have to either explicitly annotate each property as nullable or nonnull - or, if all properties are not nullable, mark the class with NS_ASSUME_NONNULL_BEGIN.
@shiki shiki self-requested a review October 28, 2019 12:08
@shiki shiki self-assigned this Oct 28, 2019
@guarani guarani changed the title Issue/12141 restore revision dialog Add autosave attributes to RemotePost Oct 29, 2019
@guarani
Copy link
Contributor Author

guarani commented Oct 29, 2019

I think autosave is not currently supported on the XML RPC API as it has not been included in the Android changes I've come across (please let me know if this seems incorrect)

Update: Autosave is not supported by the XML RPC API.

Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

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

It's looking good, @guarani. I have a couple of comments.

Do you think it's possible to add a unit test that confirms that the autoSave properties are copied to RemotePost? Probably using a mock JSON like PostServiceRemoteRESTRevisionsTest.

WordPressKit/PostServiceRemoteREST.m Outdated Show resolved Hide resolved
When the fetch posts REST endpoint is called, autosave properties are
mapped to the RemotePost object.
@guarani
Copy link
Contributor Author

guarani commented Nov 2, 2019

@shiki, yes. I've now added a test testFetchPostsPerformsAutosaveMappingSuccessfully 👍

@guarani guarani requested a review from shiki November 2, 2019 21:42
Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

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

Great work, @guarani! I have a couple of minor comments that I'd like to hear your opinion on. After that, this is ready to be merged. 🎉

WordPressKit/RemotePost.h Show resolved Hide resolved
WordPressKit/RemotePostAutosave.swift Outdated Show resolved Hide resolved
@shiki
Copy link
Member

shiki commented Nov 4, 2019

@guarani Would you mind incrementing the pod's beta version as well? Just like this commit: 9c3a55e

`open` allowed subclassing of RemotePostAutosave and overriding of its
properties, `public` disallows this. Further restiction to disallow
setting the properties from outside the module using internal(set)
doesn't work due to Obj-C interoperability issues.
@guarani guarani requested a review from shiki November 6, 2019 00:31
@guarani
Copy link
Contributor Author

guarani commented Nov 6, 2019

Thanks again for the review, @shiki! I've updated the PR to address your comments.

If the fetch posts response JSON returns autosave as null, that's
converted to NSNull, which is a truthy value. Updating to treat NSNull
as no autosave.
Copy link
Member

@shiki shiki left a comment

Choose a reason for hiding this comment

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

LGTM!

@shiki shiki merged commit 055a195 into wordpress-mobile:develop Nov 6, 2019
@guarani
Copy link
Contributor Author

guarani commented Nov 6, 2019

Thank you, @shiki!

@guarani guarani deleted the issue/12141-restore-revision-dialog branch November 6, 2019 18:32
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