-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
542 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace ChartMogul; | ||
|
||
use ChartMogul\Resource\AbstractResource; | ||
use ChartMogul\Resource\CollectionWithCursor; | ||
use ChartMogul\Http\ClientInterface; | ||
use ChartMogul\Service\AllTrait; | ||
use ChartMogul\Service\UpdateTrait; | ||
use ChartMogul\Service\CreateTrait; | ||
use ChartMogul\Service\DestroyTrait; | ||
use ChartMogul\Service\GetTrait; | ||
|
||
/** | ||
* @property-read string $uuid | ||
* @property-read string $customer_uuid | ||
* @property-read string $data_source_uuid | ||
* @property-read string $customer_external_id | ||
* @property-read string $first_name | ||
* @property-read string $last_name | ||
* @property-read integer $position | ||
* @property-read string $email | ||
* @property-read string $title | ||
* @property-read string $notes | ||
* @property-read string $phone | ||
* @property-read string $linked_in | ||
* @property-read string $twitter | ||
* @property-read string $custom | ||
*/ | ||
class Contact extends AbstractResource | ||
{ | ||
use CreateTrait; | ||
use AllTrait; | ||
use GetTrait; | ||
use DestroyTrait; | ||
use UpdateTrait; | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
public const RESOURCE_NAME = 'Contact'; | ||
/** | ||
* @ignore | ||
*/ | ||
public const RESOURCE_PATH = '/v1/contacts'; | ||
public const RESOURCE_ID = 'contact_uuid'; | ||
public const ROOT_KEY = 'entries'; | ||
|
||
protected $uuid; | ||
protected $customer_uuid; | ||
protected $data_source_uuid; | ||
protected $customer_external_id; | ||
protected $first_name; | ||
protected $last_name; | ||
protected $position; | ||
protected $email; | ||
protected $title; | ||
protected $notes; | ||
protected $phone; | ||
protected $linked_in; | ||
protected $twitter; | ||
protected $custom; | ||
|
||
/** | ||
* Merge Contacts | ||
* @param string $into | ||
* @param string $from | ||
* @param ClientInterface|null $client | ||
* @return Contact | ||
*/ | ||
public static function merge($into, $from, ClientInterface $client = null) | ||
{ | ||
$result = (new static([], $client)) | ||
->getClient() | ||
->send("/v1/contacts/".$into."/merge/".$from, "POST"); | ||
|
||
return new Contact($result, $client); | ||
} | ||
|
||
/** | ||
* Overrides fromArray so that it will return a collection with cursor instead. | ||
* | ||
* @param array $data | ||
* @param ClientInterface|null $client | ||
* @return CollectionWithCursor|static | ||
*/ | ||
public static function fromArray(array $data, ClientInterface $client = null) | ||
{ | ||
if (isset($data[static::ROOT_KEY])) { | ||
$array = new CollectionWithCursor(array_map(function ($data) use ($client) { | ||
return static::fromArray($data, $client); | ||
}, $data[static::ROOT_KEY])); | ||
|
||
if (isset($data["cursor"])) { | ||
$array->cursor = $data["cursor"]; | ||
} | ||
|
||
if (isset($data["has_more"])) { | ||
$array->has_more = $data["has_more"]; | ||
} | ||
|
||
return $array; | ||
} | ||
|
||
return new static($data, $client); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace ChartMogul\Resource; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
|
||
class CollectionWithCursor extends ArrayCollection | ||
{ | ||
/** | ||
* @var boolean | ||
*/ | ||
public $has_more; | ||
/** | ||
* @var string | ||
*/ | ||
public $cursor; | ||
} |
Oops, something went wrong.