From 1df0ae68bfb64429f6e14f17878e3d4524c89302 Mon Sep 17 00:00:00 2001 From: Ignacio Colautti Date: Mon, 31 Aug 2020 11:14:52 -0700 Subject: [PATCH 1/5] Email validation replaced --- composer.json | 1 + src/Model/Email.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ba49ae7..e66d9fd 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "php": "^7.1", "ext-json": "*", "doctrine/inflector": "^1.3", + "egulias/email-validator": "^2.1", "fig/http-message-util": "^1.1", "php-http/client-common": "^1.5|^2.0", "php-http/client-implementation": "^1.0", diff --git a/src/Model/Email.php b/src/Model/Email.php index d5cc113..2fa8ca5 100644 --- a/src/Model/Email.php +++ b/src/Model/Email.php @@ -13,6 +13,8 @@ namespace LooplineSystems\CloseIoApiWrapper\Model; +use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Validation\RFCValidation; use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException; use LooplineSystems\CloseIoApiWrapper\Library\JsonSerializableHelperTrait; use LooplineSystems\CloseIoApiWrapper\Library\ObjectHydrateHelperTrait; @@ -36,6 +38,16 @@ class Email implements \JsonSerializable */ private $type; + /** + * @var object + */ + private $validator; + + /** + * @var object + */ + private $validation; + /** * @param array $data * @@ -46,6 +58,9 @@ public function __construct(array $data = null) if ($data) { $this->hydrate($data); } + + $this->validator = new EmailValidator(); + $this->validation = new RFCValidation(); } /** @@ -65,7 +80,7 @@ public function getEmail() */ public function setEmail($email) { - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + if (!$this->validator($email, $this->validation)) { throw new InvalidParamException('Invalid email format: "' . $email . '"'); } else { $this->email = $email; From 889925eb54278065b972e29963da1bdfd772e515 Mon Sep 17 00:00:00 2001 From: Ignacio Colautti Date: Mon, 31 Aug 2020 11:56:46 -0700 Subject: [PATCH 2/5] Email validator fixed --- src/Model/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Email.php b/src/Model/Email.php index 2fa8ca5..2a3eb72 100644 --- a/src/Model/Email.php +++ b/src/Model/Email.php @@ -80,7 +80,7 @@ public function getEmail() */ public function setEmail($email) { - if (!$this->validator($email, $this->validation)) { + if (!$this->validator->isValid($email, $this->validation)) { throw new InvalidParamException('Invalid email format: "' . $email . '"'); } else { $this->email = $email; From 0af226048bd04f9b533c055dc262ec3dec2c6c97 Mon Sep 17 00:00:00 2001 From: Ignacio Colautti Date: Mon, 31 Aug 2020 12:09:47 -0700 Subject: [PATCH 3/5] Final bug fix :P --- src/Model/Email.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Model/Email.php b/src/Model/Email.php index 2a3eb72..cc80247 100644 --- a/src/Model/Email.php +++ b/src/Model/Email.php @@ -58,9 +58,6 @@ public function __construct(array $data = null) if ($data) { $this->hydrate($data); } - - $this->validator = new EmailValidator(); - $this->validation = new RFCValidation(); } /** @@ -80,7 +77,7 @@ public function getEmail() */ public function setEmail($email) { - if (!$this->validator->isValid($email, $this->validation)) { + if (!$this->_getValidator()->isValid($email, $this->_getValidation())) { throw new InvalidParamException('Invalid email format: "' . $email . '"'); } else { $this->email = $email; @@ -108,4 +105,21 @@ public function setType($type) return $this; } + + private function _getValidator() + { + if (is_null($this->validator)) + $this->validator = new EmailValidator(); + + return $this->validator; + } + + private function _getValidation() + { + if (is_null($this->validation)) + $this->validation = new RFCValidation(); + + return $this->validation; + } } + From e7d38272d38223c5a98c22347b9985687f6d4530 Mon Sep 17 00:00:00 2001 From: Ignacio Colautti Date: Wed, 2 Sep 2020 06:05:04 -0700 Subject: [PATCH 4/5] OpportunityApi list method consolidated --- src/Api/OpportunityApi.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Api/OpportunityApi.php b/src/Api/OpportunityApi.php index f7723c5..f2d70e5 100644 --- a/src/Api/OpportunityApi.php +++ b/src/Api/OpportunityApi.php @@ -50,18 +50,13 @@ protected function initUrls() */ public function list(int $offset = 0, int $limit = self::MAX_ITEMS_PER_REQUEST, array $filters = [], array $fields = []): array { - $params = [ + /** @var Opportunity[] $opportunities */ + $opportunities = []; + $response = $this->client->get($this->prepareUrlForKey('get-opportunities'), array_merge($filters, [ '_skip' => $offset, '_limit' => $limit, '_fields' => $fields, - ]; - - if (!empty($filters)) { - $params['query'] = $this->buildQueryString($filters); - } - - $opportunities = []; - $response = $this->client->get($this->prepareUrlForKey('get-opportunities'), $params); + ])); $responseData = $response->getDecodedBody(); From a3e2183b791d65f1569bae7eee3ff66784384986 Mon Sep 17 00:00:00 2001 From: Ignacio Colautti Date: Thu, 3 Sep 2020 13:49:23 -0300 Subject: [PATCH 5/5] Meeting API added --- src/Api/MeetingActivityApi.php | 132 +++++++++++++++ src/CloseIoApiWrapper.php | 15 ++ src/Model/MeetingActivity.php | 299 +++++++++++++++++++++++++++++++++ 3 files changed, 446 insertions(+) create mode 100644 src/Api/MeetingActivityApi.php create mode 100644 src/Model/MeetingActivity.php diff --git a/src/Api/MeetingActivityApi.php b/src/Api/MeetingActivityApi.php new file mode 100644 index 0000000..c9139a7 --- /dev/null +++ b/src/Api/MeetingActivityApi.php @@ -0,0 +1,132 @@ +urls = [ + 'get-meetings' => '/activity/meeting/', + 'get-meeting' => '/activity/meeting/[:id]/', + 'add-meeting' => '/activity/meeting/', + 'update-meeting' => '/activity/meeting/[:id]/', + 'delete-meeting' => '/activity/meeting/[:id]/', + ]; + } + + /** + * Gets up to the specified number of meeting activities that match the given + * criteria. + * + * @param int $offset The offset from which start getting the items + * @param int $limit The maximum number of items to get + * @param array $filters A set of criteria to filter the items by + * @param string[] $fields The subset of fields to get (defaults to all) + * + * @return MeetingActivity[] + */ + public function list(int $offset = 0, int $limit = self::MAX_ITEMS_PER_REQUEST, array $filters = [], array $fields = []): array + { + /** @var MeetingActivity[] $activities */ + $activities = []; + $response = $this->client->get($this->prepareUrlForKey('get-meetings'), array_merge($filters, [ + '_skip' => $offset, + '_limit' => $limit, + '_fields' => $fields, + ])); + + $responseData = $response->getDecodedBody(); + + foreach ($responseData['data'] as $activity) { + $activities[] = new MeetingActivity($activity); + } + + return $activities; + } + + /** + * Gets the information about the meeting activity that matches the given ID. + * + * @param string $id The ID of the activity + * @param string[] $fields The subset of fields to get (defaults to all) + * + * @return MeetingActivity + */ + public function get(string $id, array $fields = []): MeetingActivity + { + $response = $this->client->get($this->prepareUrlForKey('get-meeting', ['id' => $id]), ['_fields' => $fields]); + + return new MeetingActivity($response->getDecodedBody()); + } + + /** + * Creates a new meeting activity using the given information. + * + * @param MeetingActivity $activity The information of the activity to create + * + * @return MeetingActivity + */ + public function create(MeetingActivity $activity): MeetingActivity + { + $response = $this->client->post($this->prepareUrlForKey('add-meeting'), [], $activity->jsonSerialize()); + $responseData = $response->getDecodedBody(); + + return new MeetingActivity($responseData); + } + + /** + * Updates the given meeting activity. + * + * @param MeetingActivity $activity The activity to update + * + * @return MeetingActivity + */ + public function update(MeetingActivity $activity): MeetingActivity + { + $id = $activity->getId(); + + $activity->setId(null); + + $response = $this->client->put($this->prepareUrlForKey('update-meeting', ['id' => $id]), [], $activity->jsonSerialize()); + $responseData = $response->getDecodedBody(); + + return new MeetingActivity($responseData); + } + + /** + * Deletes the given meeting activity. + * + * @param MeetingActivity $activity The meeting activity to delete + */ + public function delete(MeetingActivity $activity): void + { + $id = $activity->getId(); + + $activity->setId(null); + + $this->client->delete($this->prepareUrlForKey('delete-meeting', ['id' => $id])); + } +} diff --git a/src/CloseIoApiWrapper.php b/src/CloseIoApiWrapper.php index 6849d5f..260b45e 100644 --- a/src/CloseIoApiWrapper.php +++ b/src/CloseIoApiWrapper.php @@ -20,6 +20,7 @@ use LooplineSystems\CloseIoApiWrapper\Api\EmailActivityApi; use LooplineSystems\CloseIoApiWrapper\Api\LeadApi; use LooplineSystems\CloseIoApiWrapper\Api\LeadStatusApi; +use LooplineSystems\CloseIoApiWrapper\Api\MeetingActivityApi; use LooplineSystems\CloseIoApiWrapper\Api\NoteActivityApi; use LooplineSystems\CloseIoApiWrapper\Api\OpportunityApi; use LooplineSystems\CloseIoApiWrapper\Api\OpportunityStatusApi; @@ -79,6 +80,11 @@ class CloseIoApiWrapper */ private $emailActivitiesApi; + /** + * @var MeetingActivityApi + */ + private $meetingActivitiesApi; + /** * @var NoteActivityApi */ @@ -106,6 +112,7 @@ public function __construct(Client $client) $this->callActivitiesApi = new CallActivityApi($client); $this->smsActivitiesApi = new SmsActivityApi($client); $this->emailActivitiesApi = new EmailActivityApi($client); + $this->meetingActivitiesApi = new MeetingActivityApi($client); $this->noteActivitiesApi = new NoteActivityApi($client); $this->taskApi = new TaskApi($client); $this->userApi = new UserApi($client); @@ -191,6 +198,14 @@ public function getEmailActivitiesApi(): EmailActivityApi return $this->emailActivitiesApi; } + /** + * @return MeetingActivityApi + */ + public function getMeetingActivitiesApi(): MeetingActivityApi + { + return $this->meetingActivitiesApi; + } + /** * @return NoteActivityApi */ diff --git a/src/Model/MeetingActivity.php b/src/Model/MeetingActivity.php new file mode 100644 index 0000000..5c1c84f --- /dev/null +++ b/src/Model/MeetingActivity.php @@ -0,0 +1,299 @@ +attendees; + } + + /** + * @param Contact[] $attendees + * + * @return MeetingActivity + */ + public function setAttendees(array $attendees) + { + $this->attendees = $attendees; + + return $this; + } + + /** + * @return string + */ + public function getCalendarEventLink() + { + return $this->calendar_event_link; + } + + /** + * @param string $calendar_event_link + * + * @return MeetingActivity + */ + public function setCalendarEventLink($calendar_event_link) + { + $this->calendar_event_link = $calendar_event_link; + + return $this; + } + + /** + * @return string + */ + public function getConnectedAccountId() + { + return $this->connected_account_id; + } + + /** + * @param string $connected_account_id + * + * @return MeetingActivity + */ + public function setConnectedAccountId($connected_account_id) + { + $this->connected_account_id = $connected_account_id; + + return $this; + } + + /** + * @return int + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param int $duration + * + * @return MeetingActivity + */ + public function setDuration($duration) + { + $this->duration = $duration; + + return $this; + } + + /** + * @return \DateTime + */ + public function getEndsAt() + { + return $this->ends_at; + } + + /** + * @param \DateTime $ends_at + * + * @return MeetingActivity + */ + public function setEndsAt($ends_at) + { + $this->ends_at = $ends_at; + + return $this; + } + + /** + * @return bool + */ + public function getIsRecurring() + { + return $this->is_recurring; + } + + /** + * @param bool $is_recurring + * + * @return MeetingActivity + */ + public function setIsRecurring($is_recurring) + { + $this->is_recurring = $is_recurring; + + return $this; + } + + /** + * @return string + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param string $duration + * + * @return MeetingActivity + */ + public function setLocation($location) + { + $this->location = $location; + + return $this; + } + + /** + * @return string + */ + public function getNote() + { + return $this->note; + } + + /** + * @param string $note + * + * @return MeetingActivity + */ + public function setNote($note) + { + $this->note = $note; + + return $this; + } + + /** + * @return string + */ + public function getSource() + { + return $this->source; + } + + /** + * @param string $source + * + * @return MeetingActivity + */ + public function setSource($source) + { + $this->source = $source; + + return $this; + } + + /** + * @return \DateTime + */ + public function getStartsAt() + { + return $this->starts_at; + } + + /** + * @param \DateTime $starts_at + * + * @return MeetingActivity + */ + public function setStartsAt($starts_at) + { + $this->starts_at = $starts_at; + + return $this; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param string $status + * + * @return MeetingActivity + */ + public function setStatus($status) + { + $this->status = $status; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * + * @return MeetingActivity + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } +}