Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Email validation updated #110

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
132 changes: 132 additions & 0 deletions src/Api/MeetingActivityApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

/**
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems.
*
* @see https://github.com/loopline-systems/closeio-api-wrapper for the canonical source repository
*
* @copyright Copyright (c) 2014 LLS Internet GmbH - Loopline Systems (http://www.loopline-systems.com)
* @license https://github.com/loopline-systems/closeio-api-wrapper/blob/master/LICENSE (MIT Licence)
*/

declare(strict_types=1);

namespace LooplineSystems\CloseIoApiWrapper\Api;

use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi;
use LooplineSystems\CloseIoApiWrapper\Model\MeetingActivity;

class MeetingActivityApi extends AbstractApi
{
/**
* The maximum number of items that are requested by default.
*/
private const MAX_ITEMS_PER_REQUEST = 100;

/**
* {@inheritdoc}
*/
protected function initUrls()
{
$this->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]));
}
}
13 changes: 4 additions & 9 deletions src/Api/OpportunityApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
15 changes: 15 additions & 0 deletions src/CloseIoApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,11 @@ class CloseIoApiWrapper
*/
private $emailActivitiesApi;

/**
* @var MeetingActivityApi
*/
private $meetingActivitiesApi;

/**
* @var NoteActivityApi
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -191,6 +198,14 @@ public function getEmailActivitiesApi(): EmailActivityApi
return $this->emailActivitiesApi;
}

/**
* @return MeetingActivityApi
*/
public function getMeetingActivitiesApi(): MeetingActivityApi
{
return $this->meetingActivitiesApi;
}

/**
* @return NoteActivityApi
*/
Expand Down
31 changes: 30 additions & 1 deletion src/Model/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +38,16 @@ class Email implements \JsonSerializable
*/
private $type;

/**
* @var object
*/
private $validator;

/**
* @var object
*/
private $validation;

/**
* @param array $data
*
Expand Down Expand Up @@ -65,7 +77,7 @@ public function getEmail()
*/
public function setEmail($email)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
if (!$this->_getValidator()->isValid($email, $this->_getValidation())) {
throw new InvalidParamException('Invalid email format: "' . $email . '"');
} else {
$this->email = $email;
Expand Down Expand Up @@ -93,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;
}
}

Loading