-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
356 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
/** | ||
* WooCommerce Plugin Framework | ||
* | ||
* This source file is subject to the GNU General Public License v3.0 | ||
* that is bundled with this package in the file license.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://www.gnu.org/licenses/gpl-3.0.html | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade the plugin to newer | ||
* versions in the future. If you wish to customize the plugin for your | ||
* needs please refer to http://www.skyverge.com | ||
* | ||
* @package SkyVerge/WooCommerce/API/Response | ||
* @author SkyVerge | ||
* @copyright Copyright (c) 2013-2015, SkyVerge, Inc. | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | ||
|
||
if ( ! class_exists( 'SV_WC_API_JSON_Response' ) ) : | ||
|
||
|
||
/** | ||
* API JSON Base Response Class | ||
* | ||
* Useful for API's that return application/json responses | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Response | ||
*/ | ||
class SV_WC_API_JSON_Response implements SV_WC_API_Response { | ||
|
||
|
||
/** @var string string representation of this response */ | ||
protected $raw_response_json; | ||
|
||
/** @var mixed decoded response data */ | ||
public $response_data; | ||
|
||
|
||
/** | ||
* Build a response object from the raw response JSON | ||
* | ||
* @since 3.1.2-1 | ||
* @param string $raw_response_json the raw response JSON | ||
*/ | ||
public function __construct( $raw_response_json ) { | ||
$this->raw_response_json = $raw_response_json; | ||
$this->response_data = json_decode( $raw_response_json ); | ||
} | ||
|
||
|
||
/** | ||
* Magic accessor for response data attributes | ||
* | ||
* @since 3.1.2-1 | ||
* @param string $name the attribute name to get | ||
* @return mixed the attribute value | ||
*/ | ||
public function __get( $name ) { | ||
|
||
// accessing the response_data object indirectly via attribute (useful when it's a class) | ||
return isset( $this->response_data->$name ) ? $this->response_data->$name : null; | ||
} | ||
|
||
|
||
/** | ||
* Returns the string representation of this response | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Response::to_string() | ||
* @return string the raw response | ||
*/ | ||
public function to_string() { | ||
|
||
return $this->raw_response_json; | ||
} | ||
|
||
|
||
/** | ||
* Returns the string representation of this response with any and all | ||
* sensitive elements masked or removed | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Response::to_string_safe() | ||
* @return string response safe for logging/displaying | ||
*/ | ||
public function to_string_safe() { | ||
|
||
// no sensitive data to mask | ||
return $this->to_string(); | ||
} | ||
|
||
|
||
} | ||
|
||
endif; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
/** | ||
* WooCommerce Plugin Framework | ||
* | ||
* This source file is subject to the GNU General Public License v3.0 | ||
* that is bundled with this package in the file license.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://www.gnu.org/licenses/gpl-3.0.html | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade the plugin to newer | ||
* versions in the future. If you wish to customize the plugin for your | ||
* needs please refer to http://www.skyverge.com | ||
* | ||
* @package SkyVerge/WooCommerce/API/Request | ||
* @author SkyVerge | ||
* @copyright Copyright (c) 2013-2015, SkyVerge, Inc. | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly | ||
|
||
if ( ! class_exists( 'SV_WC_API_REST_Request' ) ) : | ||
|
||
|
||
/** | ||
* Base REST API Request class | ||
* | ||
* @since 3.1.2-1 | ||
*/ | ||
class SV_WC_API_REST_Request implements SV_WC_API_Request { | ||
|
||
|
||
/** @var string the request method, one of HEAD, GET, PUT, PATCH, POST, DELETE */ | ||
protected $method; | ||
|
||
/** @var string the request path */ | ||
protected $path; | ||
|
||
/** @var array the request parameters, if any */ | ||
protected $params; | ||
|
||
|
||
/** | ||
* Construct REST request object | ||
* | ||
* @since 3.1.2-1 | ||
* @param string $method the request method, one of HEAD, GET, PUT, PATCH, POST, DELETE | ||
* @param string $path optional request path | ||
* @param array $params optional associative array of request parameters | ||
*/ | ||
public function __construct( $method, $path = '', $params = array() ) { | ||
$this->method = $method; | ||
$this->path = $path; | ||
$this->params = $params; | ||
} | ||
|
||
|
||
/** Getter Methods ******************************************************/ | ||
|
||
|
||
/** | ||
* Returns the method for this request: one of HEAD, GET, PUT, PATCH, POST, DELETE | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Request::get_method() | ||
* @return string the request method | ||
*/ | ||
public function get_method() { | ||
return $this->method; | ||
} | ||
|
||
|
||
/** | ||
* Returns the request path | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Request::get_path() | ||
* @return string the request path | ||
*/ | ||
public function get_path() { | ||
return $this->path; | ||
} | ||
|
||
|
||
/** | ||
* Returns the request params, if any | ||
* | ||
* @since 3.1.2-1 | ||
* @return array the request params | ||
*/ | ||
public function get_params() { | ||
return $this->params; | ||
} | ||
|
||
|
||
/** API Helper Methods ******************************************************/ | ||
|
||
|
||
/** | ||
* Returns the string representation of this request | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Request::to_string() | ||
* @return string request | ||
*/ | ||
public function to_string() { | ||
// URL encode params | ||
return build_query( $this->get_params() ); | ||
} | ||
|
||
|
||
/** | ||
* Returns the string representation of this request with any and all | ||
* sensitive elements masked or removed | ||
* | ||
* @since 3.1.2-1 | ||
* @see SV_WC_API_Request::to_string_safe() | ||
* @return string the request, safe for logging/displaying | ||
*/ | ||
public function to_string_safe() { | ||
|
||
return $this->to_string(); | ||
} | ||
|
||
|
||
} | ||
|
||
endif; |
Oops, something went wrong.