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 westeros houses example using google sheets #33

Merged
merged 31 commits into from
Sep 13, 2024

Conversation

shekharnwagh
Copy link
Contributor

@shekharnwagh shekharnwagh commented Sep 10, 2024

Description

This PR adds an example block for Google Sheets. Google Sheets like Airtable and unlike Shopify doesn't have a static schema for the data. So this example is just one example and the schema would be different for each Google Sheet. The example used here is a sheet containing the list of houses of Westeros with the columns as "Name", "Seat", "Region", "Words" and "Sigil". The 2 blocks added are:

  • "Westeros House" to add a single house
  • "Westeros Houses List" to add all houses

Testing

Google Sheets and Google API Access Setup

  • To test this block, create a Google Sheet with above columns with the "Sigil" column having the URL of the sigil image.
  • Create a project in Google Cloud Platform. resourcemanager.projects.create permission is needed to create a new project. Skip this step if you already have a project setup in your organization in Google Cloud Platform.
  • Enable the Google Drive API for your project.
  • Enable the Google Sheets API for your project.
  • Create a service account for your project.
  • Create a key for the service account. This will download a JSON key file. Keep this file safe as it will be used to authenticate the block.
  • Convert the downloaded keys JSON to a JSON string, Base64 encode it and add it to the REMOTE_DATA_BLOCKS_EXAMPLE_GOOGLE_SHEETS_WESTEROS_HOUSES_ACCESS_TOKEN" key in the .wp-env.override.json file.

Trying out the block

  • Start the local WordPress environment with npm run monolith
  • Go to the WordPress admin dashboard at http://localhost:8888/wp-admin
  • Create a new post and try adding the newly added "Westeros House" block to the post.
  • You can also try adding the "Westeros Houses List" block to the post.

Screenshots

Screenshot 2024-09-13 at 4 09 39 PM
Single "Westeros House" block in Editor
Screenshot 2024-09-13 at 4 09 49 PM
"Westeros Houses List" block in WordPress Frontend

@shekharnwagh shekharnwagh self-assigned this Sep 10, 2024
@shekharnwagh shekharnwagh changed the title feat: add westeros houses example using google sheets [WIP] add westeros houses example using google sheets Sep 10, 2024
Base automatically changed from add/google-oauth to trunk September 12, 2024 17:06
@shekharnwagh shekharnwagh marked this pull request as ready for review September 13, 2024 11:11
@shekharnwagh shekharnwagh changed the title [WIP] add westeros houses example using google sheets add westeros houses example using google sheets Sep 13, 2024
The google auth logic was located in inc/config/auth dir. The
/inc/integrations dir seems more appropriate for this as it won't just
contains configs.
@shekharnwagh shekharnwagh force-pushed the add/google-sheets-westeros-houses-example branch from 726940b to 85090a7 Compare September 13, 2024 12:30
Copy link
Contributor

@mhsdef mhsdef left a comment

Choose a reason for hiding this comment

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

Cool stuff! Didn't test, but, code makes sense. :shipit:

Copy link
Member

@chriszarate chriszarate left a comment

Choose a reason for hiding this comment

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

Tested, looks good. But I am concerned about all the fantasy content in these examples 😂

@shekharnwagh shekharnwagh merged commit 070cd3a into trunk Sep 13, 2024
7 checks passed
@shekharnwagh shekharnwagh deleted the add/google-sheets-westeros-houses-example branch September 13, 2024 16:17
Comment on lines +81 to +86
wp_cache_set(
$cache_key,
$token,
'oauth-tokens',
3000, // 50 minutes
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chriszarate @mhsdef I am wondering if we should encrypt this token before writing to cache ? We do encrypt the data source config when we store it in options table, but that is persistent as opposed to this which has TTL of 50mins for now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, yeah. We could do what we're doing with the DB option if there's a hook that fires in the cache set. I didn't see one, in brief perusing, but maybe I missed it.

Otherwise, could invoke our encryption code manually to handle.

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.

4 participants