@@ -29,86 +29,86 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Api |
| 31 | 31 | { |
| 32 | - /** |
|
| 33 | - * @var EndpointsContainer |
|
| 34 | - */ |
|
| 35 | - protected $endpointsContainer; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - protected $organizationId; |
|
| 41 | - |
|
| 42 | - public function __construct(EndpointsContainer $endpointsContainer) |
|
| 43 | - { |
|
| 44 | - $this->endpointsContainer = $endpointsContainer; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Magic method to access different endpoints. |
|
| 49 | - * |
|
| 50 | - * @param string $endpoint |
|
| 51 | - * |
|
| 52 | - * @return Endpoint |
|
| 53 | - */ |
|
| 54 | - public function __get($endpoint) |
|
| 55 | - { |
|
| 56 | - $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
| 57 | - |
|
| 58 | - if (method_exists($endpoint, 'setOrganizationId')) { |
|
| 59 | - $endpoint->setOrganizationId($this->organizationId); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $endpoint; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @param $organizationName |
|
| 67 | - * @return $this |
|
| 68 | - */ |
|
| 69 | - public function setOrganization($organizationName) |
|
| 70 | - { |
|
| 71 | - if($organization = $this->getOrganizationByName($organizationName)) { |
|
| 72 | - $this->setOrganizationId($organization['organizationId']); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $this; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param int $organizationId |
|
| 80 | - * @return $this |
|
| 81 | - */ |
|
| 82 | - public function setOrganizationId($organizationId) |
|
| 83 | - { |
|
| 84 | - $this->organizationId = $organizationId; |
|
| 85 | - |
|
| 86 | - return $this; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - public function getOrganizationId() |
|
| 94 | - { |
|
| 95 | - return $this->organizationId; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param $organization |
|
| 100 | - * @return bool|array |
|
| 101 | - */ |
|
| 102 | - protected function getOrganizationByName($organization) |
|
| 103 | - { |
|
| 104 | - $organizations = $this->organizations->getAll(); |
|
| 105 | - |
|
| 106 | - foreach ($organizations['entities'] as $entity) { |
|
| 107 | - if ($entity['name'] == $organization) { |
|
| 108 | - return $entity; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return false; |
|
| 113 | - } |
|
| 32 | + /** |
|
| 33 | + * @var EndpointsContainer |
|
| 34 | + */ |
|
| 35 | + protected $endpointsContainer; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + protected $organizationId; |
|
| 41 | + |
|
| 42 | + public function __construct(EndpointsContainer $endpointsContainer) |
|
| 43 | + { |
|
| 44 | + $this->endpointsContainer = $endpointsContainer; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Magic method to access different endpoints. |
|
| 49 | + * |
|
| 50 | + * @param string $endpoint |
|
| 51 | + * |
|
| 52 | + * @return Endpoint |
|
| 53 | + */ |
|
| 54 | + public function __get($endpoint) |
|
| 55 | + { |
|
| 56 | + $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
| 57 | + |
|
| 58 | + if (method_exists($endpoint, 'setOrganizationId')) { |
|
| 59 | + $endpoint->setOrganizationId($this->organizationId); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $endpoint; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @param $organizationName |
|
| 67 | + * @return $this |
|
| 68 | + */ |
|
| 69 | + public function setOrganization($organizationName) |
|
| 70 | + { |
|
| 71 | + if($organization = $this->getOrganizationByName($organizationName)) { |
|
| 72 | + $this->setOrganizationId($organization['organizationId']); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $this; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param int $organizationId |
|
| 80 | + * @return $this |
|
| 81 | + */ |
|
| 82 | + public function setOrganizationId($organizationId) |
|
| 83 | + { |
|
| 84 | + $this->organizationId = $organizationId; |
|
| 85 | + |
|
| 86 | + return $this; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + public function getOrganizationId() |
|
| 94 | + { |
|
| 95 | + return $this->organizationId; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param $organization |
|
| 100 | + * @return bool|array |
|
| 101 | + */ |
|
| 102 | + protected function getOrganizationByName($organization) |
|
| 103 | + { |
|
| 104 | + $organizations = $this->organizations->getAll(); |
|
| 105 | + |
|
| 106 | + foreach ($organizations['entities'] as $entity) { |
|
| 107 | + if ($entity['name'] == $organization) { |
|
| 108 | + return $entity; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return false; |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | \ No newline at end of file |
@@ -6,112 +6,112 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Endpoint |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @var array |
|
| 11 | - */ |
|
| 12 | - protected $allowedMethods = [ |
|
| 13 | - 'getById', |
|
| 14 | - 'getAll', |
|
| 15 | - 'create', |
|
| 16 | - 'update', |
|
| 17 | - 'delete', |
|
| 18 | - ]; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $endpoint; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected $headers = []; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var HttpClient |
|
| 32 | - */ |
|
| 33 | - protected $http; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - protected $organizationId; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param HttpClient $http |
|
| 42 | - */ |
|
| 43 | - public function __construct(HttpClient $http) |
|
| 44 | - { |
|
| 45 | - $this->http = $http; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param string $verb |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public function makeRequestUrl($verb = '') |
|
| 53 | - { |
|
| 54 | - return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param string $method |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isMethodAllowed($method) |
|
| 62 | - { |
|
| 63 | - return in_array($method, $this->allowedMethods); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return HttpClient |
|
| 68 | - */ |
|
| 69 | - public function getHttp() |
|
| 70 | - { |
|
| 71 | - return $this->http; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param array $params |
|
| 76 | - * @return array |
|
| 77 | - */ |
|
| 78 | - public function getAll(array $params = []) |
|
| 79 | - { |
|
| 80 | - return $this->getHttp()->get( |
|
| 81 | - $this->makeRequestUrl(), $params, $this->getHeaders() |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $id |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - public function getById($id) |
|
| 90 | - { |
|
| 91 | - return $this->getHttp()->get( |
|
| 92 | - $this->makeRequestUrl($id), [], $this->getHeaders() |
|
| 93 | - ); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @return array |
|
| 98 | - */ |
|
| 99 | - protected function getHeaders() |
|
| 100 | - { |
|
| 101 | - return array_merge( |
|
| 102 | - $this->headers, |
|
| 103 | - ['organizationId' => $this->organizationId] |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param int $organizationId |
|
| 109 | - * @return $this |
|
| 110 | - */ |
|
| 111 | - public function setOrganizationId($organizationId) |
|
| 112 | - { |
|
| 113 | - $this->organizationId = $organizationId; |
|
| 114 | - |
|
| 115 | - return $this; |
|
| 116 | - } |
|
| 9 | + /** |
|
| 10 | + * @var array |
|
| 11 | + */ |
|
| 12 | + protected $allowedMethods = [ |
|
| 13 | + 'getById', |
|
| 14 | + 'getAll', |
|
| 15 | + 'create', |
|
| 16 | + 'update', |
|
| 17 | + 'delete', |
|
| 18 | + ]; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $endpoint; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected $headers = []; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var HttpClient |
|
| 32 | + */ |
|
| 33 | + protected $http; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + protected $organizationId; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param HttpClient $http |
|
| 42 | + */ |
|
| 43 | + public function __construct(HttpClient $http) |
|
| 44 | + { |
|
| 45 | + $this->http = $http; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param string $verb |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public function makeRequestUrl($verb = '') |
|
| 53 | + { |
|
| 54 | + return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param string $method |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isMethodAllowed($method) |
|
| 62 | + { |
|
| 63 | + return in_array($method, $this->allowedMethods); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return HttpClient |
|
| 68 | + */ |
|
| 69 | + public function getHttp() |
|
| 70 | + { |
|
| 71 | + return $this->http; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param array $params |
|
| 76 | + * @return array |
|
| 77 | + */ |
|
| 78 | + public function getAll(array $params = []) |
|
| 79 | + { |
|
| 80 | + return $this->getHttp()->get( |
|
| 81 | + $this->makeRequestUrl(), $params, $this->getHeaders() |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $id |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + public function getById($id) |
|
| 90 | + { |
|
| 91 | + return $this->getHttp()->get( |
|
| 92 | + $this->makeRequestUrl($id), [], $this->getHeaders() |
|
| 93 | + ); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @return array |
|
| 98 | + */ |
|
| 99 | + protected function getHeaders() |
|
| 100 | + { |
|
| 101 | + return array_merge( |
|
| 102 | + $this->headers, |
|
| 103 | + ['organizationId' => $this->organizationId] |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param int $organizationId |
|
| 109 | + * @return $this |
|
| 110 | + */ |
|
| 111 | + public function setOrganizationId($organizationId) |
|
| 112 | + { |
|
| 113 | + $this->organizationId = $organizationId; |
|
| 114 | + |
|
| 115 | + return $this; |
|
| 116 | + } |
|
| 117 | 117 | } |
| 118 | 118 | \ No newline at end of file |
@@ -7,35 +7,35 @@ |
||
| 7 | 7 | class Cards extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'cards'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'cards'; |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @param string $widgetCommonId |
|
| 19 | - * @return mixed |
|
| 20 | - */ |
|
| 21 | - public function getAll($widgetCommonId) |
|
| 22 | - { |
|
| 23 | - return parent::getAll(['widgetCommonId'=>$widgetCommonId]); |
|
| 24 | - } |
|
| 17 | + /** |
|
| 18 | + * @param string $widgetCommonId |
|
| 19 | + * @return mixed |
|
| 20 | + */ |
|
| 21 | + public function getAll($widgetCommonId) |
|
| 22 | + { |
|
| 23 | + return parent::getAll(['widgetCommonId'=>$widgetCommonId]); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @param string $cardId |
|
| 28 | - * @param bool $everywhere |
|
| 29 | - * @return mixed |
|
| 30 | - */ |
|
| 31 | - public function delete($cardId, $everywhere) |
|
| 32 | - { |
|
| 33 | - return $this |
|
| 34 | - ->getHttp() |
|
| 35 | - ->delete( |
|
| 36 | - $this->makeRequestUrl($cardId), |
|
| 37 | - ['everywhere' => $everywhere], |
|
| 38 | - $this->getHeaders() |
|
| 39 | - ); |
|
| 40 | - } |
|
| 26 | + /** |
|
| 27 | + * @param string $cardId |
|
| 28 | + * @param bool $everywhere |
|
| 29 | + * @return mixed |
|
| 30 | + */ |
|
| 31 | + public function delete($cardId, $everywhere) |
|
| 32 | + { |
|
| 33 | + return $this |
|
| 34 | + ->getHttp() |
|
| 35 | + ->delete( |
|
| 36 | + $this->makeRequestUrl($cardId), |
|
| 37 | + ['everywhere' => $everywhere], |
|
| 38 | + $this->getHeaders() |
|
| 39 | + ); |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | class Tasks extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'tasks'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'tasks'; |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | class Columns extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'columns'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'columns'; |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | class Comments extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'comments'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'comments'; |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | class Tags extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'tags'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'tags'; |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
| 7 | 7 | class TaskLists extends Endpoint |
| 8 | 8 | { |
| 9 | 9 | |
| 10 | - use CrudEndpoint; |
|
| 10 | + use CrudEndpoint; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @var string |
|
| 14 | - */ |
|
| 15 | - protected $endpoint = 'tasklists'; |
|
| 12 | + /** |
|
| 13 | + * @var string |
|
| 14 | + */ |
|
| 15 | + protected $endpoint = 'tasklists'; |
|
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Collections extends Endpoint |
| 8 | 8 | { |
| 9 | - use CrudEndpoint; |
|
| 9 | + use CrudEndpoint; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $endpoint = 'collections'; |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $endpoint = 'collections'; |
|
| 15 | 15 | } |
| 16 | 16 | \ No newline at end of file |