@@ -30,17 +30,17 @@ class APIResource {
3030 protected static $ structure = [];
3131
3232 /**
33- * TODO: Docs
33+ * @dec connection config for making requests.
3434 */
3535 private $ config ;
3636
3737 /**
38- * TODO: Docs
38+ * @desc Ivory\HttpAdapter\HttpAdapterInterface to make requests through.
3939 */
40- private $ httpAdapter ;
40+ protected $ httpAdapter ;
4141
4242 /**
43- * TODO: Docs
43+ * @desc Default config values. Passed in values will override these.
4444 */
4545 private static $ apiDefaults = [
4646 'host ' =>'api.sparkpost.com ' ,
@@ -52,7 +52,9 @@ class APIResource {
5252 ];
5353
5454 /**
55- * @desc TODO: Docs
55+ * @desc Initializes config and httpAdapter for use later.
56+ * @param $httpAdapter Ivory\HttpAdapter\HttpAdapterInterface to make requests through.
57+ * @param $config connection config for making requests.
5658 */
5759 public function __construct ($ httpAdapter , $ config ) {
5860 //config needs to be setup before adapter because of default adapter settings
@@ -84,7 +86,6 @@ private function getHttpHeaders(Array $headers = null) {
8486 * @desc Helper function for getting the configuration for http requests
8587 * @return \Ivory\HttpAdapter\Configuration
8688 */
87- // TODO: Need to figure out how to set strictSSL
8889 private function getHttpConfig ($ config ) {
8990 // get composer.json to extract version number
9091 $ composerFile = file_get_contents (dirname (__FILE__ ) . "/../../composer.json " );
@@ -99,7 +100,9 @@ private function getHttpConfig($config) {
99100 }
100101
101102 /**
102- * TODO: Docs
103+ * @desc Validates and sets up the httpAdapter
104+ * @param $httpAdapter Ivory\HttpAdapter\HttpAdapterInterface to make requests through.
105+ * @throws \Exception
103106 */
104107 public function setHttpAdapter ($ httpAdapter ) {
105108 if (!$ httpAdapter instanceOf HttpAdapterInterface) {
@@ -133,6 +136,10 @@ public function setConfig(Array $settingsConfig) {
133136
134137 /**
135138 * @desc Private Method helper to reference parameter mappings and set the right value for the right parameter
139+ *
140+ * @param array $model (pass by reference) the set of values to map
141+ * @param string $mapKey a dot syntax path determining which value to set
142+ * @param mixed $value value for the given path
136143 */
137144 protected function setMappedValue (&$ model , $ mapKey , $ value ) {
138145 //get mapping
@@ -160,7 +167,10 @@ protected function setMappedValue (&$model, $mapKey, $value) {
160167 }
161168
162169 /**
163- * TODO: Docs
170+ * @desc maps values from the passed in model to those needed for the request
171+ * @param $requestConfig the passed in model
172+ * @param $model the set of defaults
173+ * @return array A model ready for the body of a request
164174 */
165175 protected function buildRequestModel (Array $ requestConfig , Array $ model =[] ) {
166176 foreach ($ requestConfig as $ key => $ value ) {
@@ -170,14 +180,18 @@ protected function buildRequestModel(Array $requestConfig, Array $model=[] ) {
170180 }
171181
172182 /**
173- * TODO: Docs
183+ * @desc posts to the api with a supplied body
184+ * @param body post body for the request
185+ * @return array Result of the request
174186 */
175187 public function create (Array $ body =[]) {
176188 return $ this ->callResource ( 'post ' , null , ['body ' =>$ body ]);
177189 }
178190
179191 /**
180- * TODO: Docs
192+ * @desc Makes a put request to the api with a supplied body
193+ * @param body Put body for the request
194+ * @return array Result of the request
181195 */
182196 public function update ( $ resourcePath , Array $ body =[]) {
183197 return $ this ->callResource ( 'put ' , $ resourcePath , ['body ' =>$ body ]);
@@ -188,7 +202,7 @@ public function update( $resourcePath, Array $body=[]) {
188202 *
189203 * @param string $resourcePath (optional) string resource path of specific resource
190204 * @param array $options (optional) query string parameters
191- * @return array Result set of transmissions found
205+ * @return array Result of the request
192206 */
193207 public function get ( $ resourcePath =null , Array $ query =[] ) {
194208 return $ this ->callResource ( 'get ' , $ resourcePath , ['query ' =>$ query ] );
@@ -199,15 +213,18 @@ public function get( $resourcePath=null, Array $query=[] ) {
199213 *
200214 * @param string $resourcePath (optional) string resource path of specific resource
201215 * @param array $options (optional) query string parameters
202- * @return array Result set of transmissions found
216+ * @return array Result of the request
203217 */
204218 public function delete ( $ resourcePath =null , Array $ query =[] ) {
205219 return $ this ->callResource ( 'delete ' , $ resourcePath , ['query ' =>$ query ] );
206220 }
207221
208222
209223 /**
210- * TODO: docs
224+ * @desc assembles a URL for a request
225+ * @param string $resourcePath path after the initial endpoint
226+ * @param array options array with an optional value of query with values to build a querystring from.
227+ * @return string the assembled URL
211228 */
212229 private function buildUrl ($ resourcePath , $ options ) {
213230 $ url = join (['/ ' , $ this ->endpoint , '/ ' ]);
@@ -225,7 +242,9 @@ private function buildUrl($resourcePath, $options) {
225242
226243
227244 /**
228- * TODO: Docs
245+ * @desc Prepares a body for put and post requests
246+ * @param array options array with an optional value of body with values to build a request body from.
247+ * @return string|null A json encoded string or null if no body was provided
229248 */
230249 private function buildBody ($ options ) {
231250 $ body = null ;
@@ -270,7 +289,7 @@ private function callResource( $action, $resourcePath=null, $options=[] ) {
270289 * Handles 4XX responses
271290 */
272291 catch (HttpAdapterException $ exception ) {
273- $ response = $ exception ->getBody ();
292+ $ response = $ exception ->getResponse ();
274293 $ statusCode = $ response ->getStatusCode ();
275294 if ($ statusCode === 404 ) {
276295 throw new \Exception ("The specified resource does not exist " , 404 );
0 commit comments