| @@ -4,46 +4,46 @@ | ||
| 4 | 4 | |
| 5 | 5 | interface HttpClient | 
| 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 $body | |
| 34 | - * @param array $headers | |
| 35 | - * @return mixed | |
| 36 | - */ | |
| 37 | - public function delete($uri, $body = [], $headers = []); | |
| 31 | + /** | |
| 32 | + * @param string $uri | |
| 33 | + * @param array $body | |
| 34 | + * @param array $headers | |
| 35 | + * @return mixed | |
| 36 | + */ | |
| 37 | + public function delete($uri, $body = [], $headers = []); | |
| 38 | 38 | |
| 39 | - /** | |
| 40 | - * @param string $url | |
| 41 | - * @return $this | |
| 42 | - */ | |
| 43 | - public function setBaseUrl($url); | |
| 39 | + /** | |
| 40 | + * @param string $url | |
| 41 | + * @return $this | |
| 42 | + */ | |
| 43 | + public function setBaseUrl($url); | |
| 44 | 44 | |
| 45 | - /** | |
| 46 | - * @return array | |
| 47 | - */ | |
| 48 | - public function getResponseHeaders(); | |
| 45 | + /** | |
| 46 | + * @return array | |
| 47 | + */ | |
| 48 | + public function getResponseHeaders(); | |
| 49 | 49 | } | 
| 50 | 50 | \ No newline at end of file | 
| @@ -8,130 +8,130 @@ | ||
| 8 | 8 | |
| 9 | 9 | class GuzzleHttpClient implements HttpClient | 
| 10 | 10 |  { | 
| 11 | - /** | |
| 12 | - * @var ClientInterface | |
| 13 | - */ | |
| 14 | - protected $client; | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * @var array | |
| 18 | - */ | |
| 19 | - protected $responseHeaders; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @param ClientInterface $client | |
| 23 | - */ | |
| 24 | - public function __construct(ClientInterface $client) | |
| 25 | -    { | |
| 26 | - $this->client = $client; | |
| 27 | - } | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * @param string $uri | |
| 31 | - * @param array $params | |
| 32 | - * @param array $headers | |
| 33 | - * @return string | |
| 34 | - */ | |
| 35 | - public function get($uri, $params = [], $headers = []) | |
| 36 | -    { | |
| 37 | -        if (!empty($params)) { | |
| 38 | - $uri .= '?' . http_build_query($params); | |
| 39 | - } | |
| 40 | - | |
| 41 | - $response = $this | |
| 42 | - ->client | |
| 43 | - ->get($uri, ['headers' => $headers]); | |
| 44 | - | |
| 45 | - return $this->parseResponse($response); | |
| 46 | - } | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * @param string $uri | |
| 50 | - * @param array $body | |
| 51 | - * @param array $headers | |
| 52 | - * @return string | |
| 53 | - */ | |
| 54 | - public function post($uri, $body = [], $headers = []) | |
| 55 | -    { | |
| 56 | - $response = $this | |
| 57 | - ->client | |
| 58 | - ->post( | |
| 59 | - $uri, [ | |
| 60 | - 'headers' => $headers, | |
| 61 | - 'form_params' => $body, | |
| 62 | - ] | |
| 63 | - ); | |
| 64 | - | |
| 65 | - return $this->parseResponse($response); | |
| 66 | - } | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * @param string $uri | |
| 70 | - * @param array $body | |
| 71 | - * @param array $headers | |
| 72 | - * @return mixed | |
| 73 | - */ | |
| 74 | - public function put($uri, $body = [], $headers = []) | |
| 75 | -    { | |
| 76 | - $response = $this | |
| 77 | - ->client | |
| 78 | - ->put( | |
| 79 | - $uri, [ | |
| 80 | - 'headers' => $headers, | |
| 81 | - 'form_params' => $body, | |
| 82 | - ] | |
| 83 | - ); | |
| 84 | - | |
| 85 | - return $this->parseResponse($response); | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * @param string $uri | |
| 90 | - * @param array $body | |
| 91 | - * @param array $headers | |
| 92 | - * @return mixed | |
| 93 | - */ | |
| 94 | - public function delete($uri, $body = [], $headers = []) | |
| 95 | -    { | |
| 96 | - $response = $this | |
| 97 | - ->client | |
| 98 | - ->delete($uri, [ | |
| 99 | - 'headers' => $headers, | |
| 100 | - 'form_params' => $body, | |
| 101 | - ]); | |
| 102 | - | |
| 103 | - return $this->parseResponse($response); | |
| 104 | - } | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * @param string $url | |
| 108 | - * @return $this | |
| 109 | - */ | |
| 110 | - public function setBaseUrl($url) | |
| 111 | -    { | |
| 112 | - $this->client->setBaseUrl($url); | |
| 113 | - | |
| 114 | - return $this; | |
| 115 | - } | |
| 116 | - | |
| 117 | - /** | |
| 118 | - * @param ResponseInterface $response | |
| 119 | - * @return array|null | |
| 120 | - */ | |
| 121 | - protected function parseResponse(ResponseInterface $response) | |
| 122 | -    { | |
| 123 | - $responseContents = $response->getBody()->getContents(); | |
| 124 | - | |
| 125 | - $this->responseHeaders = $response->getHeaders(); | |
| 126 | - | |
| 127 | - return json_decode($responseContents, true); | |
| 128 | - } | |
| 129 | - | |
| 130 | - /** | |
| 131 | - * @return array | |
| 132 | - */ | |
| 133 | - public function getResponseHeaders() | |
| 134 | -    { | |
| 135 | - return $this->responseHeaders; | |
| 136 | - } | |
| 11 | + /** | |
| 12 | + * @var ClientInterface | |
| 13 | + */ | |
| 14 | + protected $client; | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * @var array | |
| 18 | + */ | |
| 19 | + protected $responseHeaders; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @param ClientInterface $client | |
| 23 | + */ | |
| 24 | + public function __construct(ClientInterface $client) | |
| 25 | +	{ | |
| 26 | + $this->client = $client; | |
| 27 | + } | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * @param string $uri | |
| 31 | + * @param array $params | |
| 32 | + * @param array $headers | |
| 33 | + * @return string | |
| 34 | + */ | |
| 35 | + public function get($uri, $params = [], $headers = []) | |
| 36 | +	{ | |
| 37 | +		if (!empty($params)) { | |
| 38 | + $uri .= '?' . http_build_query($params); | |
| 39 | + } | |
| 40 | + | |
| 41 | + $response = $this | |
| 42 | + ->client | |
| 43 | + ->get($uri, ['headers' => $headers]); | |
| 44 | + | |
| 45 | + return $this->parseResponse($response); | |
| 46 | + } | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * @param string $uri | |
| 50 | + * @param array $body | |
| 51 | + * @param array $headers | |
| 52 | + * @return string | |
| 53 | + */ | |
| 54 | + public function post($uri, $body = [], $headers = []) | |
| 55 | +	{ | |
| 56 | + $response = $this | |
| 57 | + ->client | |
| 58 | + ->post( | |
| 59 | + $uri, [ | |
| 60 | + 'headers' => $headers, | |
| 61 | + 'form_params' => $body, | |
| 62 | + ] | |
| 63 | + ); | |
| 64 | + | |
| 65 | + return $this->parseResponse($response); | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * @param string $uri | |
| 70 | + * @param array $body | |
| 71 | + * @param array $headers | |
| 72 | + * @return mixed | |
| 73 | + */ | |
| 74 | + public function put($uri, $body = [], $headers = []) | |
| 75 | +	{ | |
| 76 | + $response = $this | |
| 77 | + ->client | |
| 78 | + ->put( | |
| 79 | + $uri, [ | |
| 80 | + 'headers' => $headers, | |
| 81 | + 'form_params' => $body, | |
| 82 | + ] | |
| 83 | + ); | |
| 84 | + | |
| 85 | + return $this->parseResponse($response); | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * @param string $uri | |
| 90 | + * @param array $body | |
| 91 | + * @param array $headers | |
| 92 | + * @return mixed | |
| 93 | + */ | |
| 94 | + public function delete($uri, $body = [], $headers = []) | |
| 95 | +	{ | |
| 96 | + $response = $this | |
| 97 | + ->client | |
| 98 | + ->delete($uri, [ | |
| 99 | + 'headers' => $headers, | |
| 100 | + 'form_params' => $body, | |
| 101 | + ]); | |
| 102 | + | |
| 103 | + return $this->parseResponse($response); | |
| 104 | + } | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @param string $url | |
| 108 | + * @return $this | |
| 109 | + */ | |
| 110 | + public function setBaseUrl($url) | |
| 111 | +	{ | |
| 112 | + $this->client->setBaseUrl($url); | |
| 113 | + | |
| 114 | + return $this; | |
| 115 | + } | |
| 116 | + | |
| 117 | + /** | |
| 118 | + * @param ResponseInterface $response | |
| 119 | + * @return array|null | |
| 120 | + */ | |
| 121 | + protected function parseResponse(ResponseInterface $response) | |
| 122 | +	{ | |
| 123 | + $responseContents = $response->getBody()->getContents(); | |
| 124 | + | |
| 125 | + $this->responseHeaders = $response->getHeaders(); | |
| 126 | + | |
| 127 | + return json_decode($responseContents, true); | |
| 128 | + } | |
| 129 | + | |
| 130 | + /** | |
| 131 | + * @return array | |
| 132 | + */ | |
| 133 | + public function getResponseHeaders() | |
| 134 | +	{ | |
| 135 | + return $this->responseHeaders; | |
| 136 | + } | |
| 137 | 137 | } | 
| 138 | 138 | \ No newline at end of file | 
| @@ -107,7 +107,7 @@ | ||
| 107 | 107 | } | 
| 108 | 108 | |
| 109 | 109 | /** | 
| 110 | - * @param $organizationName | |
| 110 | + * @param string $organizationName | |
| 111 | 111 | * @return array|bool | 
| 112 | 112 | * @throws WrongOrganizationName | 
| 113 | 113 | */ | 
| @@ -31,125 +31,125 @@ | ||
| 31 | 31 | */ | 
| 32 | 32 | class Api | 
| 33 | 33 |  { | 
| 34 | - /** | |
| 35 | - * @var string | |
| 36 | - */ | |
| 37 | - private $organizationId; | |
| 38 | - | |
| 39 | - /** | |
| 40 | - * @var HttpClient | |
| 41 | - */ | |
| 42 | - private $httpClient; | |
| 43 | - | |
| 44 | - /** | |
| 45 | - * @var Endpoint[] | |
| 46 | - */ | |
| 47 | - private $endpoints; | |
| 48 | - | |
| 49 | - public function __construct(HttpClient $httpClient, Endpoint ...$endpoints) | |
| 50 | -    { | |
| 51 | - $this->httpClient = $httpClient; | |
| 52 | -        foreach ($endpoints as $endpoint) { | |
| 53 | - $this->endpoints[$endpoint->endpoint()] = $endpoint; | |
| 54 | - } | |
| 55 | - } | |
| 56 | - | |
| 57 | - /** | |
| 58 | - * Magic method to access different endpoints. | |
| 59 | - * | |
| 60 | - * @param string $endpoint | |
| 61 | - * | |
| 62 | - * @return Endpoint | |
| 63 | - * @throws WrongEndpoint | |
| 64 | - */ | |
| 65 | - public function __get($endpoint) | |
| 66 | -    { | |
| 67 | - $endpoint = $this->resolveEndpoint($endpoint); | |
| 68 | - | |
| 69 | -        if (method_exists($endpoint, 'setOrganizationId')) { | |
| 70 | - $endpoint->setOrganizationId($this->organizationId); | |
| 71 | - } | |
| 72 | - | |
| 73 | - return $endpoint; | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @param string $organizationName | |
| 78 | - * @return $this | |
| 79 | - * @throws WrongOrganizationName | |
| 80 | - */ | |
| 81 | - public function setOrganization($organizationName) | |
| 82 | -    { | |
| 83 | -        if($organization = $this->getOrganizationByName($organizationName)) { | |
| 84 | - $this->setOrganizationId($organization['organizationId']); | |
| 85 | - } | |
| 86 | - | |
| 87 | - return $this; | |
| 88 | - } | |
| 89 | - | |
| 90 | - /** | |
| 91 | - * @param int $organizationId | |
| 92 | - * @return $this | |
| 93 | - */ | |
| 94 | - public function setOrganizationId($organizationId) | |
| 95 | -    { | |
| 96 | - $this->organizationId = $organizationId; | |
| 97 | - | |
| 98 | - return $this; | |
| 99 | - } | |
| 100 | - | |
| 101 | - /** | |
| 102 | - * @return string | |
| 103 | - */ | |
| 104 | - public function getOrganizationId() | |
| 105 | -    { | |
| 106 | - return $this->organizationId; | |
| 107 | - } | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * @param $organizationName | |
| 111 | - * @return array|bool | |
| 112 | - * @throws WrongOrganizationName | |
| 113 | - */ | |
| 114 | - private function getOrganizationByName($organizationName) | |
| 115 | -    { | |
| 116 | - $organizations = $this->organizations->getAll(); | |
| 117 | -        foreach ($organizations['entities'] as $entity) { | |
| 118 | -            if ($entity['name'] == $organizationName) { | |
| 119 | - return $entity; | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | -        throw new WrongOrganizationName("Organization $organizationName not found!"); | |
| 124 | - } | |
| 125 | - | |
| 126 | - /** | |
| 127 | - * @param string $endpoint | |
| 128 | - * @return Endpoint | |
| 129 | - * @throws WrongEndpoint | |
| 130 | - */ | |
| 131 | - private function resolveEndpoint($endpoint) | |
| 132 | -    { | |
| 133 | - $endpoint = strtolower($endpoint); | |
| 134 | - | |
| 135 | -        if(isset($this->endpoints[$endpoint])) { | |
| 136 | - return $this->endpoints[$endpoint]; | |
| 137 | - } | |
| 138 | - | |
| 139 | -        throw new WrongEndpoint("There is no endpoint called $endpoint."); | |
| 140 | - } | |
| 141 | - | |
| 142 | - /** | |
| 143 | - * @return array | |
| 144 | - */ | |
| 145 | - public function getRateInfo() | |
| 146 | -    { | |
| 147 | - $responseHeaders = $this->httpClient->getResponseHeaders(); | |
| 148 | - | |
| 149 | - return [ | |
| 150 | - 'reset' => $responseHeaders['X-RateLimit-Reset'][0], | |
| 151 | - 'limit' => $responseHeaders['X-RateLimit-Limit'][0], | |
| 152 | - 'remaining' => $responseHeaders['X-RateLimit-Remaining'][0], | |
| 153 | - ]; | |
| 154 | - } | |
| 34 | + /** | |
| 35 | + * @var string | |
| 36 | + */ | |
| 37 | + private $organizationId; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * @var HttpClient | |
| 41 | + */ | |
| 42 | + private $httpClient; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * @var Endpoint[] | |
| 46 | + */ | |
| 47 | + private $endpoints; | |
| 48 | + | |
| 49 | + public function __construct(HttpClient $httpClient, Endpoint ...$endpoints) | |
| 50 | +	{ | |
| 51 | + $this->httpClient = $httpClient; | |
| 52 | +		foreach ($endpoints as $endpoint) { | |
| 53 | + $this->endpoints[$endpoint->endpoint()] = $endpoint; | |
| 54 | + } | |
| 55 | + } | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * Magic method to access different endpoints. | |
| 59 | + * | |
| 60 | + * @param string $endpoint | |
| 61 | + * | |
| 62 | + * @return Endpoint | |
| 63 | + * @throws WrongEndpoint | |
| 64 | + */ | |
| 65 | + public function __get($endpoint) | |
| 66 | +	{ | |
| 67 | + $endpoint = $this->resolveEndpoint($endpoint); | |
| 68 | + | |
| 69 | +		if (method_exists($endpoint, 'setOrganizationId')) { | |
| 70 | + $endpoint->setOrganizationId($this->organizationId); | |
| 71 | + } | |
| 72 | + | |
| 73 | + return $endpoint; | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @param string $organizationName | |
| 78 | + * @return $this | |
| 79 | + * @throws WrongOrganizationName | |
| 80 | + */ | |
| 81 | + public function setOrganization($organizationName) | |
| 82 | +	{ | |
| 83 | +		if($organization = $this->getOrganizationByName($organizationName)) { | |
| 84 | + $this->setOrganizationId($organization['organizationId']); | |
| 85 | + } | |
| 86 | + | |
| 87 | + return $this; | |
| 88 | + } | |
| 89 | + | |
| 90 | + /** | |
| 91 | + * @param int $organizationId | |
| 92 | + * @return $this | |
| 93 | + */ | |
| 94 | + public function setOrganizationId($organizationId) | |
| 95 | +	{ | |
| 96 | + $this->organizationId = $organizationId; | |
| 97 | + | |
| 98 | + return $this; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * @return string | |
| 103 | + */ | |
| 104 | + public function getOrganizationId() | |
| 105 | +	{ | |
| 106 | + return $this->organizationId; | |
| 107 | + } | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * @param $organizationName | |
| 111 | + * @return array|bool | |
| 112 | + * @throws WrongOrganizationName | |
| 113 | + */ | |
| 114 | + private function getOrganizationByName($organizationName) | |
| 115 | +	{ | |
| 116 | + $organizations = $this->organizations->getAll(); | |
| 117 | +		foreach ($organizations['entities'] as $entity) { | |
| 118 | +			if ($entity['name'] == $organizationName) { | |
| 119 | + return $entity; | |
| 120 | + } | |
| 121 | + } | |
| 122 | + | |
| 123 | +		throw new WrongOrganizationName("Organization $organizationName not found!"); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * @param string $endpoint | |
| 128 | + * @return Endpoint | |
| 129 | + * @throws WrongEndpoint | |
| 130 | + */ | |
| 131 | + private function resolveEndpoint($endpoint) | |
| 132 | +	{ | |
| 133 | + $endpoint = strtolower($endpoint); | |
| 134 | + | |
| 135 | +		if(isset($this->endpoints[$endpoint])) { | |
| 136 | + return $this->endpoints[$endpoint]; | |
| 137 | + } | |
| 138 | + | |
| 139 | +		throw new WrongEndpoint("There is no endpoint called $endpoint."); | |
| 140 | + } | |
| 141 | + | |
| 142 | + /** | |
| 143 | + * @return array | |
| 144 | + */ | |
| 145 | + public function getRateInfo() | |
| 146 | +	{ | |
| 147 | + $responseHeaders = $this->httpClient->getResponseHeaders(); | |
| 148 | + | |
| 149 | + return [ | |
| 150 | + 'reset' => $responseHeaders['X-RateLimit-Reset'][0], | |
| 151 | + 'limit' => $responseHeaders['X-RateLimit-Limit'][0], | |
| 152 | + 'remaining' => $responseHeaders['X-RateLimit-Remaining'][0], | |
| 153 | + ]; | |
| 154 | + } | |
| 155 | 155 | } | 
| @@ -80,7 +80,7 @@ discard block | ||
| 80 | 80 | */ | 
| 81 | 81 | public function setOrganization($organizationName) | 
| 82 | 82 |      { | 
| 83 | -        if($organization = $this->getOrganizationByName($organizationName)) { | |
| 83 | +        if ($organization = $this->getOrganizationByName($organizationName)) { | |
| 84 | 84 | $this->setOrganizationId($organization['organizationId']); | 
| 85 | 85 | } | 
| 86 | 86 | |
| @@ -132,7 +132,7 @@ discard block | ||
| 132 | 132 |      { | 
| 133 | 133 | $endpoint = strtolower($endpoint); | 
| 134 | 134 | |
| 135 | -        if(isset($this->endpoints[$endpoint])) { | |
| 135 | +        if (isset($this->endpoints[$endpoint])) { | |
| 136 | 136 | return $this->endpoints[$endpoint]; | 
| 137 | 137 | } | 
| 138 | 138 | |
| @@ -6,105 +6,105 @@ | ||
| 6 | 6 | |
| 7 | 7 | abstract class Endpoint | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * @var array | |
| 11 | - */ | |
| 12 | - protected $rateLimitInfo; | |
| 9 | + /** | |
| 10 | + * @var array | |
| 11 | + */ | |
| 12 | + protected $rateLimitInfo; | |
| 13 | 13 | |
| 14 | - /** | |
| 15 | - * @var array | |
| 16 | - */ | |
| 17 | - protected $headers = []; | |
| 14 | + /** | |
| 15 | + * @var array | |
| 16 | + */ | |
| 17 | + protected $headers = []; | |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * @var HttpClient | |
| 21 | - */ | |
| 22 | - protected $http; | |
| 19 | + /** | |
| 20 | + * @var HttpClient | |
| 21 | + */ | |
| 22 | + protected $http; | |
| 23 | 23 | |
| 24 | - /** | |
| 25 | - * @var string | |
| 26 | - */ | |
| 27 | - protected $organizationId; | |
| 24 | + /** | |
| 25 | + * @var string | |
| 26 | + */ | |
| 27 | + protected $organizationId; | |
| 28 | 28 | |
| 29 | - /** | |
| 30 | - * @param HttpClient $http | |
| 31 | - */ | |
| 32 | - public function __construct(HttpClient $http) | |
| 33 | -    { | |
| 34 | - $this->http = $http; | |
| 35 | - } | |
| 29 | + /** | |
| 30 | + * @param HttpClient $http | |
| 31 | + */ | |
| 32 | + public function __construct(HttpClient $http) | |
| 33 | +	{ | |
| 34 | + $this->http = $http; | |
| 35 | + } | |
| 36 | 36 | |
| 37 | - /** | |
| 38 | - * @param string $verb | |
| 39 | - * @return string | |
| 40 | - */ | |
| 41 | - public function makeRequestUrl($verb = '') | |
| 42 | -    { | |
| 43 | -        return "https://favro.com/api/v1/{$this->endpoint()}/$verb"; | |
| 44 | - } | |
| 37 | + /** | |
| 38 | + * @param string $verb | |
| 39 | + * @return string | |
| 40 | + */ | |
| 41 | + public function makeRequestUrl($verb = '') | |
| 42 | +	{ | |
| 43 | +		return "https://favro.com/api/v1/{$this->endpoint()}/$verb"; | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * @return HttpClient | |
| 48 | - */ | |
| 49 | - public function getHttp() | |
| 50 | -    { | |
| 51 | - return $this->http; | |
| 52 | - } | |
| 46 | + /** | |
| 47 | + * @return HttpClient | |
| 48 | + */ | |
| 49 | + public function getHttp() | |
| 50 | +	{ | |
| 51 | + return $this->http; | |
| 52 | + } | |
| 53 | 53 | |
| 54 | - /** | |
| 55 | - * @param array $params | |
| 56 | - * @return array | |
| 57 | - */ | |
| 58 | - public function getAll(array $params = []) | |
| 59 | -    { | |
| 60 | - return $this | |
| 61 | - ->getHttp() | |
| 62 | - ->get( | |
| 63 | - $this->makeRequestUrl(), | |
| 64 | - $params, | |
| 65 | - $this->getHeaders() | |
| 66 | - ); | |
| 67 | - } | |
| 54 | + /** | |
| 55 | + * @param array $params | |
| 56 | + * @return array | |
| 57 | + */ | |
| 58 | + public function getAll(array $params = []) | |
| 59 | +	{ | |
| 60 | + return $this | |
| 61 | + ->getHttp() | |
| 62 | + ->get( | |
| 63 | + $this->makeRequestUrl(), | |
| 64 | + $params, | |
| 65 | + $this->getHeaders() | |
| 66 | + ); | |
| 67 | + } | |
| 68 | 68 | |
| 69 | - /** | |
| 70 | - * @param string $id | |
| 71 | - * @return array | |
| 72 | - */ | |
| 73 | - public function getById($id) | |
| 74 | -    { | |
| 75 | - return $this | |
| 76 | - ->getHttp() | |
| 77 | - ->get( | |
| 78 | - $this->makeRequestUrl($id), | |
| 79 | - [], | |
| 80 | - $this->getHeaders() | |
| 81 | - ); | |
| 82 | - } | |
| 69 | + /** | |
| 70 | + * @param string $id | |
| 71 | + * @return array | |
| 72 | + */ | |
| 73 | + public function getById($id) | |
| 74 | +	{ | |
| 75 | + return $this | |
| 76 | + ->getHttp() | |
| 77 | + ->get( | |
| 78 | + $this->makeRequestUrl($id), | |
| 79 | + [], | |
| 80 | + $this->getHeaders() | |
| 81 | + ); | |
| 82 | + } | |
| 83 | 83 | |
| 84 | - /** | |
| 85 | - * @return array | |
| 86 | - */ | |
| 87 | - public function getHeaders() | |
| 88 | -    { | |
| 89 | - return array_merge( | |
| 90 | - ['organizationId' => $this->organizationId], | |
| 91 | - $this->headers | |
| 92 | - ); | |
| 93 | - } | |
| 84 | + /** | |
| 85 | + * @return array | |
| 86 | + */ | |
| 87 | + public function getHeaders() | |
| 88 | +	{ | |
| 89 | + return array_merge( | |
| 90 | + ['organizationId' => $this->organizationId], | |
| 91 | + $this->headers | |
| 92 | + ); | |
| 93 | + } | |
| 94 | 94 | |
| 95 | - /** | |
| 96 | - * @param string $organizationId | |
| 97 | - * @return $this | |
| 98 | - */ | |
| 99 | - public function setOrganizationId($organizationId) | |
| 100 | -    { | |
| 101 | - $this->organizationId = $organizationId; | |
| 95 | + /** | |
| 96 | + * @param string $organizationId | |
| 97 | + * @return $this | |
| 98 | + */ | |
| 99 | + public function setOrganizationId($organizationId) | |
| 100 | +	{ | |
| 101 | + $this->organizationId = $organizationId; | |
| 102 | 102 | |
| 103 | - return $this; | |
| 104 | - } | |
| 103 | + return $this; | |
| 104 | + } | |
| 105 | 105 | |
| 106 | - /** | |
| 107 | - * @return string | |
| 108 | - */ | |
| 109 | - abstract public function endpoint(); | |
| 106 | + /** | |
| 107 | + * @return string | |
| 108 | + */ | |
| 109 | + abstract public function endpoint(); | |
| 110 | 110 | } | 
| @@ -4,52 +4,52 @@ | ||
| 4 | 4 | |
| 5 | 5 | abstract class CrudEndpoint extends Endpoint | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @param array $attributes | |
| 9 | - * @return array | |
| 10 | - */ | |
| 11 | - public function create(array $attributes) | |
| 12 | -    { | |
| 13 | - return $this | |
| 14 | - ->getHttp() | |
| 15 | - ->post( | |
| 16 | - $this->makeRequestUrl(), | |
| 17 | - $attributes, | |
| 18 | - $this->getHeaders() | |
| 19 | - ); | |
| 20 | - } | |
| 7 | + /** | |
| 8 | + * @param array $attributes | |
| 9 | + * @return array | |
| 10 | + */ | |
| 11 | + public function create(array $attributes) | |
| 12 | +	{ | |
| 13 | + return $this | |
| 14 | + ->getHttp() | |
| 15 | + ->post( | |
| 16 | + $this->makeRequestUrl(), | |
| 17 | + $attributes, | |
| 18 | + $this->getHeaders() | |
| 19 | + ); | |
| 20 | + } | |
| 21 | 21 | |
| 22 | - /** | |
| 23 | - * @param string $itemId | |
| 24 | - * @param array $attributes | |
| 25 | - * @return mixed | |
| 26 | - */ | |
| 27 | - public function update($itemId, array $attributes) | |
| 28 | -    { | |
| 29 | - return $this | |
| 30 | - ->getHttp() | |
| 31 | - ->put( | |
| 32 | - $this->makeRequestUrl($itemId), | |
| 33 | - $attributes, | |
| 34 | - $this->getHeaders() | |
| 35 | - ); | |
| 36 | - } | |
| 22 | + /** | |
| 23 | + * @param string $itemId | |
| 24 | + * @param array $attributes | |
| 25 | + * @return mixed | |
| 26 | + */ | |
| 27 | + public function update($itemId, array $attributes) | |
| 28 | +	{ | |
| 29 | + return $this | |
| 30 | + ->getHttp() | |
| 31 | + ->put( | |
| 32 | + $this->makeRequestUrl($itemId), | |
| 33 | + $attributes, | |
| 34 | + $this->getHeaders() | |
| 35 | + ); | |
| 36 | + } | |
| 37 | 37 | |
| 38 | - /** | |
| 39 | - * @param string $itemId | |
| 40 | - * @param bool $everywhere | |
| 41 | - * @return mixed | |
| 42 | - */ | |
| 43 | - public function delete($itemId, $everywhere = false) | |
| 44 | -    { | |
| 45 | - $params = $everywhere ? ['everywhere' => $everywhere] : []; | |
| 38 | + /** | |
| 39 | + * @param string $itemId | |
| 40 | + * @param bool $everywhere | |
| 41 | + * @return mixed | |
| 42 | + */ | |
| 43 | + public function delete($itemId, $everywhere = false) | |
| 44 | +	{ | |
| 45 | + $params = $everywhere ? ['everywhere' => $everywhere] : []; | |
| 46 | 46 | |
| 47 | - return $this | |
| 48 | - ->getHttp() | |
| 49 | - ->delete( | |
| 50 | - $this->makeRequestUrl($itemId), | |
| 51 | - $params, | |
| 52 | - $this->getHeaders() | |
| 53 | - ); | |
| 54 | - } | |
| 47 | + return $this | |
| 48 | + ->getHttp() | |
| 49 | + ->delete( | |
| 50 | + $this->makeRequestUrl($itemId), | |
| 51 | + $params, | |
| 52 | + $this->getHeaders() | |
| 53 | + ); | |
| 54 | + } | |
| 55 | 55 | } | 
| @@ -17,43 +17,43 @@ | ||
| 17 | 17 | |
| 18 | 18 | class Favro | 
| 19 | 19 |  { | 
| 20 | - /** | |
| 21 | - * @param string $login | |
| 22 | - * @param string $password | |
| 23 | - * @return Api | |
| 24 | - */ | |
| 25 | - public static function create($login, $password) | |
| 26 | -    { | |
| 27 | - $httpClient = new GuzzleHttpClient( | |
| 28 | - new Client(['auth' => [$login, $password]]) | |
| 29 | - ); | |
| 20 | + /** | |
| 21 | + * @param string $login | |
| 22 | + * @param string $password | |
| 23 | + * @return Api | |
| 24 | + */ | |
| 25 | + public static function create($login, $password) | |
| 26 | +	{ | |
| 27 | + $httpClient = new GuzzleHttpClient( | |
| 28 | + new Client(['auth' => [$login, $password]]) | |
| 29 | + ); | |
| 30 | 30 | |
| 31 | - return new Api( | |
| 32 | - $httpClient, | |
| 33 | - new Cards($httpClient), | |
| 34 | - new Collections($httpClient), | |
| 35 | - new Columns($httpClient), | |
| 36 | - new Comments($httpClient), | |
| 37 | - new Organizations($httpClient), | |
| 38 | - new Tags($httpClient), | |
| 39 | - new TaskLists($httpClient), | |
| 40 | - new Tasks($httpClient), | |
| 41 | - new Users($httpClient), | |
| 42 | - new Widgets($httpClient) | |
| 43 | - ); | |
| 44 | - } | |
| 31 | + return new Api( | |
| 32 | + $httpClient, | |
| 33 | + new Cards($httpClient), | |
| 34 | + new Collections($httpClient), | |
| 35 | + new Columns($httpClient), | |
| 36 | + new Comments($httpClient), | |
| 37 | + new Organizations($httpClient), | |
| 38 | + new Tags($httpClient), | |
| 39 | + new TaskLists($httpClient), | |
| 40 | + new Tasks($httpClient), | |
| 41 | + new Users($httpClient), | |
| 42 | + new Widgets($httpClient) | |
| 43 | + ); | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * @codeCoverageIgnore | |
| 48 | - */ | |
| 49 | - private function __construct() | |
| 50 | -    { | |
| 51 | - } | |
| 46 | + /** | |
| 47 | + * @codeCoverageIgnore | |
| 48 | + */ | |
| 49 | + private function __construct() | |
| 50 | +	{ | |
| 51 | + } | |
| 52 | 52 | |
| 53 | - /** | |
| 54 | - * @codeCoverageIgnore | |
| 55 | - */ | |
| 56 | - private function __clone() | |
| 57 | -    { | |
| 58 | - } | |
| 53 | + /** | |
| 54 | + * @codeCoverageIgnore | |
| 55 | + */ | |
| 56 | + private function __clone() | |
| 57 | +	{ | |
| 58 | + } | |
| 59 | 59 | } | 
| @@ -4,11 +4,11 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Comments extends CrudEndpoint | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | -     * {@inheritdoc} | |
| 9 | - */ | |
| 10 | - public function endpoint() | |
| 11 | -    { | |
| 12 | - return 'comments'; | |
| 13 | - } | |
| 7 | + /** | |
| 8 | +	 * {@inheritdoc} | |
| 9 | + */ | |
| 10 | + public function endpoint() | |
| 11 | +	{ | |
| 12 | + return 'comments'; | |
| 13 | + } | |
| 14 | 14 | } | 
| @@ -4,11 +4,11 @@ | ||
| 4 | 4 | |
| 5 | 5 | class TaskLists extends CrudEndpoint | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | -     * {@inheritdoc} | |
| 9 | - */ | |
| 10 | - public function endpoint() | |
| 11 | -    { | |
| 12 | - return 'tasklists'; | |
| 13 | - } | |
| 7 | + /** | |
| 8 | +	 * {@inheritdoc} | |
| 9 | + */ | |
| 10 | + public function endpoint() | |
| 11 | +	{ | |
| 12 | + return 'tasklists'; | |
| 13 | + } | |
| 14 | 14 | } | 
| @@ -4,29 +4,29 @@ | ||
| 4 | 4 | |
| 5 | 5 | class Widgets extends CrudEndpoint | 
| 6 | 6 |  { | 
| 7 | - /** | |
| 8 | - * @param string $itemId | |
| 9 | - * @param string|null $collectionId | |
| 10 | - * @return mixed | |
| 11 | - */ | |
| 12 | - public function delete($itemId, $collectionId = null) | |
| 13 | -    { | |
| 14 | - $attributes = $collectionId ? ['collectionId' => $collectionId] : []; | |
| 7 | + /** | |
| 8 | + * @param string $itemId | |
| 9 | + * @param string|null $collectionId | |
| 10 | + * @return mixed | |
| 11 | + */ | |
| 12 | + public function delete($itemId, $collectionId = null) | |
| 13 | +	{ | |
| 14 | + $attributes = $collectionId ? ['collectionId' => $collectionId] : []; | |
| 15 | 15 | |
| 16 | - return $this | |
| 17 | - ->getHttp() | |
| 18 | - ->delete( | |
| 19 | - $this->makeRequestUrl($itemId), | |
| 20 | - $attributes, | |
| 21 | - $this->getHeaders() | |
| 22 | - ); | |
| 23 | - } | |
| 16 | + return $this | |
| 17 | + ->getHttp() | |
| 18 | + ->delete( | |
| 19 | + $this->makeRequestUrl($itemId), | |
| 20 | + $attributes, | |
| 21 | + $this->getHeaders() | |
| 22 | + ); | |
| 23 | + } | |
| 24 | 24 | |
| 25 | - /** | |
| 26 | -     * {@inheritdoc} | |
| 27 | - */ | |
| 28 | - public function endpoint() | |
| 29 | -    { | |
| 30 | - return 'widgets'; | |
| 31 | - } | |
| 25 | + /** | |
| 26 | +	 * {@inheritdoc} | |
| 27 | + */ | |
| 28 | + public function endpoint() | |
| 29 | +	{ | |
| 30 | + return 'widgets'; | |
| 31 | + } | |
| 32 | 32 | } |