Skip to content

Commit b08c6b4

Browse files
committed
Fix #150: Rename Resource to ResourceBase and leave deprecation note
1 parent 8c75ab0 commit b08c6b4

File tree

3 files changed

+99
-83
lines changed

3 files changed

+99
-83
lines changed

lib/SparkPost/Resource.php

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,87 +2,11 @@
22

33
namespace SparkPost;
44

5-
class Resource
5+
/**
6+
* Class Resource
7+
* @package SparkPost
8+
* @deprecated Soft reservations placed on name Resource (as of PHP7)
9+
*/
10+
class Resource extends ResourceBase
611
{
7-
/**
8-
* SparkPost object used to make requests.
9-
*/
10-
protected $sparkpost;
11-
12-
/**
13-
* The api endpoint that gets prepended to all requests send through this resource.
14-
*/
15-
protected $endpoint;
16-
17-
/**
18-
* Sets up the Resource.
19-
*
20-
* @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to
21-
* @param string $endpoint - the endpoint that this resource wraps
22-
*/
23-
public function __construct(SparkPost $sparkpost, $endpoint)
24-
{
25-
$this->sparkpost = $sparkpost;
26-
$this->endpoint = $endpoint;
27-
}
28-
29-
/**
30-
* Sends get request to API at the set endpoint.
31-
*
32-
* @see SparkPost->request()
33-
*/
34-
public function get($uri = '', $payload = [], $headers = [])
35-
{
36-
return $this->request('GET', $uri, $payload, $headers);
37-
}
38-
39-
/**
40-
* Sends put request to API at the set endpoint.
41-
*
42-
* @see SparkPost->request()
43-
*/
44-
public function put($uri = '', $payload = [], $headers = [])
45-
{
46-
return $this->request('PUT', $uri, $payload, $headers);
47-
}
48-
49-
/**
50-
* Sends post request to API at the set endpoint.
51-
*
52-
* @see SparkPost->request()
53-
*/
54-
public function post($payload = [], $headers = [])
55-
{
56-
return $this->request('POST', '', $payload, $headers);
57-
}
58-
59-
/**
60-
* Sends delete request to API at the set endpoint.
61-
*
62-
* @see SparkPost->request()
63-
*/
64-
public function delete($uri = '', $payload = [], $headers = [])
65-
{
66-
return $this->request('DELETE', $uri, $payload, $headers);
67-
}
68-
69-
/**
70-
* Sends requests to SparkPost object to the resource endpoint.
71-
*
72-
* @see SparkPost->request()
73-
*
74-
* @return SparkPostPromise or SparkPostResponse depending on sync or async request
75-
*/
76-
public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
77-
{
78-
if (is_array($uri)) {
79-
$headers = $payload;
80-
$payload = $uri;
81-
$uri = '';
82-
}
83-
84-
$uri = $this->endpoint.'/'.$uri;
85-
86-
return $this->sparkpost->request($method, $uri, $payload, $headers);
87-
}
8812
}

lib/SparkPost/ResourceBase.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
namespace SparkPost;
4+
5+
/**
6+
* Class ResourceBase
7+
* @package SparkPost
8+
*/
9+
class ResourceBase
10+
{
11+
/**
12+
* SparkPost object used to make requests.
13+
*/
14+
protected $sparkpost;
15+
16+
/**
17+
* The api endpoint that gets prepended to all requests send through this resource.
18+
*/
19+
protected $endpoint;
20+
21+
/**
22+
* Sets up the Resource.
23+
*
24+
* @param SparkPost $sparkpost - the sparkpost instance that this resource is attached to
25+
* @param string $endpoint - the endpoint that this resource wraps
26+
*/
27+
public function __construct(SparkPost $sparkpost, $endpoint)
28+
{
29+
$this->sparkpost = $sparkpost;
30+
$this->endpoint = $endpoint;
31+
}
32+
33+
/**
34+
* Sends get request to API at the set endpoint.
35+
*
36+
* @see SparkPost->request()
37+
*/
38+
public function get($uri = '', $payload = [], $headers = [])
39+
{
40+
return $this->request('GET', $uri, $payload, $headers);
41+
}
42+
43+
/**
44+
* Sends put request to API at the set endpoint.
45+
*
46+
* @see SparkPost->request()
47+
*/
48+
public function put($uri = '', $payload = [], $headers = [])
49+
{
50+
return $this->request('PUT', $uri, $payload, $headers);
51+
}
52+
53+
/**
54+
* Sends post request to API at the set endpoint.
55+
*
56+
* @see SparkPost->request()
57+
*/
58+
public function post($payload = [], $headers = [])
59+
{
60+
return $this->request('POST', '', $payload, $headers);
61+
}
62+
63+
/**
64+
* Sends delete request to API at the set endpoint.
65+
*
66+
* @see SparkPost->request()
67+
*/
68+
public function delete($uri = '', $payload = [], $headers = [])
69+
{
70+
return $this->request('DELETE', $uri, $payload, $headers);
71+
}
72+
73+
/**
74+
* Sends requests to SparkPost object to the resource endpoint.
75+
*
76+
* @see SparkPost->request()
77+
*
78+
* @return SparkPostPromise or SparkPostResponse depending on sync or async request
79+
*/
80+
public function request($method = 'GET', $uri = '', $payload = [], $headers = [])
81+
{
82+
if (is_array($uri)) {
83+
$headers = $payload;
84+
$payload = $uri;
85+
$uri = '';
86+
}
87+
88+
$uri = $this->endpoint.'/'.$uri;
89+
90+
return $this->sparkpost->request($method, $uri, $payload, $headers);
91+
}
92+
}

lib/SparkPost/Transmission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace SparkPost;
44

5-
class Transmission extends Resource
5+
class Transmission extends ResourceBase
66
{
77
public function __construct(SparkPost $sparkpost)
88
{

0 commit comments

Comments
 (0)