11<?php
22namespace SparkPost ;
3- use Ivory \HttpAdapter \HttpAdapterException ;
4- use SparkPost \SparkPost ;
5-
6-
73
84/**
9- * @desc SDK interface for managing SparkPost API endpoints
5+ * SDK interface for managing SparkPost API endpoints
106 */
117class APIResource {
128
139 /**
14- * @desc name of the API endpoint, mainly used for URL construction.
10+ * name of the API endpoint, mainly used for URL construction.
1511 * This is public to provide an interface
1612 *
1713 * @var string
1814 */
1915 public $ endpoint ;
2016
2117 /**
22- * @desc Mapping for values passed into the send method to the values needed for the respective API
18+ * Mapping for values passed into the send method to the values needed for the respective API
2319 * @var array
2420 */
2521 protected static $ parameterMappings = [];
2622
2723 /**
28- * @desc Sets up default structure and default values for the model that is acceptable by the API
24+ * Sets up default structure and default values for the model that is acceptable by the API
2925 * @var array
3026 */
3127 protected static $ structure = [];
3228
3329 /**
34- * @desc SparkPost reference for httpAdapters and configs
30+ * SparkPost reference for httpAdapters and configs
3531 */
3632 protected $ sparkpost ;
3733
3834 /**
39- * @desc Initializes config and httpAdapter for use later.
40- * @param $sparkpost SparkPost\SparkPost provides api configuration information
35+ * Initializes config and httpAdapter for use later.
36+ * @param $sparkpost \ SparkPost\SparkPost provides api configuration information
4137 */
4238 public function __construct (SparkPost $ sparkpost ) {
4339 $ this ->sparkpost = $ sparkpost ;
4440 }
4541
4642 /**
47- * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter
43+ * Private Method helper to reference parameter mappings and set the right value for the right parameter
4844 *
4945 * @param array $model (pass by reference) the set of values to map
5046 * @param string $mapKey a dot syntax path determining which value to set
@@ -76,9 +72,9 @@ protected function setMappedValue(&$model, $mapKey, $value) {
7672 }
7773
7874 /**
79- * @desc maps values from the passed in model to those needed for the request
80- * @param $requestConfig the passed in model
81- * @param $model the set of defaults
75+ * maps values from the passed in model to those needed for the request
76+ * @param array $requestConfig the passed in model
77+ * @param array $model the set of defaults
8278 * @return array A model ready for the body of a request
8379 */
8480 protected function buildRequestModel (Array $ requestConfig , Array $ model =[] ) {
@@ -89,39 +85,41 @@ protected function buildRequestModel(Array $requestConfig, Array $model=[] ) {
8985 }
9086
9187 /**
92- * @desc posts to the api with a supplied body
93- * @param body post body for the request
88+ * posts to the api with a supplied body
89+ * @param array $ body post body for the request
9490 * @return array Result of the request
9591 */
9692 public function create (Array $ body =[]) {
9793 return $ this ->callResource ( 'post ' , null , ['body ' =>$ body ]);
9894 }
9995
10096 /**
101- * @desc Makes a put request to the api with a supplied body
102- * @param body Put body for the request
97+ * Makes a put request to the api with a supplied body
98+ * @param $resourcePath
99+ * @param array $body Put body for the request
103100 * @return array Result of the request
101+ * @throws APIResponseException
104102 */
105103 public function update ( $ resourcePath , Array $ body =[]) {
106104 return $ this ->callResource ( 'put ' , $ resourcePath , ['body ' =>$ body ]);
107105 }
108106
109107 /**
110- * @desc Wrapper method for issuing GET request to current API endpoint
108+ * Wrapper method for issuing GET request to current API endpoint
111109 *
112110 * @param string $resourcePath (optional) string resource path of specific resource
113- * @param array $options (optional) query string parameters
111+ * @param array $query (optional) query string parameters
114112 * @return array Result of the request
115113 */
116114 public function get ( $ resourcePath =null , Array $ query =[] ) {
117115 return $ this ->callResource ( 'get ' , $ resourcePath , ['query ' =>$ query ] );
118116 }
119117
120118 /**
121- * @desc Wrapper method for issuing DELETE request to current API endpoint
119+ * Wrapper method for issuing DELETE request to current API endpoint
122120 *
123121 * @param string $resourcePath (optional) string resource path of specific resource
124- * @param array $options (optional) query string parameters
122+ * @param array $query (optional) query string parameters
125123 * @return array Result of the request
126124 */
127125 public function delete ( $ resourcePath =null , Array $ query =[] ) {
@@ -130,13 +128,13 @@ public function delete( $resourcePath=null, Array $query=[] ) {
130128
131129
132130 /**
133- * @desc assembles a URL for a request
131+ * assembles a URL for a request
134132 * @param string $resourcePath path after the initial endpoint
135- * @param array options array with an optional value of query with values to build a querystring from.
133+ * @param array $ options array with an optional value of query with values to build a querystring from.
136134 * @return string the assembled URL
137135 */
138136 private function buildUrl ($ resourcePath , $ options ) {
139- $ url = join ([ ' / ' , $ this ->endpoint , ' / ' ]) ;
137+ $ url = " / { $ this ->endpoint } / " ;
140138 if (!is_null ($ resourcePath )){
141139 $ url .= $ resourcePath ;
142140 }
@@ -151,8 +149,8 @@ private function buildUrl($resourcePath, $options) {
151149
152150
153151 /**
154- * @desc Prepares a body for put and post requests
155- * @param array options array with an optional value of body with values to build a request body from.
152+ * Prepares a body for put and post requests
153+ * @param array $ options array with an optional value of body with values to build a request body from.
156154 * @return string|null A json encoded string or null if no body was provided
157155 */
158156 private function buildBody ($ options ) {
@@ -165,9 +163,8 @@ private function buildBody($options) {
165163 return $ body ;
166164 }
167165
168-
169166 /**
170- * @desc Private Method for issuing GET and DELETE request to current API endpoint
167+ * Private Method for issuing GET and DELETE request to current API endpoint
171168 *
172169 * This method is responsible for getting the collection _and_
173170 * a specific entity from the API endpoint
@@ -178,6 +175,7 @@ private function buildBody($options) {
178175 * @param string $resourcePath (optional) string resource path of specific resource
179176 * @param array $options (optional) query string parameters
180177 * @return array Result set of action performed on resource
178+ * @throws APIResponseException
181179 */
182180 private function callResource ( $ action , $ resourcePath =null , $ options =[] ) {
183181 $ action = strtoupper ($ action ); // normalize
0 commit comments