diff --git a/example/rest-api/art-institute/README.md b/example/rest-api/art-institute/README.md index f916dac9..661376a4 100644 --- a/example/rest-api/art-institute/README.md +++ b/example/rest-api/art-institute/README.md @@ -1,3 +1,5 @@ # Example: "Art Institute of Chicago" block -This example registers a remote data block representing an artwork from the [Art Institute of Chicago's public API](http://api.artic.edu/docs/). +This example plugin registers a remote data block representing an artwork from the [Art Institute of Chicago's public API](http://api.artic.edu/docs/). The source is defined in the plugin code directly, as opposed to the in settings screen like the Zip Code example. + +To enable it, simply copy the art-institute.php file to your plugins folder and activate it. This will expose a new custom block called `Art Institute of Chicago` diff --git a/example/rest-api/art-institute/register.php b/example/rest-api/art-institute/art-institute.php similarity index 81% rename from example/rest-api/art-institute/register.php rename to example/rest-api/art-institute/art-institute.php index 8be11d9a..28cc0af2 100644 --- a/example/rest-api/art-institute/register.php +++ b/example/rest-api/art-institute/art-institute.php @@ -1,5 +1,15 @@ [ '__version' => 1, 'display_name' => 'Art Institute of Chicago', @@ -16,9 +26,9 @@ function register_aic_block(): void { 'Content-Type' => 'application/json', ], ], - ] ); + ]); - $get_art_query = HttpQuery::from_array( [ + $get_art_query = HttpQuery::from_array([ 'data_source' => $aic_data_source, 'endpoint' => function ( array $input_variables ) use ( $aic_data_source ): string { return sprintf( '%s/%s', $aic_data_source->get_endpoint(), $input_variables['id'] ?? '' ); @@ -54,9 +64,9 @@ function register_aic_block(): void { ], ], ], - ] ); + ]); - $search_art_query = HttpQuery::from_array( [ + $search_art_query = HttpQuery::from_array([ 'data_source' => $aic_data_source, 'endpoint' => function ( array $input_variables ) use ( $aic_data_source ): string { $query = $input_variables['search_terms']; @@ -84,9 +94,9 @@ function register_aic_block(): void { ], ], ], - ] ); + ]); - register_remote_data_block( [ + register_remote_data_block([ 'title' => 'Art Institute of Chicago', 'render_query' => [ 'query' => $get_art_query, @@ -97,6 +107,6 @@ function register_aic_block(): void { 'type' => 'search', ], ], - ] ); + ]); } add_action( 'init', __NAMESPACE__ . '\\register_aic_block' ); diff --git a/example/rest-api/zip-code/README.md b/example/rest-api/zip-code/README.md index 39821e55..b775b333 100644 --- a/example/rest-api/zip-code/README.md +++ b/example/rest-api/zip-code/README.md @@ -1,7 +1,9 @@ # Example: "Zip Code" block -This example registers a remote data block representing a Zip code. The block fetches data from the [Zippopotam.us API](http://www.zippopotam.us/). +This example plugin registers a remote data block to represent the city and state from a US ZIP code. The block fetches data from the [Zippopotam.us API](http://www.zippopotam.us/). When working with REST APIs that do not have a first-class integration (like Airtable, Google Sheets, Shopify, et al.), a common approach is to define a data source on the settings screen and then commit a custom query in code to fetch and process the data. This example illustrates this approach, and assumes you have configured the data source in the UI and have provided the UUID via the `EXAMPLE_ZIP_CODE_DATA_SOURCE_UUID` constant. + +To enable it, simply copy the zipcode.php file to your plugins folder, replace the UUID, and activate it. This will expose a new custom block called `Zip Code' diff --git a/example/rest-api/zip-code/register.php b/example/rest-api/zip-code/zip-code.php similarity index 61% rename from example/rest-api/zip-code/register.php rename to example/rest-api/zip-code/zip-code.php index 2ac0c709..57183a5e 100644 --- a/example/rest-api/zip-code/register.php +++ b/example/rest-api/zip-code/zip-code.php @@ -1,23 +1,34 @@ $zipcode_data_source, 'endpoint' => function ( array $input_variables ) use ( $zipcode_data_source ): string { return $zipcode_data_source->get_endpoint() . $input_variables['zip_code']; @@ -48,13 +59,13 @@ function register_zipcode_block(): void { ], ], ], - ] ); + ]); - register_remote_data_block( [ + register_remote_data_block([ 'title' => 'Zip Code', 'render_query' => [ 'query' => $zipcode_query, ], - ] ); + ]); } add_action( 'init', __NAMESPACE__ . '\\register_zipcode_block' ); diff --git a/phpcs.xml b/phpcs.xml index ac2201dc..3a8de2fc 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -102,6 +102,8 @@ remote-data-blocks.php + zip-code.php + art-institute.php functions.php