Skip to content

Commit

Permalink
Added prospects api client and example code
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealBenSmith committed Nov 26, 2011
1 parent c3c2090 commit b09a212
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 0 deletions.
171 changes: 171 additions & 0 deletions class.prospects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php
/**
* Copyright 2011 HubSpot, Inc.
*
* Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the
* License.
*/
require_once('class.baseclient.php');

class Prospects extends BaseClient {
//Client for HubSpot Prospects API.

//Define required client variables
protected $API_PATH = 'prospects';
protected $API_VERSION = 'v1';

/**
* Get a listing of the prospects timeline
*
* @param params: Array of query parameters
* @returns Array of Prospects as stdObjects
*
* @throws exception
**/
public function get_timeline($params) {
$endpoint = 'timeline';
try {
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
} catch (Exception $e) {
throw new Exception('Unable to retrieve timeline: ' . $e);
}
}

/**
* Get details about a specific organization
*
* @param organization: Organization to retrieve
* @returns Array of Organization details as stdObjects
*
* @throws exception
**/
public function get_organization_details($organization) {
$endpoint = 'timeline/' . $organization;
try {
return json_decode($this->execute_get_request($this->get_request_url($endpoint,null)));
} catch (Exception $e) {
throw new Exception('Unable to retrieve organization details: ' . $e);
}
}

/**
* Get typeahead information
*
* @param query: Query string
* @returns Array of typeahead results
*
* @throws exception
**/
public function get_typeahead($query) {
$endpoint = 'typeahead';
$params = array('q'=>$query);
try {
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
} catch (Exception $e) {
throw new Exception('Unable to retrieve typeahead information: ' . $e);
}
}

/**
* Get search results
*
* @param type: Type of search: city, region, or country
* @param query: Query string
* @returns Array of search results
*
* @throws exception
**/
public function get_search_results($type, $query) {
if (($type != 'city')&&($type!='region')&&($type!='country')) {
throw new Exception('Invalid type: ' . $type . ' Type must be equal to city, region, or country');
}
$endpoint = 'search/' . $type;
$params = array('q'=>$query);
try {
return json_decode($this->execute_get_request($this->get_request_url($endpoint,$params)));
} catch (Exception $e) {
throw new Exception('Unable to retrieve search results: ' . $e);
}
}

/**
* Get a list of existing filters
*
* @returns Array of filters as stdObjects
*
* @throws exception
**/
public function get_filters() {
$endpoint = 'filters';
try {
return json_decode($this->execute_get_request($this->get_request_url($endpoint,null)));
} catch (Exception $e) {
throw new Exception('Unable to retrieve filters: ' . $e);
}
}

/**
* Add a filter
*
* @param organization: String value of the name of the organization to hide
*
* @returns Body of POST request
*
* @throws exception
**/
public function add_filter($organization) {
$endpoint = 'filters';

if ($this->isBlank($organization)) {
throw new Exception('Organization is required');
}

$params = array('organization'=>$organization);

$body = $this->array_to_params($params);
try {
return $this->execute_post_request($this->get_request_url($endpoint,null), $body);
} catch (Exception $e) {
throw new Exception('Unable to add filter: ' . $e);
}
}

/**
* Delete a filter
*
* @param organization: String value of the name of the organization to unhide
*
* @returns Body of POST request
*
* @throws exception
**/
public function delete_filter($organization) {
$endpoint = 'filters';

if ($this->isBlank($organization)) {
throw new Exception('Organization is required');
}

$params = array('organization'=>$organization);

$body = $this->array_to_params($params);
try {
return $this->execute_delete_request($this->get_request_url($endpoint,null), $body);
} catch (Exception $e) {
throw new Exception('Unable to delete filter: ' . $e);
}
}

}
?>
12 changes: 12 additions & 0 deletions example.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
require_once 'class.settings.php';
require_once 'class.events.php';
require_once 'class.leadnurturing.php';
require_once 'class.prospects.php';

$HAPIKey = 'demo';
/*
Expand Down Expand Up @@ -87,4 +89,14 @@

//Get campaign history for a lead
print_r($nurture->get_campaign_history('8a706adf33a131b40133a1323f46000d'));

//Exercise Prospects API
$prospects = new Prospects($HAPIKey);
print_r($prospects->get_timeline(null));
print_r($prospects->get_organization_details('MURPHX INNOVATIVE SOLUTIONS'));
print_r($prospects->get_typeahead('MURPH'));
print_r($prospects->get_search_results('country', 'UNITED KINGDOM'));
echo $prospects->add_filter('SOMEORG');
print_r($prospects->get_filters());
echo $prospects->delete_filter('SOMEORG');
?>

0 comments on commit b09a212

Please sign in to comment.