@@ -4,40 +4,40 @@ |
||
| 4 | 4 | |
| 5 | 5 | interface HttpInterface |
| 6 | 6 | { |
| 7 | - /** |
|
| 8 | - * @param $uri |
|
| 9 | - * @param array $params |
|
| 10 | - * @param array $headers |
|
| 11 | - * @return array |
|
| 12 | - */ |
|
| 13 | - public function get($uri, $params = [], $headers = []); |
|
| 7 | + /** |
|
| 8 | + * @param $uri |
|
| 9 | + * @param array $params |
|
| 10 | + * @param array $headers |
|
| 11 | + * @return array |
|
| 12 | + */ |
|
| 13 | + public function get($uri, $params = [], $headers = []); |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @param string $uri |
|
| 17 | - * @param array $body |
|
| 18 | - * @param array $headers |
|
| 19 | - * @return array |
|
| 20 | - */ |
|
| 21 | - public function post($uri, $body = [], $headers = []); |
|
| 15 | + /** |
|
| 16 | + * @param string $uri |
|
| 17 | + * @param array $body |
|
| 18 | + * @param array $headers |
|
| 19 | + * @return array |
|
| 20 | + */ |
|
| 21 | + public function post($uri, $body = [], $headers = []); |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param string $uri |
|
| 25 | - * @param array $body |
|
| 26 | - * @param array $headers |
|
| 27 | - * @return mixed |
|
| 28 | - */ |
|
| 29 | - public function put($uri, $body = [], $headers = []); |
|
| 23 | + /** |
|
| 24 | + * @param string $uri |
|
| 25 | + * @param array $body |
|
| 26 | + * @param array $headers |
|
| 27 | + * @return mixed |
|
| 28 | + */ |
|
| 29 | + public function put($uri, $body = [], $headers = []); |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param string $uri |
|
| 33 | - * @param array $headers |
|
| 34 | - * @return mixed |
|
| 35 | - */ |
|
| 36 | - public function delete($uri, $headers = []); |
|
| 31 | + /** |
|
| 32 | + * @param string $uri |
|
| 33 | + * @param array $headers |
|
| 34 | + * @return mixed |
|
| 35 | + */ |
|
| 36 | + public function delete($uri, $headers = []); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $url |
|
| 40 | - * @return $this |
|
| 41 | - */ |
|
| 42 | - public function setBaseUrl($url); |
|
| 38 | + /** |
|
| 39 | + * @param string $url |
|
| 40 | + * @return $this |
|
| 41 | + */ |
|
| 42 | + public function setBaseUrl($url); |
|
| 43 | 43 | } |
| 44 | 44 | \ No newline at end of file |
@@ -8,103 +8,103 @@ |
||
| 8 | 8 | |
| 9 | 9 | class GuzzleHttpAdapter implements HttpInterface |
| 10 | 10 | { |
| 11 | - /** |
|
| 12 | - * @var ClientInterface |
|
| 13 | - */ |
|
| 14 | - protected $client; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @param ClientInterface $client |
|
| 18 | - */ |
|
| 19 | - public function __construct(ClientInterface $client) |
|
| 20 | - { |
|
| 21 | - $this->client = $client; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @param string $uri |
|
| 26 | - * @param array $params |
|
| 27 | - * @param array $headers |
|
| 28 | - * @return string |
|
| 29 | - */ |
|
| 30 | - public function get($uri, $params = [], $headers = []) |
|
| 31 | - { |
|
| 32 | - if (!empty($params)) { |
|
| 33 | - $uri .= '?' . http_build_query($params); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $response = $this->client->get($uri, ['headers' => $headers]); |
|
| 37 | - |
|
| 38 | - return $this->parseResponse($response); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param string $uri |
|
| 43 | - * @param array $body |
|
| 44 | - * @param array $headers |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function post($uri, $body = [], $headers = []) |
|
| 48 | - { |
|
| 49 | - $response = $this->client->post( |
|
| 50 | - $uri, [ |
|
| 51 | - 'headers' => $headers, |
|
| 52 | - 'form_params' => $body, |
|
| 53 | - ] |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - return $this->parseResponse($response); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param string $uri |
|
| 61 | - * @param array $body |
|
| 62 | - * @param array $headers |
|
| 63 | - * @return mixed |
|
| 64 | - */ |
|
| 65 | - public function put($uri, $body = [], $headers = []) |
|
| 66 | - { |
|
| 67 | - $response = $this->client->put( |
|
| 68 | - $uri, [ |
|
| 69 | - 'headers' => $headers, |
|
| 70 | - 'form_params' => $body, |
|
| 71 | - ] |
|
| 72 | - ); |
|
| 73 | - |
|
| 74 | - return $this->parseResponse($response); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $uri |
|
| 79 | - * @param array $headers |
|
| 80 | - * @return mixed |
|
| 81 | - */ |
|
| 82 | - public function delete($uri, $headers = []) |
|
| 83 | - { |
|
| 84 | - $response = $this->client->delete($uri, ['headers' => $headers]); |
|
| 85 | - |
|
| 86 | - return $this->parseResponse($response); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param string $url |
|
| 91 | - * @return $this |
|
| 92 | - */ |
|
| 93 | - public function setBaseUrl($url) |
|
| 94 | - { |
|
| 95 | - $this->client->setBaseUrl($url); |
|
| 96 | - return $this; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param ResponseInterface $response |
|
| 101 | - * @return array|null |
|
| 102 | - */ |
|
| 103 | - protected function parseResponse(ResponseInterface $response) |
|
| 104 | - { |
|
| 105 | - $responseContents = $response->getBody()->getContents(); |
|
| 106 | - |
|
| 107 | - return json_decode($responseContents, true); |
|
| 108 | - } |
|
| 11 | + /** |
|
| 12 | + * @var ClientInterface |
|
| 13 | + */ |
|
| 14 | + protected $client; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param ClientInterface $client |
|
| 18 | + */ |
|
| 19 | + public function __construct(ClientInterface $client) |
|
| 20 | + { |
|
| 21 | + $this->client = $client; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @param string $uri |
|
| 26 | + * @param array $params |
|
| 27 | + * @param array $headers |
|
| 28 | + * @return string |
|
| 29 | + */ |
|
| 30 | + public function get($uri, $params = [], $headers = []) |
|
| 31 | + { |
|
| 32 | + if (!empty($params)) { |
|
| 33 | + $uri .= '?' . http_build_query($params); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $response = $this->client->get($uri, ['headers' => $headers]); |
|
| 37 | + |
|
| 38 | + return $this->parseResponse($response); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param string $uri |
|
| 43 | + * @param array $body |
|
| 44 | + * @param array $headers |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function post($uri, $body = [], $headers = []) |
|
| 48 | + { |
|
| 49 | + $response = $this->client->post( |
|
| 50 | + $uri, [ |
|
| 51 | + 'headers' => $headers, |
|
| 52 | + 'form_params' => $body, |
|
| 53 | + ] |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + return $this->parseResponse($response); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param string $uri |
|
| 61 | + * @param array $body |
|
| 62 | + * @param array $headers |
|
| 63 | + * @return mixed |
|
| 64 | + */ |
|
| 65 | + public function put($uri, $body = [], $headers = []) |
|
| 66 | + { |
|
| 67 | + $response = $this->client->put( |
|
| 68 | + $uri, [ |
|
| 69 | + 'headers' => $headers, |
|
| 70 | + 'form_params' => $body, |
|
| 71 | + ] |
|
| 72 | + ); |
|
| 73 | + |
|
| 74 | + return $this->parseResponse($response); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $uri |
|
| 79 | + * @param array $headers |
|
| 80 | + * @return mixed |
|
| 81 | + */ |
|
| 82 | + public function delete($uri, $headers = []) |
|
| 83 | + { |
|
| 84 | + $response = $this->client->delete($uri, ['headers' => $headers]); |
|
| 85 | + |
|
| 86 | + return $this->parseResponse($response); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param string $url |
|
| 91 | + * @return $this |
|
| 92 | + */ |
|
| 93 | + public function setBaseUrl($url) |
|
| 94 | + { |
|
| 95 | + $this->client->setBaseUrl($url); |
|
| 96 | + return $this; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param ResponseInterface $response |
|
| 101 | + * @return array|null |
|
| 102 | + */ |
|
| 103 | + protected function parseResponse(ResponseInterface $response) |
|
| 104 | + { |
|
| 105 | + $responseContents = $response->getBody()->getContents(); |
|
| 106 | + |
|
| 107 | + return json_decode($responseContents, true); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |
@@ -9,36 +9,36 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Favro |
| 11 | 11 | { |
| 12 | - /** |
|
| 13 | - * @param string $login |
|
| 14 | - * @param string $password |
|
| 15 | - * @return Api |
|
| 16 | - */ |
|
| 17 | - public static function create($login, $password) |
|
| 18 | - { |
|
| 19 | - $endpointsContainer = new EndpointsContainer( |
|
| 20 | - self::getHttpInterfaceAdapter($login, $password) |
|
| 21 | - ); |
|
| 22 | - return new Api($endpointsContainer); |
|
| 23 | - } |
|
| 12 | + /** |
|
| 13 | + * @param string $login |
|
| 14 | + * @param string $password |
|
| 15 | + * @return Api |
|
| 16 | + */ |
|
| 17 | + public static function create($login, $password) |
|
| 18 | + { |
|
| 19 | + $endpointsContainer = new EndpointsContainer( |
|
| 20 | + self::getHttpInterfaceAdapter($login, $password) |
|
| 21 | + ); |
|
| 22 | + return new Api($endpointsContainer); |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @param string $login |
|
| 27 | - * @param string $password |
|
| 28 | - * @return GuzzleHttpAdapter |
|
| 29 | - */ |
|
| 30 | - protected static function getHttpInterfaceAdapter($login, $password) |
|
| 31 | - { |
|
| 32 | - return new GuzzleHttpAdapter( |
|
| 33 | - new Client(['auth' => [$login, $password]]) |
|
| 34 | - ); |
|
| 35 | - } |
|
| 25 | + /** |
|
| 26 | + * @param string $login |
|
| 27 | + * @param string $password |
|
| 28 | + * @return GuzzleHttpAdapter |
|
| 29 | + */ |
|
| 30 | + protected static function getHttpInterfaceAdapter($login, $password) |
|
| 31 | + { |
|
| 32 | + return new GuzzleHttpAdapter( |
|
| 33 | + new Client(['auth' => [$login, $password]]) |
|
| 34 | + ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - private function __construct() |
|
| 38 | - { |
|
| 39 | - } |
|
| 37 | + private function __construct() |
|
| 38 | + { |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - private function __clone() |
|
| 42 | - { |
|
| 43 | - } |
|
| 41 | + private function __clone() |
|
| 42 | + { |
|
| 43 | + } |
|
| 44 | 44 | } |
| 45 | 45 | \ No newline at end of file |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | |
| 7 | 7 | class Users extends Endpoint |
| 8 | 8 | { |
| 9 | - use BelongsToOrganization; |
|
| 9 | + use BelongsToOrganization; |
|
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * @var string |
|
| 13 | - */ |
|
| 14 | - protected $endpoint = 'users'; |
|
| 11 | + /** |
|
| 12 | + * @var string |
|
| 13 | + */ |
|
| 14 | + protected $endpoint = 'users'; |
|
| 15 | 15 | } |
| 16 | 16 | \ No newline at end of file |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | class Columns extends Endpoint |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - use BelongsToOrganization, BelongsToWidget, CrudEndpoint; |
|
| 12 | + use BelongsToOrganization, BelongsToWidget, CrudEndpoint; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $endpoint = 'columns'; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $endpoint = 'columns'; |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | class TaskLists extends Endpoint |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - use CrudEndpoint, BelongsToOrganization, BelongsToCard; |
|
| 12 | + use CrudEndpoint, BelongsToOrganization, BelongsToCard; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $endpoint = 'tasklists'; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $endpoint = 'tasklists'; |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -8,63 +8,63 @@ |
||
| 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 $http; |
|
| 16 | + protected $http; |
|
| 17 | 17 | |
| 18 | - /* |
|
| 18 | + /* |
|
| 19 | 19 | * @var array |
| 20 | 20 | */ |
| 21 | - protected $endpoints = []; |
|
| 21 | + protected $endpoints = []; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param HttpInterface $http |
|
| 25 | - */ |
|
| 26 | - public function __construct(HttpInterface $http) |
|
| 27 | - { |
|
| 28 | - $this->http = $http; |
|
| 29 | - } |
|
| 23 | + /** |
|
| 24 | + * @param HttpInterface $http |
|
| 25 | + */ |
|
| 26 | + public function __construct(HttpInterface $http) |
|
| 27 | + { |
|
| 28 | + $this->http = $http; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param string $endpoint |
|
| 33 | - * @return Endpoint |
|
| 34 | - */ |
|
| 35 | - public function resolveEndpoint($endpoint) |
|
| 36 | - { |
|
| 37 | - $endpoint = strtolower($endpoint); |
|
| 31 | + /** |
|
| 32 | + * @param string $endpoint |
|
| 33 | + * @return Endpoint |
|
| 34 | + */ |
|
| 35 | + public function resolveEndpoint($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 BadEndpointException |
|
| 50 | - */ |
|
| 51 | - protected function addProvider($endpoint) |
|
| 52 | - { |
|
| 53 | - $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint); |
|
| 47 | + /** |
|
| 48 | + * @param $endpoint |
|
| 49 | + * @throws BadEndpointException |
|
| 50 | + */ |
|
| 51 | + protected function addProvider($endpoint) |
|
| 52 | + { |
|
| 53 | + $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint); |
|
| 54 | 54 | |
| 55 | - if (!class_exists($className)) { |
|
| 56 | - throw new BadEndpointException("Endpoint $className not found."); |
|
| 57 | - } |
|
| 55 | + if (!class_exists($className)) { |
|
| 56 | + throw new BadEndpointException("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->http]); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * @param string $className |
|
| 64 | + * @return Endpoint|object |
|
| 65 | + */ |
|
| 66 | + protected function buildEndpoint($className) |
|
| 67 | + { |
|
| 68 | + return (new ReflectionClass($className))->newInstanceArgs([$this->http]); |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | \ No newline at end of file |
@@ -9,10 +9,10 @@ |
||
| 9 | 9 | class Cards extends Endpoint |
| 10 | 10 | { |
| 11 | 11 | |
| 12 | - use BelongsToOrganization, BelongsToWidget, CrudEndpoint; |
|
| 12 | + use BelongsToOrganization, BelongsToWidget, CrudEndpoint; |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $endpoint = 'cards'; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $endpoint = 'cards'; |
|
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -8,10 +8,10 @@ |
||
| 8 | 8 | class Tags extends Endpoint |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - use CrudEndpoint, BelongsToOrganization; |
|
| 11 | + use CrudEndpoint, BelongsToOrganization; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var string |
|
| 15 | - */ |
|
| 16 | - protected $endpoint = 'tags'; |
|
| 13 | + /** |
|
| 14 | + * @var string |
|
| 15 | + */ |
|
| 16 | + protected $endpoint = 'tags'; |
|
| 17 | 17 | } |
| 18 | 18 | \ No newline at end of file |