Skip to content

Commit

Permalink
Merge pull request #12 from dnadesign/feature/get-contact-improvements
Browse files Browse the repository at this point in the history
Improving documentation and validation of getContact function.
  • Loading branch information
Leapfrognz authored Jul 26, 2021
2 parents 29f05b7 + ced565d commit 1a32369
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Services/UbiquityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,31 @@ public function call($method = null, string $uri = null, $query = null, $data =
}

/**
* Retrieves the ID of an existing entry if it exists
* Retrieves an array of subscriber data for an existing contact if it exists
*
* @param Array $emailField the field containing the email address to check
* @return Int (ID) or false if it doesn't exist
* @param array The $params array should contain the fieldID of the email field (in the Ubiquity Database) and the value (an email address) of a subscriber
* @return array|false array of user data or false if it doesn't exist
*/
public function getContact($emailData)
public function getContact($params)
{
// check the function has been passed a fieldID
$fieldID = (isset($params['fieldID'])) ? $params['fieldID'] : null;
if (!$fieldID) {
throw new Exception('The fieldID of the email field is required.');
}

// get the email address submitted
$email = (isset($emailData['value'])) ? $emailData['value'] : null;
$email = (isset($params['value'])) ? $params['value'] : null;

// check the email address is valid
if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
throw new Exception('Email field value is not a valid email address');
}

$query = [
'filter' => $this->buildFilterQueryString(array($emailData))
'filter' => $this->buildFilterQueryString(array($params))
];

//self::get()?
$response = $this->call(self::METHOD_GET, 'database/contacts', $query);

if ($response->getStatusCode() !== 200) {
Expand Down

0 comments on commit 1a32369

Please sign in to comment.