Permalink
Browse files

Merge pull request #1 from adrianmott/master

Changes from a 3rd party developer Jason Bramley.
Changes look good!
  • Loading branch information...
2 parents e8bb4c3 + 257d39b commit 5b10a18b9796d85714198310d505a92b9b45d89b @TheRealBenSmith TheRealBenSmith committed Mar 19, 2012
Showing with 14 additions and 4 deletions.
  1. +13 −3 class.baseclient.php
  2. +1 −1 class.leads.php
View
@@ -26,16 +26,18 @@ class BaseClient {
protected $isTest = false;
protected $PATH_DIV = '/';
protected $KEY_PARAM = '?hapikey=';
- protected $PROD_DOMAIN = 'https://hubapi.com';
+ protected $PROD_DOMAIN = 'https://api.hubapi.com';
protected $QA_DOMAIN = 'https://hubapiqa.com';
+ protected $userAgent; // new
/**
* Constructor.
*
* @param $HAPIKey: String value of HubSpot API Key for requests
**/
- function __construct($HAPIKey) {
+ function __construct($HAPIKey,$userAgent="haPiHP default UserAgent") { // new
$this->HAPIKey = $HAPIKey;
+ $this->userAgent = $userAgent; // new
}
/**
@@ -127,6 +129,7 @@ protected function execute_get_request($url) {
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);
@@ -148,14 +151,17 @@ protected function execute_get_request($url) {
*
* @throws exception
**/
- protected function execute_post_request($url, $body) {
+ protected function execute_post_request($url, $body, $formenc=FALSE) { //new
// 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) // new
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); // new
$output = curl_exec($ch);
$errno = curl_errno($ch);
$error = curl_error($ch);
@@ -185,6 +191,7 @@ protected function execute_xml_post_request($url, $body) {
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_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml'));
$output = curl_exec($ch);
@@ -211,6 +218,7 @@ protected function execute_xml_post_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); // new
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($body)));
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -241,6 +249,7 @@ protected function execute_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); // new
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml','Content-Length: ' . strlen($body)));
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
@@ -271,6 +280,7 @@ protected function execute_xml_put_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); // new
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($body)));
//curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
View
@@ -161,7 +161,7 @@ public function register_webhook($callbackURL) {
$params = array('url'=>$callbackURL);
$body = $this->array_to_params($params);
try {
- return $this->execute_post_request($this->get_request_url($endpoint,null), $body);
+ return $this->execute_post_request($this->get_request_url($endpoint,null), $body, true); // new
} catch (Exception $e) {
throw new Exception('Unable to register webhook: ' . $e);
}

0 comments on commit 5b10a18

Please sign in to comment.