Skip to content

Commit c1c27f6

Browse files
committed
Merge pull request #8 from ShootProof/contacts-support
Adding support for Contacts API methods.
2 parents c2ba6da + 7c00225 commit c1c27f6

File tree

5 files changed

+420
-155
lines changed

5 files changed

+420
-155
lines changed

examples/index.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
// Configure your desired settings here
44
$shootproof_client_id = 'YOUR_CLIENT_ID_HERE';
55
$shootproof_api_scope = array(
6-
'sp.studio.info',
7-
'sp.event.get_list',
8-
'sp.event.create',
9-
'sp.event.photo_exists',
10-
'sp.event.get_photos',
11-
'sp.album.get_list',
12-
'sp.album.create',
13-
'sp.album.get_photos',
14-
'sp.photo.upload',
15-
'sp.photo.delete',
16-
'sp.order.get_list',
17-
'sp.order.get_details',
18-
'sp.auth.deauthorize',
6+
'sp.studio.info',
7+
'sp.event.get_list',
8+
'sp.event.create',
9+
'sp.event.photo_exists',
10+
'sp.event.get_photos',
11+
'sp.album.get_list',
12+
'sp.album.create',
13+
'sp.album.get_photos',
14+
'sp.photo.upload',
15+
'sp.photo.delete',
16+
'sp.order.get_list',
17+
'sp.order.get_details',
18+
'sp.auth.deauthorize',
1919
);
2020

2121
// Include the ShootProof PHP SDK files
@@ -30,36 +30,36 @@
3030

3131
// Get the URL of the current page to redirect back to
3232
if (empty($_SESSION['redirect_url'])) {
33-
$_SESSION['redirect_url'] = sprintf(
34-
'%s://%s%s',
35-
isset($_SERVER['HTTPS']) ? 'https' : 'http',
36-
$_SERVER['HTTP_HOST'],
37-
$_SERVER['REQUEST_URI']
38-
);
33+
$_SESSION['redirect_url'] = sprintf(
34+
'%s://%s%s',
35+
isset($_SERVER['HTTPS']) ? 'https' : 'http',
36+
$_SERVER['HTTP_HOST'],
37+
$_SERVER['REQUEST_URI']
38+
);
3939
}
4040

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

4444
// Exchange the authorization code for an access token
4545
if (empty($_SESSION['sp_tokens']) && ! empty($_GET['code'])) {
46-
try {
47-
$_SESSION['sp_tokens'] = $auth->requestAccessToken($_GET['code']);
48-
} catch (Exception $e) {
49-
echo $e->getMessage();
50-
exit;
51-
}
46+
try {
47+
$_SESSION['sp_tokens'] = $auth->requestAccessToken($_GET['code']);
48+
} catch (Exception $e) {
49+
echo $e->getMessage();
50+
exit;
51+
}
5252
}
5353

5454
// Test the API by calling the sp.event.get_list ShootProof API method
5555
if ( ! empty($_SESSION['sp_tokens']['access_token'])) {
56-
try {
57-
$client = new Sp_Api($_SESSION['sp_tokens']['access_token']);
58-
$events = $client->getEvents();
59-
} catch (Exception $e) {
60-
echo $e->getMessage();
61-
exit;
62-
}
56+
try {
57+
$client = new Sp_Api($_SESSION['sp_tokens']['access_token']);
58+
$events = $client->getEvents();
59+
} catch (Exception $e) {
60+
echo $e->getMessage();
61+
exit;
62+
}
6363
}
6464

6565
?>
@@ -68,10 +68,10 @@
6868

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

71-
<h1>Access Tokens</h1>
72-
<pre><?php print_r($_SESSION['sp_tokens']) ?></pre>
71+
<h1>Access Tokens</h1>
72+
<pre><?php print_r($_SESSION['sp_tokens']) ?></pre>
7373

74-
<h1>Event Listing</h1>
75-
<pre><?php print_r($events) ?></pre>
74+
<h1>Event Listing</h1>
75+
<pre><?php print_r($events) ?></pre>
7676

7777
<?php endif; ?>

lib/Sp_Api.php

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ public function getMobileAppPhotos($mobileAppId)
522522

523523
/**
524524
* Method to return all active brands for a studio.
525-
*
525+
*
526526
* @return array
527527
*/
528528
public function getBrands()
@@ -536,7 +536,7 @@ public function getBrands()
536536

537537
/**
538538
* Method to return data on a single brand.
539-
*
539+
*
540540
* @param integer $brandId Brand ID to retrieve for.
541541
* @return array
542542
*/
@@ -550,6 +550,154 @@ public function getBrandInfo($brandId)
550550
return $this->_makeApiRequest($params);
551551
}
552552

