Skip to content

Commit

Permalink
Merge pull request #8 from ShootProof/contacts-support
Browse files Browse the repository at this point in the history
Adding support for Contacts API methods.
  • Loading branch information
bdeshong committed Mar 16, 2015
2 parents c2ba6da + 7c00225 commit c1c27f6
Show file tree
Hide file tree
Showing 5 changed files with 420 additions and 155 deletions.
72 changes: 36 additions & 36 deletions examples/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
// Configure your desired settings here
$shootproof_client_id = 'YOUR_CLIENT_ID_HERE';
$shootproof_api_scope = array(
'sp.studio.info',
'sp.event.get_list',
'sp.event.create',
'sp.event.photo_exists',
'sp.event.get_photos',
'sp.album.get_list',
'sp.album.create',
'sp.album.get_photos',
'sp.photo.upload',
'sp.photo.delete',
'sp.order.get_list',
'sp.order.get_details',
'sp.auth.deauthorize',
'sp.studio.info',
'sp.event.get_list',
'sp.event.create',
'sp.event.photo_exists',
'sp.event.get_photos',
'sp.album.get_list',
'sp.album.create',
'sp.album.get_photos',
'sp.photo.upload',
'sp.photo.delete',
'sp.order.get_list',
'sp.order.get_details',
'sp.auth.deauthorize',
);

// Include the ShootProof PHP SDK files
Expand All @@ -30,36 +30,36 @@

// Get the URL of the current page to redirect back to
if (empty($_SESSION['redirect_url'])) {
$_SESSION['redirect_url'] = sprintf(
'%s://%s%s',
isset($_SERVER['HTTPS']) ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
$_SESSION['redirect_url'] = sprintf(
'%s://%s%s',
isset($_SERVER['HTTPS']) ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
}

// Configure the ShootProof OAuth client
$auth = new Sp_Auth($shootproof_client_id, $_SESSION['redirect_url'], implode(' ', $shootproof_api_scope));

// Exchange the authorization code for an access token
if (empty($_SESSION['sp_tokens']) && ! empty($_GET['code'])) {
try {
$_SESSION['sp_tokens'] = $auth->requestAccessToken($_GET['code']);
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
try {
$_SESSION['sp_tokens'] = $auth->requestAccessToken($_GET['code']);
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
}

// Test the API by calling the sp.event.get_list ShootProof API method
if ( ! empty($_SESSION['sp_tokens']['access_token'])) {
try {
$client = new Sp_Api($_SESSION['sp_tokens']['access_token']);
$events = $client->getEvents();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
try {
$client = new Sp_Api($_SESSION['sp_tokens']['access_token']);
$events = $client->getEvents();
} catch (Exception $e) {
echo $e->getMessage();
exit;
}
}

?>
Expand All @@ -68,10 +68,10 @@

<?php if ( ! empty($_SESSION['sp_tokens'])): ?>

<h1>Access Tokens</h1>
<pre><?php print_r($_SESSION['sp_tokens']) ?></pre>
<h1>Access Tokens</h1>
<pre><?php print_r($_SESSION['sp_tokens']) ?></pre>

<h1>Event Listing</h1>
<pre><?php print_r($events) ?></pre>
<h1>Event Listing</h1>
<pre><?php print_r($events) ?></pre>

<?php endif; ?>
152 changes: 150 additions & 2 deletions lib/Sp_Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public function getMobileAppPhotos($mobileAppId)

/**
* Method to return all active brands for a studio.
*
*
* @return array
*/
public function getBrands()
Expand All @@ -536,7 +536,7 @@ public function getBrands()

/**
* Method to return data on a single brand.
*
*
* @param integer $brandId Brand ID to retrieve for.
* @return array
*/
Expand All @@ -550,6 +550,154 @@ public function getBrandInfo($brandId)
return $this->_makeApiRequest($params);
}

/**
* Method to return data on a single contact.
*
* @param integer $contactId Contact ID to retrieve for.
* @return array
*/
public function getContactInfo($contactId)
{
$params = array(
'method' => 'sp.contact.info',
'contact_id' => $contactId
);

return $this->_makeApiRequest($params);
}

/**
* Method to create a new contact.
*
* Supported key-value pairs:
*
* brand_id
* first_name (required)
* last_name
* email (required)
* phone
* business_name
* notes
* tags (string of tags, separated by commas)
* address (associative array)
* address_1
* address_2
* city
* state
* state_other
* country (required if address is provided)
* zip_postal
*
* @param array $contactData Associative array of contact data.
* @return array
*/
public function createContact(array $contactData)
{
$params = array_merge(
array(
'method' => 'sp.contact.create'
),
$contactData
);

return $this->_makeApiRequest($params);
}

/**
* Method to update a new contact.
*
* Supported key-value pairs:
*
* brand_id
* first_name (required)
* last_name
* email (required)
* phone
* business_name
* notes
* tags (string of tags, separated by commas)
* address (associative array, or null to remove)
* address_1
* address_2
* city
* state
* state_other
* country (required if address is provided)
* zip_postal
*
* @param array $contactData Associative array of contact data.
* @return array
*/
public function updateContact($contactId, array $contactData)
{
$params = array_merge(
array(
'method' => 'sp.contact.create',
'contact_id' => $contactId
),
$contactData
);

return $this->_makeApiRequest($params);
}

/**
* Method to create a multiple contacts in bulk.
*
* Must be an array of associative arrays. The same key-value pauirs
* in Sp_Api::createContact() are supported in the inner associative arrays.
* Supported key-value pairs:
*
* brand_id
* first_name (required)
* last_name
* email (required)
* phone
* business_name
* notes
* tags (string of tags, separated by commas)
* address (associative array)
* address_1
* address_2
* city
* state
* state_other
* country (required if address is provided)
* zip_postal
*
* @param array $contactData Array of associative arrays of contact data.
* @return array
*/
public function bulkCreateContacts(array $contacts)
{
$params = array(
'method' => 'sp.contact.bulk_create',
'contacts' => $contacts
);

return $this->_makeApiRequest($params);
}

/**
* Method to delete a contact.
*
* @param integer $contactId
* @return array
*/
public function deleteContact($contactId)
{
if (is_null($contactId) || $contactId == '') {
throw new Exception('The contactId is required to delete a contact.');
}

$params = array(
'method' => 'sp.contact.delete',
'contact_id' => $contactId
);

return $this->_makeApiRequest($params);
}

/**
* Method to get the accessToken
*
Expand Down
52 changes: 26 additions & 26 deletions lib/Sp_Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,34 +83,34 @@ public function setRedirectUri($uri)
return $this;
}

/**
* Method to get the appId
*
* @return string
*/
protected function _getClientId()
{
return $this->_clientId;
}

/**
* Method to return the redirect uri
*
* @return string
*/
protected function _getRedirectUri()
{
return $this->_redirectUri;
/**
* Method to get the appId
*
* @return string
*/
protected function _getClientId()
{
return $this->_clientId;
}

/**
* Method to return the scope
*
* @return string
*/
protected function _getScope()
{
return $this->_scope;
/**
* Method to return the redirect uri
*
* @return string
*/
protected function _getRedirectUri()
{
return $this->_redirectUri;
}

/**
* Method to return the scope
*
* @return string
*/
protected function _getScope()
{
return $this->_scope;
}

/**
Expand Down
Loading

0 comments on commit c1c27f6

Please sign in to comment.