summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Core/Communicator.php7
-rw-r--r--src/Core/OwnableInterface.php12
-rw-r--r--src/Recipient/Membership.php2
-rw-r--r--src/Recipient/ProcessedContact.php43
-rw-r--r--src/Recipient/ProcessedGroup.php33
-rw-r--r--src/Recipient/ProcessedMembership.php20
-rw-r--r--src/Recipient/RecipientFactory.php3
7 files changed, 96 insertions, 24 deletions
diff --git a/src/Core/Communicator.php b/src/Core/Communicator.php
index 915ba39..81b0331 100644
--- a/src/Core/Communicator.php
+++ b/src/Core/Communicator.php
@@ -16,6 +16,7 @@ use IP1\RESTClient\Recipient\ProcessedBlacklistEntry;
use IP1\RESTClient\Core\ProcessedComponentInterface;
use IP1\RESTClient\Core\UpdatableComponentInterface;
use IP1\RESTClient\Core\ProcessableComponentInterface;
+use \Httpful\Response;
/**
* Handles request to the API and converts the responses into the data classes.
@@ -212,7 +213,7 @@ class Communicator
* @param boolean $https Whether the the API call should use HTTPS or not(HTTP).
* @return string The response from the API.
*/
- private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = false): string
+ private function sendRequest(string $endPoint, string $method, string $content = "", bool $https = false): Response
{
$url = ($https ? "https://" : "http://") . self::DOMAIN . "/" .$endPoint;
$request = \Httpful\Request::init($method, 'application/json');
@@ -226,8 +227,8 @@ class Communicator
$response = $request->send();
if ($response->hasErrors()) {
- $this->$errorResponses[] = $response;
+ $this->errorResponses[] = $response;
}
- return $response->__toString();
+ return $response;
}
}
diff --git a/src/Core/OwnableInterface.php b/src/Core/OwnableInterface.php
new file mode 100644
index 0000000..c54281b
--- /dev/null
+++ b/src/Core/OwnableInterface.php
@@ -0,0 +1,12 @@
+<?php
+namespace IP1\RESTClient\Core;
+
+interface OwnableInterface
+{
+
+ /**
+ * Returns ID of account owning the implemented object.
+ * @return ID of account owning the implemented object.
+ */
+ public function getOwnerID(): string;
+}
diff --git a/src/Recipient/Membership.php b/src/Recipient/Membership.php
index 4bd3be8..82647dd 100644
--- a/src/Recipient/Membership.php
+++ b/src/Recipient/Membership.php
@@ -64,7 +64,7 @@ class Membership implements ProcessableComponentInterface
{
$returnArray = [
'Group' => $this->groupID,
- 'Contact' => $this->ContactID,
+ 'Contact' => $this->contactID,
];
return $returnArray;
}
diff --git a/src/Recipient/ProcessedContact.php b/src/Recipient/ProcessedContact.php
index 87a637f..1565a50 100644
--- a/src/Recipient/ProcessedContact.php
+++ b/src/Recipient/ProcessedContact.php
@@ -17,11 +17,15 @@ use IP1\RESTClient\Recipient\RecipientFactory;
use IP1\RESTClient\Recipient\MembershipRelationInterface;
use IP1\RESTClient\Core\Communicator;
use IP1\RESTClient\Core\ClassValidationArray;
+use IP1\RESTClient\Core\OwnableInterface;
/**
* A Contact that has been added to the API. Has all the options that a normal Contact has.
*/
-class ProcessedContact extends Contact implements UpdatableComponentInterface, MembershipRelationInterface
+class ProcessedContact extends Contact implements
+ UpdatableComponentInterface,
+ MembershipRelationInterface,
+ OwnableInterface
{
/**
* The ID of the Contact given by the API.
@@ -38,6 +42,12 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
* @var \DateTime $updated
*/
private $updated;
+
+ /**
+ * The Account ID of the Contact's owner.
+ * @var string $ownerID
+ */
+ private $ownerID;
/**
* An array of Memberships that the Group has.
*
@@ -73,6 +83,7 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
* @param string $firstName The first name of the contact in question.
* @param string $phoneNumber Contact phone number: with country code and without spaces and dashes.
* @param integer $contactID Contact ID.
+ * @param string $ownerID ID of account owning the Contact.
* @param ?string $lastName Contact last name.
* @param ?string $title The contacts title.
* @param ?string $organization Contact company or other organization.
@@ -85,6 +96,7 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
string $firstName,
string $phoneNumber,
int $contactID,
+ string $ownerID,
?string $lastName,
?string $title,
?string $organization,
@@ -94,6 +106,7 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
?\DateTime $updated = null
) {
parent::__construct($firstName, $phoneNumber, $lastName, $title, $organization, $email, $notes);
+ $this->ownerID = $ownerID;
$this->contactID = $contactID;
$this->created = $created ?? null;
$this->updated = $updated ?? null;
@@ -112,7 +125,7 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
if ($communicator !== null) {
$membershipJSON = $communicator->get("api/contacts/".$this->contactID."/memberships");
$membershipStd = json_decode($membershipJSON);
- $memberships = [];
+ $memberships = new ClassValidationArray();
foreach ($membershipStd as $value) {
$memberships[] = RecipientFactory::createProcessedMembershipFromStdClass($value);
}
@@ -213,6 +226,13 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
return $this->contactID;
}
/**
+ * @return string OwnerID
+ */
+ public function getOwnerID(): string
+ {
+ return $this->ownerID;
+ }
+ /**
* Serializes the object to a value that can be serialized natively by json_encode().
* @return array Associative.
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
@@ -220,17 +240,14 @@ class ProcessedContact extends Contact implements UpdatableComponentInterface, M
public function jsonSerialize(): array
{
$contactArray = parent::jsonSerialize();
- $returnArray = array_merge(
- ['ID' => $this->contactID],
- $contactArray,
- [
- 'Modified' => isset($this->created) ? $this->updated->format("Y-m-d\TH:i:s.").
- substr($this->updated->format('u'), 0, 3) : null,
- 'Created' => isset($this->created) ? $this->created->format("Y-m-d\TH:i:s.").
- substr($this->updated->format('u'), 0, 3) : null,
- ]
- );
- return array_filter($returnArray);
+ $contactArray['ID'] = $this->contactID;
+ $contactArray['OwnerID'] = $this->ownerID;
+ $contactArray['Modified'] = isset($this->created) ? $this->updated->format("Y-m-d\TH:i:s.").
+ substr($this->updated->format('u'), 0, 3) : null;
+ $contactArray['Created'] = isset($this->created) ? $this->created->format("Y-m-d\TH:i:s.").
+ substr($this->updated->format('u'), 0, 3) : null;
+
+ return array_filter($contactArray);
}
/**
* Takes the given argument and replaces strings such as {id} to an actual value.
diff --git a/src/Recipient/ProcessedGroup.php b/src/Recipient/ProcessedGroup.php
index 48e8605..87a14d2 100644
--- a/src/Recipient/ProcessedGroup.php
+++ b/src/Recipient/ProcessedGroup.php
@@ -15,11 +15,12 @@ use IP1\RESTClient\Core\Communicator;
use IP1\RESTClient\Core\UpdatableComponentInterface;
use IP1\RESTClient\Core\ClassValidationArray;
use IP1\RESTClient\Recipient\ProcessedMembership;
+use IP1\RESTClient\Core\OwnableInterface;
/**
*
*/
-class ProcessedGroup extends Group implements UpdatableComponentInterface, MembershipRelationInterface
+class ProcessedGroup extends Group implements UpdatableComponentInterface, MembershipRelationInterface, OwnableInterface
{
/**
* The ID of the Group given by the API.
@@ -37,6 +38,11 @@ class ProcessedGroup extends Group implements UpdatableComponentInterface, Membe
*/
private $updated;
/**
+ * ID of account owning the Group
+ * @var string $ownerID
+ */
+ private $ownerID;
+ /**
* An array of memberships that the Group has.
*
* It is empty by default but is filled when the function getMemberships() is called if a Communicator is given
@@ -66,30 +72,47 @@ class ProcessedGroup extends Group implements UpdatableComponentInterface, Membe
protected $contactsFetched = false;
const IS_READ_ONLY = false;
/**
- * ProcessedGroup Contstructor
+ * ProcessedGroup Contstructor.
* @param string $name Name of the Group.
* @param string $color A hexadecimal color.
* @param integer $groupID An ID generated by the API.
+ * @param string $ownerID ID of account owning the Group.
* @param \DateTime $created When the Group was initially created.
* @param \DateTime $updated When the Group was last updated.
*/
- public function __construct(string $name, string $color, int $groupID, \DateTime $created, \DateTime $updated)
- {
+ public function __construct(
+ string $name,
+ string $color,
+ int $groupID,
+ string $ownerID,
+ \DateTime $created,
+ \DateTime $updated
+ ) {
+
parent::__construct($name, $color);
$this->groupID = $groupID;
+ $this->ownerID = $ownerID;
$this->created = $created;
$this->updated = $updated;
$this->memberships = new ClassValidationArray();
$this->contacts = new ClassValidationArray();
}
/**
- * @return integer Group ID
+ * @return integer Group ID.
*/
public function getID(): int
{
return $this->groupID;
}
/**
+ * Returns ID of account owning the Group.
+ * @return string
+ */
+ public function getOwnerID(): string
+ {
+ return $this->ownerID;
+ }
+ /**
* Returns whether the object is read only or not.
* @return boolean Whether the object is read only or not.
*/
diff --git a/src/Recipient/ProcessedMembership.php b/src/Recipient/ProcessedMembership.php
index 28160d6..590ef0f 100644
--- a/src/Recipient/ProcessedMembership.php
+++ b/src/Recipient/ProcessedMembership.php
@@ -12,12 +12,13 @@
namespace IP1\RESTClient\Recipient;
use IP1\RESTClient\Core\ProcessedComponentInterface;
+use IP1\RESTClient\Core\OwnableInterface;
/**
* ProcessedMembership class.
* Is the relation between contacts and groups.
*/
-class ProcessedMembership extends Membership implements ProcessedComponentInterface
+class ProcessedMembership extends Membership implements ProcessedComponentInterface, OwnableInterface
{
/**
@@ -31,16 +32,23 @@ class ProcessedMembership extends Membership implements ProcessedComponentInterf
*/
private $created;
/**
+ * ID of account owning the membership
+ * @var string $ownerID
+ */
+ private $ownerID;
+ /**
* ProcessedMembership Constructor
* @param integer $groupID The ID of the group.
* @param integer $contactID The ID of the contact.
* @param integer $membershipID The ID of the membership.
+ * @param string $ownerID ID of account owning the membership.
* @param \DateTime $created When the Membership was created.
*/
- public function __construct(int $groupID, int $contactID, int $membershipID, \DateTime $created)
+ public function __construct(int $groupID, int $contactID, int $membershipID, string $ownerID, \DateTime $created)
{
parent::__construct($groupID, $contactID);
$this->membershipID = $membershipID;
+ $this->ownerID = $ownerID;
$this->created = $created;
}
@@ -53,6 +61,14 @@ class ProcessedMembership extends Membership implements ProcessedComponentInterf
return $this->membershipID;
}
/**
+ * Returns ID of account owning the Membership
+ * @return string ID of account owning the Membership
+ */
+ public function getOwnerID(): string
+ {
+ return $this->ownerID;
+ }
+ /**
* @param \DateTimeZone $timezone The timezone that the user wants to get the DateTime in. Default is UTC.
* @return \DateTime|null When the Component was added.
*/
diff --git a/src/Recipient/RecipientFactory.php b/src/Recipient/RecipientFactory.php
index 05de224..0003b44 100644
--- a/src/Recipient/RecipientFactory.php
+++ b/src/Recipient/RecipientFactory.php
@@ -125,6 +125,7 @@ class RecipientFactory
$stdContact->FirstName,
$stdContact->Phone,
$stdContact->ID,
+ $stdContact->OwnerID,
$stdContact->LastName ?? null,
$stdContact->Title ?? null,
$stdContact->Organization ?? null,
@@ -155,6 +156,7 @@ class RecipientFactory
$stdGroup->Name,
$stdGroup->Color,
$stdGroup->ID,
+ $stdGroup->OwnerID,
new \DateTime($stdGroup->Created),
new \DateTime($stdGroup->Modified)
);
@@ -189,6 +191,7 @@ class RecipientFactory
$stdMembership->Group,
$stdMembership->Contact,
$stdMembership->ID,
+ $stdMembership->OwnerID,
new \DateTime($stdMembership->Created)
);
}