553+
/**
554+
* Method to return data on a single contact.
555+
*
556+
* @param integer $contactId Contact ID to retrieve for.
557+
* @return array
558+
*/
559+
public function getContactInfo($contactId)
560+
{
561+
$params = array(
562+
'method' => 'sp.contact.info',
563+
'contact_id' => $contactId
564+
);
565+
566+
return $this->_makeApiRequest($params);
567+
}
568+
569+
/**
570+
* Method to create a new contact.
571+
*
572+
* Supported key-value pairs:
573+
*
574+
* brand_id
575+
* first_name (required)
576+
* last_name
577+
* email (required)
578+
* phone
579+
* business_name
580+
* notes
581+
* tags (string of tags, separated by commas)
582+
* address (associative array)
583+
* address_1
584+
* address_2
585+
* city
586+
* state
587+
* state_other
588+
* country (required if address is provided)
589+
* zip_postal
590+
*
591+
* @param array $contactData Associative array of contact data.
592+
* @return array
593+
*/
594+
public function createContact(array $contactData)
595+
{
596+
$params = array_merge(
597+
array(
598+
'method' => 'sp.contact.create'
599+
),
600+
$contactData
601+
);
602+
603+
return $this->_makeApiRequest($params);
604+
}
605+
606+
/**
607+
* Method to update a new contact.
608+
*
609+
* Supported key-value pairs:
610+
*
611+
* brand_id
612+
* first_name (required)
613+
* last_name
614+
* email (required)
615+
* phone
616+
* business_name
617+
* notes
618+
* tags (string of tags, separated by commas)
619+
* address (associative array, or null to remove)
620+
* address_1
621+
* address_2
622+
* city
623+
* state
624+
* state_other
625+
* country (required if address is provided)
626+
* zip_postal
627+
*
628+
* @param array $contactData Associative array of contact data.
629+
* @return array
630+
*/
631+
public function updateContact($contactId, array $contactData)
632+
{
633+
$params = array_merge(
634+
array(
635+
'method' => 'sp.contact.create',
636+
'contact_id' => $contactId
637+
),
638+
$contactData
639+
);
640+
641+
return $this->_makeApiRequest($params);
642+
}
643+
644+
/**
645+
* Method to create a multiple contacts in bulk.
646+
*
647+
* Must be an array of associative arrays. The same key-value pauirs
648+
* in Sp_Api::createContact() are supported in the inner associative arrays.
649+
* Supported key-value pairs:
650+
*
651+
* brand_id
652+
* first_name (required)
653+
* last_name
654+
* email (required)
655+
* phone
656+
* business_name
657+
* notes
658+
* tags (string of tags, separated by commas)
659+
* address (associative array)
660+
* address_1
661+
* address_2
662+
* city
663+
* state
664+
* state_other
665+
* country (required if address is provided)
666+
* zip_postal
667+
*
668+
* @param array $contactData Array of associative arrays of contact data.
669+
* @return array
670+
*/
671+
public function bulkCreateContacts(array $contacts)
672+
{
673+
$params = array(
674+
'method' => 'sp.contact.bulk_create',
675+
'contacts' => $contacts
676+
);
677+
678+
return $this->_makeApiRequest($params);
679+
}
680+
681+
/**
682+
* Method to delete a contact.
683+
*
684+
* @param integer $contactId
685+
* @return array
686+
*/
687+
public function deleteContact($contactId)
688+
{
689+
if (is_null($contactId) || $contactId == '') {
690+
throw new Exception('The contactId is required to delete a contact.');
691+
}
692+
693+
$params = array(
694+
'method' => 'sp.contact.delete',
695+
'contact_id' => $contactId
696+
);
697+
698+
return $this->_makeApiRequest($params);
699+
}
700+
553701
/**
554702
* Method to get the accessToken
555703
*

lib/Sp_Auth.php

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -83,34 +83,34 @@ public function setRedirectUri($uri)
8383
return $this;
8484
}
8585

86-
/**
87-
* Method to get the appId
88-
*
89-
* @return string
90-
*/
91-
protected function _getClientId()
92-
{
93-
return $this->_clientId;
94-
}
95-
96-
/**
97-
* Method to return the redirect uri
98-
*
99-
* @return string
100-
*/
101-
protected function _getRedirectUri()
102-
{
103-
return $this->_redirectUri;
86+
/**
87+
* Method to get the appId
88+
*
89+
* @return string
90+
*/
91+
protected function _getClientId()
92+
{
93+
return $this->_clientId;
10494
}
10595

106-
/**
107-
* Method to return the scope
108-
*
109-
* @return string
110-
*/
111-
protected function _getScope()
112-
{
113-
return $this->_scope;
96+
/**
97+
* Method to return the redirect uri
98+
*
99+
* @return string
100+
*/
101+
protected function _getRedirectUri()
102+
{
103+
return $this->_redirectUri;
104+
}
105+
106+
/**
107+
* Method to return the scope
108+
*
109+
* @return string
110+
*/
111+
protected function _getScope()
112+
{
113+
return $this->_scope;
114114
}
115115

116116
/**

0 commit comments

Comments
 (0)