From b44f6eb0d50dc7a66f52bb707174a949ddefe7fa Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 30 May 2019 15:04:03 +0100 Subject: [PATCH] Data --- .../Data.php} | 22 +++++---- .../Data/Continents.php} | 25 ++++++---- .../Data/Countries.php} | 22 +++++---- .../Data/Currencies.php} | 23 +++++---- .../Data/DownloadIPs.php} | 11 +++-- src/RestApi/Version4/changelog.md | 38 +++++++-------- .../class-wc-admin-rest-data-controller.php | 47 ------------------- ...c-admin-rest-data-countries-controller.php | 27 ----------- 8 files changed, 82 insertions(+), 133 deletions(-) rename src/RestApi/Version4/{class-wc-rest-data-controller.php => Controllers/Data.php} (91%) rename src/RestApi/Version4/{class-wc-rest-data-continents-controller.php => Controllers/Data/Continents.php} (96%) rename src/RestApi/Version4/{class-wc-rest-data-countries-controller.php => Controllers/Data/Countries.php} (94%) rename src/RestApi/Version4/{class-wc-rest-data-currencies-controller.php => Controllers/Data/Currencies.php} (93%) rename src/RestApi/Version4/{class-wc-admin-rest-data-download-ips-controller.php => Controllers/Data/DownloadIPs.php} (95%) delete mode 100644 src/RestApi/Version4/class-wc-admin-rest-data-controller.php delete mode 100644 src/RestApi/Version4/class-wc-admin-rest-data-countries-controller.php diff --git a/src/RestApi/Version4/class-wc-rest-data-controller.php b/src/RestApi/Version4/Controllers/Data.php similarity index 91% rename from src/RestApi/Version4/class-wc-rest-data-controller.php rename to src/RestApi/Version4/Controllers/Data.php index 71c6dd9029a..141d7f2f166 100644 --- a/src/RestApi/Version4/class-wc-rest-data-controller.php +++ b/src/RestApi/Version4/Controllers/Data.php @@ -5,25 +5,25 @@ * Handles requests to the /data endpoint. * * @package WooCommerce/RestApi - * @since 3.5.0 */ +namespace WooCommerce\RestApi\Version4\Controllers; + defined( 'ABSPATH' ) || exit; +use \WC_REST_Controller; + /** - * REST API Data controller class. - * - * @package WooCommerce/RestApi - * @extends WC_REST_Controller + * REST API Coupons controller class. */ -class WC_REST_Data_Controller extends WC_REST_Controller { +class Data extends WC_REST_Controller { /** * Endpoint namespace. * * @var string */ - protected $namespace = 'wc/v3'; + protected $namespace = 'wc/v4'; /** * Route base. @@ -39,7 +39,9 @@ class WC_REST_Data_Controller extends WC_REST_Controller { */ public function register_routes() { register_rest_route( - $this->namespace, '/' . $this->rest_base, array( + $this->namespace, + '/' . $this->rest_base, + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), @@ -100,6 +102,10 @@ class WC_REST_Data_Controller extends WC_REST_Controller { 'slug' => 'currencies', 'description' => __( 'List of supported currencies.', 'woocommerce' ), ), + array( + 'slug' => 'download-ips', + 'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ), + ), ); foreach ( $resources as $resource ) { diff --git a/src/RestApi/Version4/class-wc-rest-data-continents-controller.php b/src/RestApi/Version4/Controllers/Data/Continents.php similarity index 96% rename from src/RestApi/Version4/class-wc-rest-data-continents-controller.php rename to src/RestApi/Version4/Controllers/Data/Continents.php index ccf64086b3f..a47f30c9f29 100644 --- a/src/RestApi/Version4/class-wc-rest-data-continents-controller.php +++ b/src/RestApi/Version4/Controllers/Data/Continents.php @@ -5,25 +5,25 @@ * Handles requests to the /data/continents endpoint. * * @package WooCommerce/RestApi - * @since 3.5.0 */ +namespace WooCommerce\RestApi\Version4\Controllers\Data; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; + /** - * REST API Data continents controller class. - * - * @package WooCommerce/RestApi - * @extends WC_REST_Controller + * REST API Data Continents controller class. */ -class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller { +class Continents extends DataController { /** * Endpoint namespace. * * @var string */ - protected $namespace = 'wc/v3'; + protected $namespace = 'wc/v4'; /** * Route base. @@ -39,7 +39,9 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller { */ public function register_routes() { register_rest_route( - $this->namespace, '/' . $this->rest_base, array( + $this->namespace, + '/' . $this->rest_base, + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), @@ -49,7 +51,9 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller { ) ); register_rest_route( - $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + $this->namespace, + '/' . $this->rest_base . '/(?P[\w-]+)', + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), @@ -104,7 +108,8 @@ class WC_REST_Data_Continents_Controller extends WC_REST_Data_Controller { if ( array_key_exists( $country_code, $locale_info ) ) { // Defensive programming against unexpected changes in locale-info.php. $country_data = wp_parse_args( - $locale_info[ $country_code ], array( + $locale_info[ $country_code ], + array( 'currency_code' => 'USD', 'currency_pos' => 'left', 'decimal_sep' => '.', diff --git a/src/RestApi/Version4/class-wc-rest-data-countries-controller.php b/src/RestApi/Version4/Controllers/Data/Countries.php similarity index 94% rename from src/RestApi/Version4/class-wc-rest-data-countries-controller.php rename to src/RestApi/Version4/Controllers/Data/Countries.php index ff659b67e09..597bad1d1f4 100644 --- a/src/RestApi/Version4/class-wc-rest-data-countries-controller.php +++ b/src/RestApi/Version4/Controllers/Data/Countries.php @@ -5,25 +5,25 @@ * Handles requests to the /data/countries endpoint. * * @package WooCommerce/RestApi - * @since 3.5.0 */ +namespace WooCommerce\RestApi\Version4\Controllers\Data; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; + /** - * REST API Data countries controller class. - * - * @package WooCommerce/RestApi - * @extends WC_REST_Controller + * REST API Data Countries controller class. */ -class WC_REST_Data_Countries_Controller extends WC_REST_Data_Controller { +class Countries extends DataController { /** * Endpoint namespace. * * @var string */ - protected $namespace = 'wc/v3'; + protected $namespace = 'wc/v4'; /** * Route base. @@ -39,7 +39,9 @@ class WC_REST_Data_Countries_Controller extends WC_REST_Data_Controller { */ public function register_routes() { register_rest_route( - $this->namespace, '/' . $this->rest_base, array( + $this->namespace, + '/' . $this->rest_base, + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), @@ -49,7 +51,9 @@ class WC_REST_Data_Countries_Controller extends WC_REST_Data_Controller { ) ); register_rest_route( - $this->namespace, '/' . $this->rest_base . '/(?P[\w-]+)', array( + $this->namespace, + '/' . $this->rest_base . '/(?P[\w-]+)', + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), diff --git a/src/RestApi/Version4/class-wc-rest-data-currencies-controller.php b/src/RestApi/Version4/Controllers/Data/Currencies.php similarity index 93% rename from src/RestApi/Version4/class-wc-rest-data-currencies-controller.php rename to src/RestApi/Version4/Controllers/Data/Currencies.php index b5439695d0d..57a29917c0e 100644 --- a/src/RestApi/Version4/class-wc-rest-data-currencies-controller.php +++ b/src/RestApi/Version4/Controllers/Data/Currencies.php @@ -5,24 +5,25 @@ * Handles requests to the /data/currencies endpoint. * * @package WooCommerce/RestApi - * @since 3.5.0 */ +namespace WooCommerce\RestApi\Version4\Controllers\Data; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; + /** * REST API Data Currencies controller class. - * - * @package WooCommerce/RestApi */ -class WC_REST_Data_Currencies_Controller extends WC_REST_Data_Controller { +class Currencies extends DataController { /** * Endpoint namespace. * * @var string */ - protected $namespace = 'wc/v3'; + protected $namespace = 'wc/v4'; /** * Route base. @@ -36,7 +37,9 @@ class WC_REST_Data_Currencies_Controller extends WC_REST_Data_Controller { */ public function register_routes() { register_rest_route( - $this->namespace, '/' . $this->rest_base, array( + $this->namespace, + '/' . $this->rest_base, + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_items' ), @@ -46,7 +49,9 @@ class WC_REST_Data_Currencies_Controller extends WC_REST_Data_Controller { ) ); register_rest_route( - $this->namespace, '/' . $this->rest_base . '/current', array( + $this->namespace, + '/' . $this->rest_base . '/current', + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_current_item' ), @@ -56,7 +61,9 @@ class WC_REST_Data_Currencies_Controller extends WC_REST_Data_Controller { ) ); register_rest_route( - $this->namespace, '/' . $this->rest_base . '/(?P[\w-]{3})', array( + $this->namespace, + '/' . $this->rest_base . '/(?P[\w-]{3})', + array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'get_item' ), diff --git a/src/RestApi/Version4/class-wc-admin-rest-data-download-ips-controller.php b/src/RestApi/Version4/Controllers/Data/DownloadIPs.php similarity index 95% rename from src/RestApi/Version4/class-wc-admin-rest-data-download-ips-controller.php rename to src/RestApi/Version4/Controllers/Data/DownloadIPs.php index 36e2431d0b9..14e85fd24a7 100644 --- a/src/RestApi/Version4/class-wc-admin-rest-data-download-ips-controller.php +++ b/src/RestApi/Version4/Controllers/Data/DownloadIPs.php @@ -4,18 +4,19 @@ * * Handles requests to /data/download-ips * - * @package WooCommerce Admin/API + * @package WooCommerce/RestApi */ +namespace WooCommerce\RestApi\Version4\Controllers\Data; + defined( 'ABSPATH' ) || exit; +use \WooCommerce\RestApi\Version4\Controllers\Data as DataController; + /** * Data Download IP controller. - * - * @package WooCommerce Admin/API - * @extends WC_REST_Data_Controller */ -class WC_Admin_REST_Data_Download_Ips_Controller extends WC_REST_Data_Controller { +class DownloadIPs extends DataController { /** * Endpoint namespace. * diff --git a/src/RestApi/Version4/changelog.md b/src/RestApi/Version4/changelog.md index c76f50bcdb9..9359f75b0ec 100644 --- a/src/RestApi/Version4/changelog.md +++ b/src/RestApi/Version4/changelog.md @@ -12,25 +12,25 @@ ## New endpoints -- Added `reports/products` endpoint. -- Added `reports/products/stats` endpoint. -- Added `reports/categories` endpoint. -- Added `reports/orders` endpoint. -- Added `reports/orders/stats` endpoint. -- Added `reports/performance-indicators` endpoint. -- Added `reports/revenue/stats` endpoint. -- Added `reports/stock` endpoint. -- Added `reports/stock/stats` endpoint. -- Added `reports/taxes` endpoint. -- Added `reports/taxes/stats` endpoint. -- Added `reports/variations` endpoint. -- Added `reports/coupons` endpoint. -- Added `reports/coupons/stats` endpoint. -- Added `reports/customer` endpoint. -- Added `reports/customers/stats` endpoint. -- Added `reports/downloads` endpoint. -- Added `reports/downloads/stats` endpoint. -- Added `reports/import` endpoint. +- `reports/products` +- `reports/products/stats` +- `reports/categories` +- `reports/orders` +- `reports/orders/stats` +- `reports/performance-indicators` +- `reports/revenue/stats` +- `reports/stock` +- `reports/stock/stats` +- `reports/taxes` +- `reports/taxes/stats` +- `reports/variations` +- `reports/coupons` +- `reports/coupons/stats` +- `reports/customer` +- `reports/customers/stats` +- `reports/downloads` +- `reports/downloads/stats` +- `reports/import` ## Removed endpoints diff --git a/src/RestApi/Version4/class-wc-admin-rest-data-controller.php b/src/RestApi/Version4/class-wc-admin-rest-data-controller.php deleted file mode 100644 index 227ec85a150..00000000000 --- a/src/RestApi/Version4/class-wc-admin-rest-data-controller.php +++ /dev/null @@ -1,47 +0,0 @@ -data[] = $this->prepare_response_for_collection( - $this->prepare_item_for_response( - (object) array( - 'slug' => 'download-ips', - 'description' => __( 'An endpoint used for searching download logs for a specific IP address.', 'woocommerce' ), - ), - $request - ) - ); - return $response; - } - -} diff --git a/src/RestApi/Version4/class-wc-admin-rest-data-countries-controller.php b/src/RestApi/Version4/class-wc-admin-rest-data-countries-controller.php deleted file mode 100644 index f4f7ea0bda8..00000000000 --- a/src/RestApi/Version4/class-wc-admin-rest-data-countries-controller.php +++ /dev/null @@ -1,27 +0,0 @@ -