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

Add EmailActivity. #24

Merged
merged 1 commit into from
Nov 18, 2017
Merged
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
63 changes: 51 additions & 12 deletions src/LooplineSystems/CloseIoApiWrapper/Api/ActivityApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use LooplineSystems\CloseIoApiWrapper\CloseIoResponse;
use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi;
use LooplineSystems\CloseIoApiWrapper\Model\Activity;
use LooplineSystems\CloseIoApiWrapper\Model\Call;
use LooplineSystems\CloseIoApiWrapper\Model\CallActivity;
use LooplineSystems\CloseIoApiWrapper\Model\EmailActivity;
use LooplineSystems\CloseIoApiWrapper\Model\NoteActivity;

class ActivityApi extends AbstractApi
{
Expand All @@ -21,16 +23,18 @@ protected function initUrls()
'add-note' => '/activity/note/',
'get-notes' => '/activity/note/',
'add-call' => '/activity/call/',
'get-calls' => '/activity/call/'
'get-calls' => '/activity/call/',
'add-email' => '/activity/email/',
'get-emails' => '/activity/email/',
];
}

/**
* @param Activity $activity
* @param NoteActivity $activity
*
* @return Activity
*/
public function addNote(Activity $activity)
public function addNote(NoteActivity $activity)
{
$activity = json_encode($activity);
$apiRequest = $this->prepareRequest('add-note', $activity);
Expand All @@ -41,24 +45,39 @@ public function addNote(Activity $activity)
}

/**
* @param Call $call
* @param CallActivity $call
*
* @return Call
* @return CallActivity
*/
public function addCall(Call $call)
public function addCall(CallActivity $call)
{
$call = json_encode($call);
$apiRequest = $this->prepareRequest('add-call', $call);

$result = $this->triggerPost($apiRequest);

return new Call($result->getData());
return new CallActivity($result->getData());
}

/**
* @param EmailActivity $email
*
* @return EmailActivity
*/
public function addEmail(EmailActivity $email)
{
$email = json_encode($email);
$apiRequest = $this->prepareRequest('add-email', $email);

$result = $this->triggerPost($apiRequest);

return new EmailActivity($result->getData());
}

/**
* @param array $filters
*
* @return array
* @return NoteActivity[]
*/
public function getNotes(array $filters)
{
Expand All @@ -69,7 +88,7 @@ public function getNotes(array $filters)
$rawData = $result->getData()[CloseIoResponse::GET_RESPONSE_DATA_KEY];
$notes = [];
foreach ($rawData as $note) {
$notes[] = new Activity($note);
$notes[] = new NoteActivity($note);
}

return $notes;
Expand All @@ -78,7 +97,7 @@ public function getNotes(array $filters)
/**
* @param array $filters
*
* @return array
* @return CallActivity[]
*/
public function getCalls(array $filters)
{
Expand All @@ -89,7 +108,27 @@ public function getCalls(array $filters)
$rawData = $result->getData()[CloseIoResponse::GET_RESPONSE_DATA_KEY];
$calls = [];
foreach ($rawData as $call) {
$calls[] = new Activity($call);
$calls[] = new CallActivity($call);
}

return $calls;
}

/**
* @param array $filters
*
* @return EmailActivity[]
*/
public function getEmails(array $filters)
{
$apiRequest = $this->prepareRequest('get-emails', null, [], $filters);

$result = $this->triggerGet($apiRequest);

$rawData = $result->getData()[CloseIoResponse::GET_RESPONSE_DATA_KEY];
$calls = [];
foreach ($rawData as $call) {
$calls[] = new EmailActivity($call);
}

return $calls;
Expand Down
56 changes: 18 additions & 38 deletions src/LooplineSystems/CloseIoApiWrapper/Model/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,75 +10,74 @@ class Activity implements \JsonSerializable
use ObjectHydrateHelperTrait;
use JsonSerializableHelperTrait;

/**
* @var string
*/
private $note;
const ACTIVITY_TYPE_CALL = 'Call';
const ACTIVITY_TYPE_EMAIL = 'Email';
const ACTIVITY_TYPE_NOTE = 'Note';

/**
* @var string
*/
private $user_id;
protected $user_id;

/**
* @var string
*/
private $user_name;
protected $user_name;

/**
* @var string
*/
private $updated_by;
protected $updated_by;

/**
* @var string
*/
private $updated_by_name;
protected $updated_by_name;

/**
* @var string
*/
private $date_updated;
protected $date_updated;

/**
* @var string
*/
private $created_by;
protected $created_by;

/**
* @var string
*/
private $created_by_name;
protected $created_by_name;

/**
* @var string
*/
private $organization_id;
protected $organization_id;

/**
* @var string
*/
private $contact_id;
protected $contact_id;

/**
* @var string
*/
private $date_created;
protected $date_created;

/**
* @var string
*/
private $id;
protected $id;

/**
* @var string
*/
private $lead_id;
protected $lead_id;

/**
* @var string
*/
private $type;
protected $type;

/**
* @param array $data
Expand All @@ -90,26 +89,6 @@ public function __construct(array $data = null)
}
}

/**
* @return string
*/
public function getNote()
{
return $this->note;
}

/**
* @param string $note
*
* @return $this
*/
public function setNote($note)
{
$this->note = $note;

return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -360,12 +339,13 @@ public function getType()

/**
* @param string $type
*
* @return Activity
*/
public function setType($type)
{
$this->type = $type;

return $this;
}

}
Loading