@@ -68,11 +68,14 @@ public function delete($url, array $headers = array())
6868 */
6969 private static function httpRequest ($ url , $ method , array $ headers = array (), $ data = null )
7070 {
71+ //adding the version header to the existing headers
72+ $ headers [] = self ::getVersionHeader ();
73+
7174 $ curl = curl_init ();
7275 curl_setopt ($ curl , CURLOPT_URL , $ url );
7376 curl_setopt ($ curl , CURLOPT_HEADER , 0 );
7477 curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , 1 );
75- curl_setopt ($ curl , CURLOPT_USERAGENT , "ConstantContact AppConnect PHP Library v1.1 " );
78+ curl_setopt ($ curl , CURLOPT_USERAGENT , "ConstantContact AppConnect PHP Library v " . Config:: get ( ' settings.version ' ) );
7679 curl_setopt ($ curl , CURLOPT_SSL_VERIFYPEER , 0 );
7780 curl_setopt ($ curl , CURLOPT_HTTPHEADER , $ headers );
7881 curl_setopt ($ curl , CURLOPT_CUSTOMREQUEST , $ method );
@@ -87,7 +90,7 @@ private static function httpRequest($url, $method, array $headers = array(), $da
8790
8891 // check if any errors were returned
8992 $ body = json_decode ($ response ->body , true );
90- if (isset ($ body [0 ]) && array_key_exists ('error_key ' , $ body [0 ])) {
93+ if (( isset ($ body [0 ]) && array_key_exists ('error_key ' , $ body [0 ])) || ( $ response -> error !== false )) {
9194 $ ex = new CtctException ($ response ->body );
9295 $ ex ->setCurlInfo ($ response ->info );
9396 $ ex ->setErrors ($ body );
@@ -96,4 +99,12 @@ private static function httpRequest($url, $method, array $headers = array(), $da
9699
97100 return $ response ;
98101 }
102+
103+ /**
104+ * Returns the version header for the rest calls
105+ * @return string
106+ */
107+ public static function getVersionHeader (){
108+ return 'x-ctct-request-source: sdk.php. ' . Config::get ('settings.version ' );
109+ }
99110}
0 commit comments