Skip to content

Commit

Permalink
Add support for consent retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Nov 27, 2024
1 parent b5281e4 commit b8ad092
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,25 @@ public function getQueryCriteria($parameters = array()) {
)));
}

/**
/**
* Get information about whether consent has been given to use a mobile phone for SMS.
*
* @param array $parameters
* - database_id (int)
* - data (array) e.g [['Email', a@example.com']['Email', b@example.com']]
*
* @return ConsentInformationRequest
*/
public function consentInformationRequest($parameters = [])
{
return $this->createRequest('ConsentInformationRequest', array_merge($parameters, array(
'credentials' => $this->getCredentials(),
'client' => $this->getClient(),
'is_use_rest' => TRUE,
)));
}

/**
* Initialize a request object
*
* This function is usually used to initialise objects of type
Expand Down
112 changes: 112 additions & 0 deletions src/Requests/ConsentInformationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Omnimail\Silverpop\Requests;

use Omnimail\Silverpop\Responses\GroupMembersResponse;
use Omnimail\Silverpop\Responses\Consent;

/**
* https://api-campaign-us-2.goacoustic.com/restdoc/#!/databases/consent_get_get_10
*/
class ConsentInformationRequest extends SilverpopBaseRequest
{

/**
* Silverpop database ID.
*
* @var int
*/
protected $database_id;

protected string $channel = 'SMS';

protected string $shortCode;

/**
* Qualifier, aka text to join.
*
* This is the SMS number that a person would send text to to consent.
*
* @var string
*
*/
protected $qualifier;

/**
* Destination - this is generally the phone number with country code but no leading zeros.
* @var int
*/
protected $destination;

private int $phone;

/**
* @return int
*/
public function getDatabaseId() {
return $this->database_id;
}

/**
* @param int $database_id
*/
public function setDatabaseId($database_id) {
$this->database_id = $database_id;
}

/**
* @return array
*/
public function getPhone() {
return $this->phone;
}

/**
* @param int $phone
*/
public function setPhone(int $phone) {
$this->phone = $phone;
}

/**
* Get Response
*
* @return GroupMembersResponse
*/
public function getResponse() {
$result = $this->requestData();
$response = new Consent($result['data']);
return $response;
}

/**
* Request data from the provider.
*/
protected function requestData() {
return $this->silverPop->restGet(
$this->getDatabaseId(),
'databases',
['consent', $this->channel . '-' . $this->getShortCode(), $this->getPhone()]);
}

/**
* Get defaults for the api.
*
* @return array
*/
public function getDefaultParameters(): array {
return [
'endpoint' => 'https://api-campaign-us-4.goacoustic.com',
];
}

public function getShortCode(): string {
return $this->shortCode;
}

public function setShortCode(string $shortCode): self {
$this->shortCode = $shortCode;
return $this;
}

}
52 changes: 52 additions & 0 deletions src/Responses/Consent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: emcnaughton
* Date: 5/4/17
* Time: 7:34 AM
*/

namespace Omnimail\Silverpop\Responses;

use SilverpopConnector\SilverpopConnector;
use SilverpopConnector\SilverpopConnectorException;
use Omnimail\Exception\InvalidRequestException;

class Consent {

/**
* @var array
*/
protected $data = [];

/**
* @return int|null
*/
public function getStatus(): string {
return $this->data['status'];
}

/**
* @return array
*/
public function getTimestamp(): int {
return strtotime($this->data['consentDate']);
}

/**
* @return string
*/
public function getSource(): ?string {
return $this->data['consentSource'];
}

/**
* @var SilverpopConnector
*/
protected $silverPop;

public function __construct($data) {
$this->data = $data;
}

}

0 comments on commit b8ad092

Please sign in to comment.