diff --git a/class.baseclient.php b/class.baseclient.php index 30e9a0a..fc90052 100644 --- a/class.baseclient.php +++ b/class.baseclient.php @@ -1,35 +1,40 @@ HAPIKey = $HAPIKey; + * @param HAPIKey: String value of HubSpot API Key for requests + * access_token: String value of Hubspot OAuth Token + * refresh_token: String value of refresh token given initially for OAuth + * client_id: Unique ID for your registered app + * + * */ + public function __construct( $HAPIKey=null, $access_token=null, $refresh_token=null, $client_id=null, $userAgent="haPiHP default UserAgent" ) { + + if ( $HAPIKey and $access_token ) { + throw new Exception( "Cannot use hapikey and OAuth token", 1 ); + } + else { + $this->HAPIKey = $HAPIKey; + print_r( "HAPIKey:".$this->HAPIKey ); + $this->ACCESS_TOKEN = $access_token; + print_r( "token:".$this->ACCESS_TOKEN ); + } $this->userAgent = $userAgent; + } /** @@ -74,8 +92,7 @@ public function __construct($HAPIKey,$userAgent="haPiHP default UserAgent") * * @return integer */ - public function getLastStatus() - { + public function getLastStatus() { return (int)$this->lastStatus; } @@ -87,10 +104,9 @@ public function getLastStatus() * * @throws HubSpot_Exception */ - protected function get_api() - { - if ( $this->isBlank($this->API_PATH) ) - throw new HubSpot_Exception('API_PATH must be defined'); + protected function get_api() { + if ( $this->isBlank( $this->API_PATH ) ) + throw new HubSpot_Exception( 'API_PATH must be defined' ); else return $this->API_PATH; } @@ -103,10 +119,9 @@ protected function get_api() * * @throws HubSpot_Exception */ - protected function get_api_version() - { - if ( $this->isBlank($this->API_VERSION) ) - throw new HubSpot_Exception('API_VERSION must be defined'); + protected function get_api_version() { + if ( $this->isBlank( $this->API_VERSION ) ) + throw new HubSpot_Exception( 'API_VERSION must be defined' ); else return $this->API_VERSION; } @@ -115,11 +130,10 @@ protected function get_api_version() * Allows developer to set testing flag to true in order to * execute api requests against hubapiqa.com * - * @param $testing: Boolean + * @param unknown $testing: Boolean */ - public function set_is_test($testing) { - if ( $testing == TRUE ) - { + public function set_is_test( $testing ) { + if ( $testing == TRUE ) { $this->isTest = TRUE; } } @@ -128,29 +142,62 @@ public function set_is_test($testing) { * Returns the hapi domain to use for requests based on isTesting * * @returns: String value of domain, including https protocol - */ - protected function get_domain() - { - if ( $this->isTest == TRUE ) - return $this->QA_DOMAIN; - else - return $this->PROD_DOMAIN; + * */ + protected function get_domain() { + if ( $this->isTest == true ) { + return $this->QA_DOMAIN; + } else { + return $this->PROD_DOMAIN; + } } /** - * Creates the url to be used for the api request + * Creates the url to be used for the api request. If OAuth token is provided but invalid, will attempt a refresh. * * @param endpoint: String value for the endpoint to be used (appears after version in url) * @param params: Array containing query parameters and values * * @returns String - */ - protected function get_request_url($endpoint, $params) - { - $paramstring = $this->array_to_params($params); - - return $this->get_domain() . $this->PATH_DIV.$this->get_api() . $this->PATH_DIV . $this->get_api_version() . - $this->PATH_DIV . $endpoint . $this->KEY_PARAM . $this->HAPIKey . $paramstring; + * */ + protected function get_request_url( $endpoint, $params ) { + $paramstring = $this->array_to_params( $params ); + echo $this->HAPIKey; + if ( $this->HAPIKey ) { + print_r( "Trying to use hapikey" ); + return $this->get_domain() . $this->PATH_DIV . + $this->get_api() . $this->PATH_DIV . + $this->get_api_version() . $this->PATH_DIV . + $endpoint . + $this->API_KEY_PARAM . $this->HAPIKey . + $paramstring; + } + else { + print "went to else"; + if ( $this->check_auth()>=400 ) { + print_r( "Auth check failed" ); + try { + $refreshed_token = $this->refresh_access_token( $this->REFRESH_TOKEN, $this->CLIENT_ID ); + $this->ACCESS_TOKEN = $refreshed_token['access_token']; + return $this->get_domain() . $this->PATH_DIV . + $this->get_api() . $this->PATH_DIV . + $this->get_api_version() . $this->PATH_DIV . + $endpoint . + $this->TOKEN_PARAM . $this->ACCESS_TOKEN . + $paramstring; + + } catch ( HubSpot_Exception $e ) { + print_r( 'Unable to refresh the OAuth token. Please provide a valid access_token or refresh_token' ); + } + } + else { + return $this->get_domain() . $this->PATH_DIV . + $this->get_api() . $this->PATH_DIV . + $this->get_api_version() . $this->PATH_DIV . + $endpoint . + $this->TOKEN_PARAM . $this->ACCESS_TOKEN . + $paramstring; + } + } } /** @@ -159,39 +206,37 @@ protected function get_request_url($endpoint, $params) * @param endpoint: String value for the endpoint to be used (appears after version in url) * @param params: Array containing query parameters and values * - * @return String - */ - protected function get_forms_request_url($url_base,$params) - { - $paramstring = $this->array_to_params($params); - - return $url_base . $this->KEY_PARAM . $this->HAPIKey . $paramstring; + * @returns String + * */ + protected function get_forms_request_url( $url_base, $params ) { + $paramstring = $this->array_to_params( $params ); + return $url_base . + $paramstring; } /** * Executes HTTP GET request * - * @param URL: String value for the URL to GET + * @param URL: String value for the URL to GET * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_get_request($url) - { + protected function execute_get_request( $url ) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); // new - $output = curl_exec($ch); - $errno = curl_errno($ch); - $error = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + $output = curl_exec( $ch ); + $errno = curl_errno( $ch ); + $error = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $errno > 0 ) - throw new HubSpot_Exception('cURL error: ' . $error); + throw new HubSpot_Exception( 'cURL error: ' . $error ); else return $output; } @@ -199,68 +244,62 @@ protected function execute_get_request($url) /** * Executes HTTP POST request * - * @param URL: String value for the URL to POST to + * @param URL: String value for the URL to POST to * @param fields: Array containing names and values for fields to post * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_post_request($url, $body, $formenc = FALSE) - { + protected function execute_post_request( $url, $body, $formenc = FALSE ) { // intialize cURL and send POST data $ch = curl_init(); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); // new - - if ($formenc) - { - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); - } - - $output = curl_exec($ch); - $errno = curl_errno($ch); - $error = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); - - if ( $errno > 0 ) - throw new HubSpot_Exception('cURL error: ' . $error); - else + curl_setopt( $ch, CURLOPT_POST, true ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + if ( $formenc ) + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded' ) ); + $output = curl_exec( $ch ); + $errno = curl_errno( $ch ); + $error = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); + if ( $errno > 0 ) { + throw new HubSpot_Exception ( 'cURL error: ' + $error ); + } else { return $output; + } } /** * Executes HTTP POST request with JSON as the POST body * - * @param URL String value for the URL to POST to - * @param fields Array containing names and values for fields to post + * @param URL String value for the URL to POST to + * @param fields Array containing names and values for fields to post * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_JSON_post_request($url, $body) - { + protected function execute_JSON_post_request( $url, $body ) { // intialize cURL and send POST data $ch = curl_init(); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); // new - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // new - $output = curl_exec($ch); - $errno = curl_errno($ch); - $error = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_POST, true ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json' ) ); + $output = curl_exec( $ch ); + $errno = curl_errno( $ch ); + $error = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $errno > 0 ) - throw new HubSpot_Exception('cURL error: ' . $error); + throw new HubSpot_Exception( 'cURL error: ' . $error ); else return $output; } @@ -268,31 +307,30 @@ protected function execute_JSON_post_request($url, $body) /** * Executes HTTP POST request with XML as the POST body * - * @param URL String value for the URL to POST to - * @param fields Array containing names and values for fields to post + * @param URL String value for the URL to POST to + * @param fields Array containing names and values for fields to post * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_xml_post_request($url, $body) - { + protected function execute_xml_post_request( $url, $body ) { // intialize cURL and send POST data $ch = curl_init(); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml')); - $output = curl_exec($ch); - $errno = curl_errno($ch); - $error = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_POST, true ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/atom+xml' ) ); + $output = curl_exec( $ch ); + $errno = curl_errno( $ch ); + $error = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $errno > 0 ) - throw new HubSpot_Exception('cURL error: ' . $error); + throw new HubSpot_Exception( 'cURL error: ' . $error ); else return $output; } @@ -300,31 +338,30 @@ protected function execute_xml_post_request($url, $body) /** * Executes HTTP PUT request * - * @param URL String value for the URL to PUT to - * @param body String value of the body of the PUT request + * @param URL String value for the URL to PUT to + * @param body String value of the body of the PUT request * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_put_request($url, $body) - { + protected function execute_put_request( $url, $body ) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($body))); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($ch, CURLOPT_POSTFIELDS,$body); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - $result = curl_exec($ch); - $apierr = curl_errno($ch); - $errmsg = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen( $body ) ) ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT" ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); + $result = curl_exec( $ch ); + $apierr = curl_errno( $ch ); + $errmsg = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $apierr > 0 ) - throw new HubSpot_Exception('cURL error: ' . $errmsg); + throw new HubSpot_Exception( 'cURL error: ' . $errmsg ); else return $result; } @@ -332,31 +369,30 @@ protected function execute_put_request($url, $body) /** * Executes HTTP PUT request with XML as the PUT body * - * @param URL String value for the URL to PUT to - * @param body String value of the body of the PUT request + * @param URL String value for the URL to PUT to + * @param body String value of the body of the PUT request * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_xml_put_request($url, $body) - { + protected function execute_xml_put_request( $url, $body ) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml','Content-Length: ' . strlen($body))); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($ch, CURLOPT_POSTFIELDS,$body); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - $result = curl_exec($ch); - $apierr = curl_errno($ch); - $errmsg = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/atom+xml', 'Content-Length: ' . strlen( $body ) ) ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT" ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); + $result = curl_exec( $ch ); + $apierr = curl_errno( $ch ); + $errmsg = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $apierr > 0 ) - throw new HubSpot_Exception('cURL error: ' . $errmsg); + throw new HubSpot_Exception( 'cURL error: ' . $errmsg ); else return $result; } @@ -364,31 +400,30 @@ protected function execute_xml_put_request($url, $body) /** * Executes HTTP DELETE request * - * @param URL String value for the URL to DELETE to - * @param body String value of the body of the DELETE request + * @param URL String value for the URL to DELETE to + * @param body String value of the body of the DELETE request * * @return Body of request result * * @throws HubSpot_Exception */ - protected function execute_delete_request($url, $body) - { + protected function execute_delete_request( $url, $body ) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($body))); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($ch, CURLOPT_POSTFIELDS,$body); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - $result = curl_exec($ch); - $apierr = curl_errno($ch); - $errmsg = curl_error($ch); - $this->setLastStatusFromCurl($ch); - curl_close($ch); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen( $body ) ) ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "DELETE" ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); + $result = curl_exec( $ch ); + $apierr = curl_errno( $ch ); + $errmsg = curl_error( $ch ); + $this->setLastStatusFromCurl( $ch ); + curl_close( $ch ); if ( $apierr > 0 ) - throw new HubSpot_Exception('cURL error: ' . $errmsg); + throw new HubSpot_Exception( 'cURL error: ' . $errmsg ); else return $result; } @@ -396,45 +431,38 @@ protected function execute_delete_request($url, $body) /** * Converts an array into url friendly list of parameters * - * @param array params Multidimensional array of parameters (name=>value) + * @param array params Multidimensional array of parameters (name=>value) * * @return String of url friendly parameters (&name=value&foo=bar) */ - protected function array_to_params($params) - { + protected function array_to_params( $params ) { $paramstring = ''; - if ( $params != NULL ) - { - foreach ( $params as $parameter => $value ) - { - if ( is_array($value) ) - { - foreach ( $value as $subparam ) - { - $paramstring = $paramstring . '&' . $parameter . '=' . urlencode($subparam); + + if ( $params != NULL ) { + foreach ( $params as $parameter => $value ) { + if ( is_array( $value ) ) { + foreach ( $value as $subparam ) { + $paramstring = $paramstring . '&' . $parameter . '=' . urlencode( $subparam ); } } - else - { - $paramstring = $paramstring . '&' . $parameter . '=' . urlencode($value); + else { + $paramstring = $paramstring . '&' . $parameter . '=' . urlencode( $value ); } } } - return $paramstring; } /** * Utility function used to determine if variable is empty * - * @param s Variable to be evaluated + * @param s Variable to be evaluated * * @returns Boolean */ - protected function isBlank ($s) - { - if ( (trim($s)=='') OR ($s == NULL) ) + protected function isBlank( $s ) { + if ( ( trim( $s )=='' ) or ( $s == NULL ) ) return true; else return false; @@ -445,9 +473,70 @@ protected function isBlank ($s) * * @param resource $ch */ - protected function setLastStatusFromCurl($ch) - { - $info = curl_getinfo($ch); - $this->lastStatus = (isset($info['http_code'])) ? $info['http_code'] : null; + protected function setLastStatusFromCurl( $ch ) { + $info = curl_getinfo( $ch ); + $this->lastStatus = ( isset( $info['http_code'] ) ) ? $info['http_code'] : null; + } + + /** + * Quick check of access_token + * + * + * @return: Response code for request + * + * */ + protected function check_auth() { + $url = 'https://api.hubapi.com/contacts/v1/properties/email?access_token='.$this->ACCESS_TOKEN; + print_r( $url ); + $ch = curl_init(); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); + curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + $output = curl_exec( $ch ); + $response_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); + curl_close( $ch ); + return $response_code; } + /** + * Refresh OAuth token + * + * @param refresh_token: The refresh token for your portal + * @param client_id: Unique ID for your app, generated when the app is registered + * + * @return: Body of request result + * + * @throws HubSpot_Exception + * */ + protected function refresh_access_token( $refresh_token, $client_id ) { + if ( $refresh_token and $client_id ) { + $url = 'https://api.hubapi.com/auth/v1/refresh'; + $body = 'refresh_token='.$refresh_token.'&client_id='.$client_id.'&grant_type=refresh_token'; + $ch = curl_init(); + curl_setopt( $ch, CURLOPT_POST, true ); + curl_setopt( $ch, CURLOPT_POSTFIELDS, $body ); + curl_setopt( $ch, CURLOPT_URL, $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_USERAGENT, $this->userAgent ); + curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/x-www-form-urlencoded' ) ); + $output = curl_exec( $ch ); + $apierr = curl_errno( $ch ); + $errmsg = curl_error( $ch ); + $response_code = curl_getinfo( $ch, CURLINFO_HTTP_CODE ); + curl_close( $ch ); + $output_array = json_decode( $output ); + if ( $response_code<400 ) { + return $output_array; + } else { + throw new HubSpot_Exception( "cURL error: " + $errmsg ); + + } + } + else { + throw new HubSpot_Exception( "Please provide a refresh_token and client_id" ); + } + + + } + } diff --git a/class.forms.php b/class.forms.php index cc21dea..5a175de 100644 --- a/class.forms.php +++ b/class.forms.php @@ -37,8 +37,18 @@ class HubSpot_Forms extends HubSpot_Baseclient{ **/ public function submit_form($portalId, $guid, $form_fields, $hs_context){ $url_base = 'https://forms.hubspot.com/uploads/form/v2/'.$portalId.'/'.$guid; - $form_fields['hs_context'] = json_encode($hs_context); - $param_string = '&'.http_build_query($form_fields,'','&'); + if(is_array($form_fields)){ + if(is_array($hs_context)){ + $form_fields['hs_context'] = json_encode($hs_context); + } + else{ + return "Please make sure you are passing hs_context as an array"; + } + } + else{ + return "Please make sure you are passing form_fields as an array"; + } + $param_string = '?'.http_build_query($form_fields,'','&'); try{ return json_decode($this->execute_post_request($this->get_forms_request_url($url_base,null),$param_string,TRUE)); } diff --git a/class.lists.php b/class.lists.php index 59cd7fa..6c33655 100644 --- a/class.lists.php +++ b/class.lists.php @@ -296,7 +296,7 @@ public function remove_contacts_from_list($vids,$id){ return $this->execute_JSON_post_request($this->get_request_url($endpoint,null),json_encode($request_body)); } catch(HubSpot_Exception $e){ - print_r("Unable to add contacts: ".$e); + print_r("Unable to remove contacts: ".$e); } } diff --git a/class.properties.php b/class.properties.php index bb9c7b9..070fe51 100644 --- a/class.properties.php +++ b/class.properties.php @@ -120,7 +120,7 @@ public function delete_property($name){ $endpoint = 'properties/'.$name; try{ - return $this->new_execute_delete_request($this->get_request_url($endpoint,null)); + return $this->execute_delete_request($this->get_request_url($endpoint,null)); } catch(HubSpot_Exception $e){ print_r('Unable to delete property: '.$e); diff --git a/class.socialmedia.php b/class.socialmedia.php index e07ddae..a91ac91 100644 --- a/class.socialmedia.php +++ b/class.socialmedia.php @@ -131,15 +131,15 @@ public function create_broadcast($broadcast){ /** - * Delete specific Broadcast Message + * Cancel specific Broadcast Message * *@param guid: Unique ID for the broadcast * - *@return returns response body for DELETE request + *@return returns response body for HTTP DELETE request * *@throws HubSpot_Exception **/ - public function delete_broadcast($guid){ + public function cancel_broadcast($guid){ $endpoint = 'broadcasts/'.$guid; try{ diff --git a/example.php b/example.php index 5fd6982..56359db 100644 --- a/example.php +++ b/example.php @@ -31,6 +31,7 @@ require_once 'class.socialmedia.php'; $HAPIKey = 'demo'; +$access_token = 'demooooo-oooo-oooo-oooo-oooooooooooo'; /* //Exercise Blog API $blogs = new HubSpot_Blog($HAPIKey); @@ -327,9 +328,9 @@ //Delete a Form $deleted_form = $forms->delete_form($new_form_guid); print_r($deleted_form); - +*/ //Exercise Lists API - $lists = new HubSpot_Lists($HAPIKey); + $lists = new HubSpot_Lists(array('access_token'=>$access_token)); //Create a contact List $list_array = array('name'=>'Tweeters','dynamic'=>false,'portalId'=>'62515','filters'=> @@ -337,7 +338,7 @@ $new_list = $lists->create_list($list_array); $list_id = $new_list->{'listId'}; print_r($new_list); - + //Update a contact List $updated_list_array = array('name'=>'Tweeters and Hubspotters','dynamic'=>false,'portalId'=>'62515','filters'=> array(array(array('operator'=>'IS_NOT_EMPTY','property'=>'twitterhandle','type'=>'string'), @@ -391,11 +392,11 @@ //Exercise Properties API - $properties = new HubSpot_Properties($HAPIKey); + $properties = new HubSpot_Properties(array('HAPIKey'=>$HAPIKey)); //Get all Properties $all_props = $properties->get_all_properties(); - print_r($all_props); + print_r($all_props); //Create new Property $new_prop_info = array('label'=>'Favorite Boston NBA Team','name'=>'favbostonnbateam','description'=>'Your favorite NBA team in the Boston Area', @@ -433,9 +434,10 @@ $deleted_group = $properties->delete_property_group('newpropgroup'); print_r($deleted_group); -*/ + + /* //Exercise Social Media API - $social = new HubSpot_SocialMedia($HAPIKey); + $social = new HubSpot_SocialMedia(array('access_token'=>'demooooo-oooo-oooo-oooo-oooooooooooo')); //Get Publishing Channels $channels = $social->get_publishing_channels(); @@ -462,5 +464,5 @@ $broadcast_guid = $new_broadcast->{'broadcastGuid'}; $deleted_broadcast = $social->cancel_broadcast($broadcast_guid); print_r($deleted_broadcast); - +*/ ?>