summaryrefslogtreecommitdiffstats
path: root/lib/SparkPost/ResourceBase.php
diff options
context:
space:
mode:
authorzaporylie <jakub@nymedia.no>2016-10-13 21:59:20 +0200
committerzaporylie <jakub@nymedia.no>2016-10-13 21:59:20 +0200
commitb08c6b4acd4bebb7ead050eb486b37f9787b766f (patch)
tree76e42543d611f3b9b4b97a58bf3c5536ee83d1ca /lib/SparkPost/ResourceBase.php
parent8c75ab08e18bc349e39582c6f8d17a9970c4a3c0 (diff)
downloadphp-sparkpost-b08c6b4acd4bebb7ead050eb486b37f9787b766f.zip
php-sparkpost-b08c6b4acd4bebb7ead050eb486b37f9787b766f.tar.gz
php-sparkpost-b08c6b4acd4bebb7ead050eb486b37f9787b766f.tar.bz2
Fix #150: Rename Resource to ResourceBase and leave deprecation note
Diffstat (limited to 'lib/SparkPost/ResourceBase.php')
-rw-r--r--lib/SparkPost/ResourceBase.php92
1 files changed, 92 insertions, 0 deletions
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);
+ }
+}