@@ -45,7 +45,7 @@ |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * @param $endpoint |
|
| 48 | + * @param string $endpoint |
|
| 49 | 49 | * @throws WrongEndpoint |
| 50 | 50 | */ |
| 51 | 51 | protected function addProvider($endpoint) |
@@ -8,77 +8,77 @@ |
||
| 8 | 8 | |
| 9 | 9 | class EndpointsContainer |
| 10 | 10 | { |
| 11 | - const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\'; |
|
| 11 | + const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\'; |
|
| 12 | 12 | |
| 13 | - /* |
|
| 13 | + /* |
|
| 14 | 14 | * @var HttpInterface |
| 15 | 15 | */ |
| 16 | - protected $httpClient; |
|
| 16 | + protected $httpClient; |
|
| 17 | 17 | |
| 18 | - /* |
|
| 18 | + /* |
|
| 19 | 19 | * @var array |
| 20 | 20 | */ |
| 21 | - protected $endpoints = []; |
|
| 21 | + protected $endpoints = []; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param HttpClient $httpClient |
|
| 25 | - */ |
|
| 26 | - public function __construct(HttpClient $httpClient) |
|
| 27 | - { |
|
| 28 | - $this->httpClient = $httpClient; |
|
| 29 | - } |
|
| 23 | + /** |
|
| 24 | + * @param HttpClient $httpClient |
|
| 25 | + */ |
|
| 26 | + public function __construct(HttpClient $httpClient) |
|
| 27 | + { |
|
| 28 | + $this->httpClient = $httpClient; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param string $endpoint |
|
| 33 | - * @return Endpoint |
|
| 34 | - */ |
|
| 35 | - public function resolve($endpoint) |
|
| 36 | - { |
|
| 37 | - $endpoint = strtolower($endpoint); |
|
| 31 | + /** |
|
| 32 | + * @param string $endpoint |
|
| 33 | + * @return Endpoint |
|
| 34 | + */ |
|
| 35 | + public function resolve($endpoint) |
|
| 36 | + { |
|
| 37 | + $endpoint = strtolower($endpoint); |
|
| 38 | 38 | |
| 39 | - // Check if an instance has already been initiated |
|
| 40 | - if (!isset($this->endpoints[$endpoint])) { |
|
| 41 | - $this->addProvider($endpoint); |
|
| 42 | - } |
|
| 39 | + // Check if an instance has already been initiated |
|
| 40 | + if (!isset($this->endpoints[$endpoint])) { |
|
| 41 | + $this->addProvider($endpoint); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - return $this->endpoints[$endpoint]; |
|
| 45 | - } |
|
| 44 | + return $this->endpoints[$endpoint]; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @param $endpoint |
|
| 49 | - * @throws WrongEndpoint |
|
| 50 | - */ |
|
| 51 | - protected function addProvider($endpoint) |
|
| 52 | - { |
|
| 53 | - $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint); |
|
| 47 | + /** |
|
| 48 | + * @param $endpoint |
|
| 49 | + * @throws WrongEndpoint |
|
| 50 | + */ |
|
| 51 | + protected function addProvider($endpoint) |
|
| 52 | + { |
|
| 53 | + $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint); |
|
| 54 | 54 | |
| 55 | - if (!class_exists($className)) { |
|
| 56 | - throw new WrongEndpoint("Endpoint $className not found."); |
|
| 57 | - } |
|
| 55 | + if (!class_exists($className)) { |
|
| 56 | + throw new WrongEndpoint("Endpoint $className not found."); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $this->endpoints[$endpoint] = $this->buildEndpoint($className); |
|
| 60 | - } |
|
| 59 | + $this->endpoints[$endpoint] = $this->buildEndpoint($className); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $className |
|
| 64 | - * @return Endpoint|object |
|
| 65 | - */ |
|
| 66 | - protected function buildEndpoint($className) |
|
| 67 | - { |
|
| 68 | - return (new ReflectionClass($className))->newInstanceArgs([$this->httpClient]); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * @param string $className |
|
| 64 | + * @return Endpoint|object |
|
| 65 | + */ |
|
| 66 | + protected function buildEndpoint($className) |
|
| 67 | + { |
|
| 68 | + return (new ReflectionClass($className))->newInstanceArgs([$this->httpClient]); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return array |
|
| 73 | - */ |
|
| 74 | - public function getRateInfo() |
|
| 75 | - { |
|
| 76 | - $responseHeaders = $this->httpClient->getResponseHeaders(); |
|
| 71 | + /** |
|
| 72 | + * @return array |
|
| 73 | + */ |
|
| 74 | + public function getRateInfo() |
|
| 75 | + { |
|
| 76 | + $responseHeaders = $this->httpClient->getResponseHeaders(); |
|
| 77 | 77 | |
| 78 | - return [ |
|
| 79 | - 'reset' => $responseHeaders['X-RateLimit-Reset'][0], |
|
| 80 | - 'limit' => $responseHeaders['X-RateLimit-Limit'][0], |
|
| 81 | - 'remaining' => $responseHeaders['X-RateLimit-Remaining'][0], |
|
| 82 | - ]; |
|
| 83 | - } |
|
| 78 | + return [ |
|
| 79 | + 'reset' => $responseHeaders['X-RateLimit-Reset'][0], |
|
| 80 | + 'limit' => $responseHeaders['X-RateLimit-Limit'][0], |
|
| 81 | + 'remaining' => $responseHeaders['X-RateLimit-Remaining'][0], |
|
| 82 | + ]; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | \ No newline at end of file |
@@ -8,36 +8,36 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Favro |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @param string $login |
|
| 13 | - * @param string $password |
|
| 14 | - * @return Api |
|
| 15 | - */ |
|
| 16 | - public static function create($login, $password) |
|
| 17 | - { |
|
| 18 | - $endpointsContainer = new EndpointsContainer( |
|
| 19 | - self::getHttpInterfaceAdapter($login, $password) |
|
| 20 | - ); |
|
| 21 | - return new Api($endpointsContainer); |
|
| 22 | - } |
|
| 11 | + /** |
|
| 12 | + * @param string $login |
|
| 13 | + * @param string $password |
|
| 14 | + * @return Api |
|
| 15 | + */ |
|
| 16 | + public static function create($login, $password) |
|
| 17 | + { |
|
| 18 | + $endpointsContainer = new EndpointsContainer( |
|
| 19 | + self::getHttpInterfaceAdapter($login, $password) |
|
| 20 | + ); |
|
| 21 | + return new Api($endpointsContainer); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $login |
|
| 26 | - * @param string $password |
|
| 27 | - * @return GuzzleHttpClient |
|
| 28 | - */ |
|
| 29 | - protected static function getHttpInterfaceAdapter($login, $password) |
|
| 30 | - { |
|
| 31 | - return new GuzzleHttpClient( |
|
| 32 | - new Client(['auth' => [$login, $password]]) |
|
| 33 | - ); |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $login |
|
| 26 | + * @param string $password |
|
| 27 | + * @return GuzzleHttpClient |
|
| 28 | + */ |
|
| 29 | + protected static function getHttpInterfaceAdapter($login, $password) |
|
| 30 | + { |
|
| 31 | + return new GuzzleHttpClient( |
|
| 32 | + new Client(['auth' => [$login, $password]]) |
|
| 33 | + ); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - private function __construct() |
|
| 37 | - { |
|
| 38 | - } |
|
| 36 | + private function __construct() |
|
| 37 | + { |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - private function __clone() |
|
| 41 | - { |
|
| 42 | - } |
|
| 40 | + private function __clone() |
|
| 41 | + { |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | \ No newline at end of file |
@@ -64,7 +64,7 @@ |
||
| 64 | 64 | */ |
| 65 | 65 | public function setOrganization($organizationName) |
| 66 | 66 | { |
| 67 | - if($organization = $this->getOrganizationByName($organizationName)) { |
|
| 67 | + if ($organization = $this->getOrganizationByName($organizationName)) { |
|
| 68 | 68 | $this->setOrganizationId($organization['organizationId']); |
| 69 | 69 | } |
| 70 | 70 | |
@@ -32,95 +32,95 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Api |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * @var EndpointsContainer |
|
| 37 | - */ |
|
| 38 | - protected $endpointsContainer; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - protected $organizationId; |
|
| 44 | - |
|
| 45 | - public function __construct(EndpointsContainer $endpointsContainer) |
|
| 46 | - { |
|
| 47 | - $this->endpointsContainer = $endpointsContainer; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Magic method to access different endpoints. |
|
| 52 | - * |
|
| 53 | - * @param string $endpoint |
|
| 54 | - * |
|
| 55 | - * @return Endpoint |
|
| 56 | - */ |
|
| 57 | - public function __get($endpoint) |
|
| 58 | - { |
|
| 59 | - $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
| 60 | - |
|
| 61 | - if (method_exists($endpoint, 'setOrganizationId')) { |
|
| 62 | - $endpoint->setOrganizationId($this->organizationId); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $endpoint; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @param $organizationName |
|
| 70 | - * @return $this |
|
| 71 | - */ |
|
| 72 | - public function setOrganization($organizationName) |
|
| 73 | - { |
|
| 74 | - if($organization = $this->getOrganizationByName($organizationName)) { |
|
| 75 | - $this->setOrganizationId($organization['organizationId']); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return $this; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param int $organizationId |
|
| 83 | - * @return $this |
|
| 84 | - */ |
|
| 85 | - public function setOrganizationId($organizationId) |
|
| 86 | - { |
|
| 87 | - $this->organizationId = $organizationId; |
|
| 88 | - |
|
| 89 | - return $this; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public function getOrganizationId() |
|
| 96 | - { |
|
| 97 | - return $this->organizationId; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param string $name |
|
| 102 | - * @param array $arguments |
|
| 103 | - * @return mixed |
|
| 104 | - */ |
|
| 105 | - public function __call($name, $arguments) |
|
| 106 | - { |
|
| 107 | - return call_user_func([$this->endpointsContainer, $name], $arguments); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $organization |
|
| 112 | - * @return array|bool |
|
| 113 | - * @throws WrongOrganizationName |
|
| 114 | - */ |
|
| 115 | - protected function getOrganizationByName($organization) |
|
| 116 | - { |
|
| 117 | - $organizations = $this->organizations->getAll(); |
|
| 118 | - foreach ($organizations['entities'] as $entity) { |
|
| 119 | - if ($entity['name'] == $organization) { |
|
| 120 | - return $entity; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - throw new WrongOrganizationName("Organization $organization not found!"); |
|
| 125 | - } |
|
| 35 | + /** |
|
| 36 | + * @var EndpointsContainer |
|
| 37 | + */ |
|
| 38 | + protected $endpointsContainer; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + protected $organizationId; |
|
| 44 | + |
|
| 45 | + public function __construct(EndpointsContainer $endpointsContainer) |
|
| 46 | + { |
|
| 47 | + $this->endpointsContainer = $endpointsContainer; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Magic method to access different endpoints. |
|
| 52 | + * |
|
| 53 | + * @param string $endpoint |
|
| 54 | + * |
|
| 55 | + * @return Endpoint |
|
| 56 | + */ |
|
| 57 | + public function __get($endpoint) |
|
| 58 | + { |
|
| 59 | + $endpoint = $this->endpointsContainer->resolve($endpoint); |
|
| 60 | + |
|
| 61 | + if (method_exists($endpoint, 'setOrganizationId')) { |
|
| 62 | + $endpoint->setOrganizationId($this->organizationId); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $endpoint; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @param $organizationName |
|
| 70 | + * @return $this |
|
| 71 | + */ |
|
| 72 | + public function setOrganization($organizationName) |
|
| 73 | + { |
|
| 74 | + if($organization = $this->getOrganizationByName($organizationName)) { |
|
| 75 | + $this->setOrganizationId($organization['organizationId']); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return $this; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param int $organizationId |
|
| 83 | + * @return $this |
|
| 84 | + */ |
|
| 85 | + public function setOrganizationId($organizationId) |
|
| 86 | + { |
|
| 87 | + $this->organizationId = $organizationId; |
|
| 88 | + |
|
| 89 | + return $this; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public function getOrganizationId() |
|
| 96 | + { |
|
| 97 | + return $this->organizationId; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param string $name |
|
| 102 | + * @param array $arguments |
|
| 103 | + * @return mixed |
|
| 104 | + */ |
|
| 105 | + public function __call($name, $arguments) |
|
| 106 | + { |
|
| 107 | + return call_user_func([$this->endpointsContainer, $name], $arguments); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $organization |
|
| 112 | + * @return array|bool |
|
| 113 | + * @throws WrongOrganizationName |
|
| 114 | + */ |
|
| 115 | + protected function getOrganizationByName($organization) |
|
| 116 | + { |
|
| 117 | + $organizations = $this->organizations->getAll(); |
|
| 118 | + foreach ($organizations['entities'] as $entity) { |
|
| 119 | + if ($entity['name'] == $organization) { |
|
| 120 | + return $entity; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + throw new WrongOrganizationName("Organization $organization not found!"); |
|
| 125 | + } |
|
| 126 | 126 | } |
| 127 | 127 | \ No newline at end of file |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | class Users extends Endpoint |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $endpoint = 'users'; |
|
| 8 | + /** |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $endpoint = 'users'; |
|
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | class TaskLists extends CrudEndpoint |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $endpoint = 'tasklists'; |
|
| 8 | + /** |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $endpoint = 'tasklists'; |
|
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Collections extends CrudEndpoint |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var string |
|
| 9 | - */ |
|
| 10 | - protected $endpoint = 'collections'; |
|
| 7 | + /** |
|
| 8 | + * @var string |
|
| 9 | + */ |
|
| 10 | + protected $endpoint = 'collections'; |
|
| 11 | 11 | } |
| 12 | 12 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Tags extends CrudEndpoint |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var string |
|
| 9 | - */ |
|
| 10 | - protected $endpoint = 'tags'; |
|
| 7 | + /** |
|
| 8 | + * @var string |
|
| 9 | + */ |
|
| 10 | + protected $endpoint = 'tags'; |
|
| 11 | 11 | } |
| 12 | 12 | \ No newline at end of file |
@@ -4,33 +4,33 @@ |
||
| 4 | 4 | |
| 5 | 5 | class Cards extends CrudEndpoint |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @var string |
|
| 9 | - */ |
|
| 10 | - protected $endpoint = 'cards'; |
|
| 7 | + /** |
|
| 8 | + * @var string |
|
| 9 | + */ |
|
| 10 | + protected $endpoint = 'cards'; |
|
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * @param string $widgetCommonId |
|
| 14 | - * @return mixed |
|
| 15 | - */ |
|
| 16 | - public function getAll($widgetCommonId) |
|
| 17 | - { |
|
| 18 | - return parent::getAll(['widgetCommonId'=>$widgetCommonId]); |
|
| 19 | - } |
|
| 12 | + /** |
|
| 13 | + * @param string $widgetCommonId |
|
| 14 | + * @return mixed |
|
| 15 | + */ |
|
| 16 | + public function getAll($widgetCommonId) |
|
| 17 | + { |
|
| 18 | + return parent::getAll(['widgetCommonId'=>$widgetCommonId]); |
|
| 19 | + } |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param string $cardId |
|
| 23 | - * @param bool $everywhere |
|
| 24 | - * @return mixed |
|
| 25 | - */ |
|
| 26 | - public function delete($cardId, $everywhere) |
|
| 27 | - { |
|
| 28 | - return $this |
|
| 29 | - ->getHttp() |
|
| 30 | - ->delete( |
|
| 31 | - $this->makeRequestUrl($cardId), |
|
| 32 | - ['everywhere' => $everywhere], |
|
| 33 | - $this->getHeaders() |
|
| 34 | - ); |
|
| 35 | - } |
|
| 21 | + /** |
|
| 22 | + * @param string $cardId |
|
| 23 | + * @param bool $everywhere |
|
| 24 | + * @return mixed |
|
| 25 | + */ |
|
| 26 | + public function delete($cardId, $everywhere) |
|
| 27 | + { |
|
| 28 | + return $this |
|
| 29 | + ->getHttp() |
|
| 30 | + ->delete( |
|
| 31 | + $this->makeRequestUrl($cardId), |
|
| 32 | + ['everywhere' => $everywhere], |
|
| 33 | + $this->getHeaders() |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |
@@ -5,8 +5,8 @@ |
||
| 5 | 5 | class Comments extends CrudEndpoint |
| 6 | 6 | { |
| 7 | 7 | |
| 8 | - /** |
|
| 9 | - * @var string |
|
| 10 | - */ |
|
| 11 | - protected $endpoint = 'comments'; |
|
| 8 | + /** |
|
| 9 | + * @var string |
|
| 10 | + */ |
|
| 11 | + protected $endpoint = 'comments'; |
|
| 12 | 12 | } |
| 13 | 13 | \ No newline at end of file |