diff options
author | Ewan Dennis <ewandennis@users.noreply.github.com> | 2016-10-26 13:34:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 13:34:36 +0100 |
commit | bd9440b5f3fa43d7cb0828ab0b0495418e93b65a (patch) | |
tree | 1d776de4581fc10380c9614bc05ab5cfa6dbbd51 | |
parent | ba44284bab2d8bbb253d76d8c436e124ec80e4e7 (diff) | |
parent | b08c6b4acd4bebb7ead050eb486b37f9787b766f (diff) | |
download | php-sparkpost-bd9440b5f3fa43d7cb0828ab0b0495418e93b65a.zip php-sparkpost-bd9440b5f3fa43d7cb0828ab0b0495418e93b65a.tar.gz php-sparkpost-bd9440b5f3fa43d7cb0828ab0b0495418e93b65a.tar.bz2 |
Merge pull request #154 from zaporylie/master
Fix #150: Rename Resource to ResourceBase and leave deprecation note
-rw-r--r-- | lib/SparkPost/Resource.php | 88 | ||||
-rw-r--r-- | lib/SparkPost/ResourceBase.php | 92 | ||||
-rw-r--r-- | lib/SparkPost/Transmission.php | 2 |
3 files changed, 99 insertions, 83 deletions
diff --git a/lib/SparkPost/Resource.php b/lib/SparkPost/Resource.php index 7c88743..4b3550d 100644 --- a/lib/SparkPost/Resource.php +++ b/lib/SparkPost/Resource.php @@ -2,87 +2,11 @@ namespace SparkPost; -class Resource +/** + * Class Resource + * @package SparkPost + * @deprecated Soft reservations placed on name Resource (as of PHP7) + */ +class Resource extends ResourceBase { - /** - * SparkPost object used to make requests. - */ - protected $sparkpost; - - /** - * The api endpoint that gets prepended to all requests send through this resource. - */ - protected $endpoint; - - /** - * Sets up the Resource. - * - * @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to - * @param string $endpoint - the endpoint that this resource wraps - */ - public function __construct(SparkPost $sparkpost, $endpoint) - { - $this->sparkpost = $sparkpost; - $this->endpoint = $endpoint; - } - - /** - * Sends get request to API at the set endpoint. - * - * @see SparkPost->request() - */ - public function get($uri = '', $payload = [], $headers = []) - { - return $this->request('GET', $uri, $payload, $headers); - } - - /** - * Sends put request to API at the set endpoint. - * - * @see SparkPost->request() - */ - public function put($uri = '', $payload = [], $headers = []) - { - return $this->request('PUT', $uri, $payload, $headers); - } - - /** - * Sends post request to API at the set endpoint. - * - * @see SparkPost->request() - */ - public function post($payload = [], $headers = []) - { - return $this->request('POST', '', $payload, $headers); - } - - /** - * Sends delete request to API at the set endpoint. - * - * @see SparkPost->request() - */ - public function delete($uri = '', $payload = [], $headers = []) - { - return $this->request('DELETE', $uri, $payload, $headers); - } - - /** - * Sends requests to SparkPost object to the resource endpoint. - * - * @see SparkPost->request() - * - * @return SparkPostPromise or SparkPostResponse depending on sync or async request - */ - public function request($method = 'GET', $uri = '', $payload = [], $headers = []) - { - if (is_array($uri)) { - $headers = $payload; - $payload = $uri; - $uri = ''; - } - - $uri = $this->endpoint.'/'.$uri; - - return $this->sparkpost->request($method, $uri, $payload, $headers); - } } diff --git a/lib/SparkPost/ResourceBase.php b/lib/SparkPost/ResourceBase.php new file mode 100644 index 0000000..4e11ac2 --- /dev/null +++ b/lib/SparkPost/ResourceBase.php @@ -0,0 +1,92 @@ +<?php + +namespace SparkPost; + +/** + * Class ResourceBase + * @package SparkPost + */ +class ResourceBase +{ + /** + * SparkPost object used to make requests. + */ + protected $sparkpost; + + /** + * The api endpoint that gets prepended to all requests send through this resource. + */ + protected $endpoint; + + /** + * Sets up the Resource. + * + * @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to + * @param string $endpoint - the endpoint that this resource wraps + */ + public function __construct(SparkPost $sparkpost, $endpoint) + { + $this->sparkpost = $sparkpost; + $this->endpoint = $endpoint; + } + + /** + * Sends get request to API at the set endpoint. + * + * @see SparkPost->request() + */ + public function get($uri = '', $payload = [], $headers = []) + { + return $this->request('GET', $uri, $payload, $headers); + } + + /** + * Sends put request to API at the set endpoint. + * + * @see SparkPost->request() + */ + public function put($uri = '', $payload = [], $headers = []) + { + return $this->request('PUT', $uri, $payload, $headers); + } + + /** + * Sends post request to API at the set endpoint. + * + * @see SparkPost->request() + */ + public function post($payload = [], $headers = []) + { + return $this->request('POST', '', $payload, $headers); + } + + /** + * Sends delete request to API at the set endpoint. + * + * @see SparkPost->request() + */ + public function delete($uri = '', $payload = [], $headers = []) + { + return $this->request('DELETE', $uri, $payload, $headers); + } + + /** + * Sends requests to SparkPost object to the resource endpoint. + * + * @see SparkPost->request() + * + * @return SparkPostPromise or SparkPostResponse depending on sync or async request + */ + public function request($method = 'GET', $uri = '', $payload = [], $headers = []) + { + if (is_array($uri)) { + $headers = $payload; + $payload = $uri; + $uri = ''; + } + + $uri = $this->endpoint.'/'.$uri; + + return $this->sparkpost->request($method, $uri, $payload, $headers); + } +} diff --git a/lib/SparkPost/Transmission.php b/lib/SparkPost/Transmission.php index 6e44ab5..8efc934 100644 --- a/lib/SparkPost/Transmission.php +++ b/lib/SparkPost/Transmission.php @@ -2,7 +2,7 @@ namespace SparkPost; -class Transmission extends Resource +class Transmission extends ResourceBase { public function __construct(SparkPost $sparkpost) { |