This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs #68: Add User model and UserApi
- Loading branch information
1 parent
a07872d
commit 460407b
Showing
4 changed files
with
421 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
/** | ||
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems | ||
* | ||
* @link 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) | ||
*/ | ||
|
||
namespace LooplineSystems\CloseIoApiWrapper\Api; | ||
|
||
use LooplineSystems\CloseIoApiWrapper\CloseIoResponse; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Api\AbstractApi; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Curl\Curl; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\BadApiRequestException; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\InvalidParamException; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\ResourceNotFoundException; | ||
use LooplineSystems\CloseIoApiWrapper\Library\Exception\UrlNotSetException; | ||
use LooplineSystems\CloseIoApiWrapper\Model\User; | ||
|
||
class UserApi extends AbstractApi | ||
{ | ||
const NAME = 'UserApi'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function initUrls() | ||
{ | ||
$this->urls = [ | ||
'get-current-user' => '/me/', | ||
'get-users' => '/user/', | ||
'get-user' => '/user/[:id]', | ||
]; | ||
} | ||
|
||
/** | ||
* @return User | ||
* | ||
* @throws BadApiRequestException | ||
* @throws InvalidParamException | ||
* @throws ResourceNotFoundException | ||
* @throws UrlNotSetException | ||
*/ | ||
public function getCurrentUser() | ||
{ | ||
$apiRequest = $this->prepareRequest('get-current-user'); | ||
|
||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200 && (!empty($result->getData()))) { | ||
$user = new User($result->getData()); | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @return User[] | ||
* | ||
* @throws BadApiRequestException | ||
* @throws InvalidParamException | ||
* @throws UrlNotSetException | ||
* @throws ResourceNotFoundException | ||
*/ | ||
public function getAllUsers() | ||
{ | ||
/** @var User[] $users */ | ||
$users = array(); | ||
|
||
$apiRequest = $this->prepareRequest('get-users'); | ||
|
||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200) { | ||
$rawData = $result->getData()[CloseIoResponse::GET_RESPONSE_DATA_KEY]; | ||
foreach ($rawData as $user) { | ||
$users[] = new User($user); | ||
} | ||
} | ||
|
||
return $users; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return User | ||
* | ||
* @throws BadApiRequestException | ||
* @throws InvalidParamException | ||
* @throws ResourceNotFoundException | ||
* @throws UrlNotSetException | ||
*/ | ||
public function getUser($id) | ||
{ | ||
$apiRequest = $this->prepareRequest('get-user', null, ['id' => $id]); | ||
|
||
$result = $this->triggerGet($apiRequest); | ||
|
||
if ($result->getReturnCode() == 200 && (!empty($result->getData()))) { | ||
$user = new User($result->getData()); | ||
} else { | ||
throw new ResourceNotFoundException(); | ||
} | ||
|
||
return $user; | ||
} | ||
|
||
/** | ||
* @param User $user | ||
* @return bool | ||
*/ | ||
public function validateUserForPost(User $user) | ||
{ | ||
return true; | ||
} | ||
|
||
} |
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,196 @@ | ||
<?php | ||
/** | ||
* Close.io Api Wrapper - LLS Internet GmbH - Loopline Systems | ||
* | ||
* @link 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) | ||
*/ | ||
|
||
namespace LooplineSystems\CloseIoApiWrapper\Model; | ||
|
||
use LooplineSystems\CloseIoApiWrapper\Library\ObjectHydrateHelperTrait; | ||
use LooplineSystems\CloseIoApiWrapper\Library\JsonSerializableHelperTrait; | ||
|
||
class User implements \JsonSerializable | ||
{ | ||
use ObjectHydrateHelperTrait; | ||
use JsonSerializableHelperTrait; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $email; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $first_name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $last_name; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $image; | ||
|
||
/** | ||
* @var \DateTime | ||
*/ | ||
private $date_created; | ||
|
||
/** | ||
* @var \DateTime | ||
*/ | ||
private $date_updated; | ||
/** | ||
* @var array | ||
*/ | ||
private $organizations; | ||
|
||
/** | ||
* @param array $data | ||
*/ | ||
public function __construct(array $data = null) | ||
{ | ||
if ($data) { | ||
$this->hydrate($data); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getEmail() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* @param string $email | ||
*/ | ||
public function setEmail($email) | ||
{ | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getFirstName() | ||
{ | ||
return $this->first_name; | ||
} | ||
|
||
/** | ||
* @param string $first_name | ||
*/ | ||
public function setFirstName($first_name) | ||
{ | ||
$this->first_name = $first_name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getLastName() | ||
{ | ||
return $this->last_name; | ||
} | ||
|
||
/** | ||
* @param string $last_name | ||
*/ | ||
public function setLastName($last_name) | ||
{ | ||
$this->last_name = $last_name; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getImage() | ||
{ | ||
return $this->image; | ||
} | ||
|
||
/** | ||
* @param string $image | ||
*/ | ||
public function setImage($image) | ||
{ | ||
$this->image = $image; | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getDateCreated() | ||
{ | ||
return $this->date_created; | ||
} | ||
|
||
/** | ||
* @param \DateTime $date_created | ||
*/ | ||
public function setDateCreated($date_created) | ||
{ | ||
$this->date_created = $date_created; | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getDateUpdated() | ||
{ | ||
return $this->date_updated; | ||
} | ||
|
||
/** | ||
* @param \DateTime $date_updated | ||
*/ | ||
public function setDateUpdated($date_updated) | ||
{ | ||
$this->date_updated = $date_updated; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOrganizations() | ||
{ | ||
return $this->organizations; | ||
} | ||
|
||
/** | ||
* @param array $organizations | ||
*/ | ||
public function setOrganizations($organizations) | ||
{ | ||
$this->organizations = $organizations; | ||
} | ||
} |
Oops, something went wrong.