11<?php
2- /**
2+ /**
33 * HTTP Client library
44 *
55 * PHP version 5.2
@@ -28,10 +28,10 @@ class Response
2828 function __construct ($ status_code = null , $ response_body = null , $ response_headers = null )
2929 {
3030 $ this ->_status_code = $ status_code ;
31- $ this ->_response_body = $ response_body ;
32- $ this ->_response_headers = $ response_headers ;
31+ $ this ->_body = $ response_body ;
32+ $ this ->_headers = $ response_headers ;
3333 }
34-
34+
3535 /**
3636 * The status code
3737 *
@@ -47,19 +47,19 @@ public function statusCode()
4747 *
4848 * @return array
4949 */
50- public function responseBody ()
50+ public function body ()
5151 {
52- return $ this ->_response_body ;
52+ return $ this ->_body ;
5353 }
5454
5555 /**
5656 * The response headers
5757 *
5858 * @return array
5959 */
60- public function responseHeaders ()
60+ public function headers ()
6161 {
62- return $ this ->_response_headers ;
62+ return $ this ->_headers ;
6363 }
6464}
6565
@@ -68,22 +68,22 @@ public function responseHeaders()
6868 */
6969class Client
7070{
71-
72- public
71+
72+ public
7373 $ host ,
7474 $ request_headers ,
7575 $ version ,
7676 $ url_path ,
77- $ methods ;
78-
77+ $ methods ;
78+
7979 /**
8080 * Initialize the client
8181 *
8282 * @param string $host the base url (e.g. https://api.sendgrid.com)
8383 * @param array $request_headers global request headers
8484 * @param string $version api version (configurable)
8585 * @param array $url_path holds the segments of the url path
86- */
86+ */
8787 function __construct ($ host , $ request_headers = null , $ version = null , $ url_path = null )
8888 {
8989 $ this ->host = $ host ;
@@ -110,7 +110,7 @@ private function _buildClient($name = null)
110110 $ this ->url_path = [];
111111 return new Client ($ this ->host , $ this ->request_headers , $ this ->version , $ url_path );
112112 }
113-
113+
114114 /**
115115 * Subclass this function for your own needs.
116116 * Or just pass the version as part of the URL
@@ -120,7 +120,7 @@ private function _buildClient($name = null)
120120 *
121121 * @return string
122122 */
123- private function _buildVersionedUrl ($ url )
123+ private function _buildVersionedUrl ($ url )
124124 {
125125 return sprintf ("%s%s%s " , $ this ->host , $ this ->version , $ url );
126126 }
@@ -129,10 +129,10 @@ private function _buildVersionedUrl($url)
129129 * Build the final URL to be passed
130130 *
131131 * @param array $query_params an array of all the query parameters
132- *
132+ *
133133 * @return string
134134 */
135- private function _buildUrl ($ query_params = null )
135+ private function _buildUrl ($ query_params = null )
136136 {
137137 $ url = '/ ' .implode ('/ ' , $ this ->url_path );
138138 if (isset ($ query_params )) {
@@ -155,10 +155,10 @@ private function _buildUrl($query_params = null)
155155 * @param string $url the final url to call
156156 * @param array $request_body request body
157157 * @param array $request_headers any additional request headers
158- *
158+ *
159159 * @return Response object
160160 */
161- public function makeRequest ($ method , $ url , $ request_body = null , $ request_headers = null )
161+ public function makeRequest ($ method , $ url , $ request_body = null , $ request_headers = null )
162162 {
163163 $ curl = curl_init ($ url );
164164 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
@@ -179,9 +179,9 @@ public function makeRequest($method, $url, $request_body = null, $request_header
179179 $ status_code = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
180180 $ response_body = substr ($ curl_response , $ header_size );
181181 $ response_header = substr ($ curl_response , 0 , $ header_size );
182-
182+
183183 curl_close ($ curl );
184-
184+
185185 return new Response ($ status_code , $ response_body , $ response_header );
186186 }
187187
@@ -192,10 +192,10 @@ public function makeRequest($method, $url, $request_body = null, $request_header
192192 * in your url, you must use this method.
193193 *
194194 * @param string $name name of the url segment
195- *
195+ *
196196 * @return Client object
197197 */
198- public function _ ($ name = null )
198+ public function _ ($ name = null )
199199 {
200200 return $ this ->_buildClient ($ name );
201201 }
@@ -206,24 +206,24 @@ public function _($name = null)
206206 *
207207 * @param string $name name of the dynamic method call or HTTP verb
208208 * @param array $args parameters passed with the method call
209- *
209+ *
210210 * @return Client or Response object
211211 */
212212 public function __call ($ name , $ args )
213- {
213+ {
214214 if ($ name == 'version ' ) {
215215 $ this ->version = $ args [0 ];
216216 return $ this ->_ ();
217217 }
218-
218+
219219 if (in_array ($ name , $ this ->methods )) {
220220 $ query_params = ((count ($ args ) >= 2 ) ? $ args [1 ] : null );
221221 $ url = $ this ->_buildUrl ($ query_params );
222222 $ request_body = ($ args ? $ args [0 ] : null );
223223 $ request_headers = ((count ($ args ) == 3 ) ? $ args [2 ] : null );
224224 return $ this ->makeRequest ($ name , $ url , $ request_body , $ request_headers );
225225 }
226-
226+
227227 return $ this ->_ ($ name );
228228 }
229229}
0 commit comments