@@ -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 |
@@ -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 |
@@ -6,21 +6,21 @@ |
||
6 | 6 | |
7 | 7 | class Organizations extends Endpoint |
8 | 8 | { |
9 | - use CrudEndpoint; |
|
9 | + use CrudEndpoint; |
|
10 | 10 | |
11 | - /** |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - protected $endpoint = 'organizations'; |
|
11 | + /** |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + protected $endpoint = 'organizations'; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @param string $id |
|
18 | - * @return array |
|
19 | - */ |
|
20 | - public function getById($id) |
|
21 | - { |
|
22 | - $this->headers['organizationId'] = $id; |
|
16 | + /** |
|
17 | + * @param string $id |
|
18 | + * @return array |
|
19 | + */ |
|
20 | + public function getById($id) |
|
21 | + { |
|
22 | + $this->headers['organizationId'] = $id; |
|
23 | 23 | |
24 | - return parent::getById($id); |
|
25 | - } |
|
24 | + return parent::getById($id); |
|
25 | + } |
|
26 | 26 | } |
27 | 27 | \ No newline at end of file |
@@ -7,10 +7,10 @@ |
||
7 | 7 | |
8 | 8 | class Collections extends Endpoint |
9 | 9 | { |
10 | - use BelongsToOrganization, CrudEndpoint; |
|
10 | + use BelongsToOrganization, CrudEndpoint; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $endpoint = 'collections'; |
|
12 | + /** |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $endpoint = 'collections'; |
|
16 | 16 | } |
17 | 17 | \ No newline at end of file |
@@ -5,49 +5,49 @@ |
||
5 | 5 | trait CrudEndpoint |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @param array $attributes |
|
10 | - * @return array |
|
11 | - */ |
|
12 | - public function create(array $attributes) |
|
13 | - { |
|
14 | - return $this |
|
15 | - ->getHttp() |
|
16 | - ->post( |
|
17 | - $this->makeRequestUrl(), |
|
18 | - $attributes, |
|
19 | - $this->getHeaders() |
|
20 | - ); |
|
21 | - } |
|
8 | + /** |
|
9 | + * @param array $attributes |
|
10 | + * @return array |
|
11 | + */ |
|
12 | + public function create(array $attributes) |
|
13 | + { |
|
14 | + return $this |
|
15 | + ->getHttp() |
|
16 | + ->post( |
|
17 | + $this->makeRequestUrl(), |
|
18 | + $attributes, |
|
19 | + $this->getHeaders() |
|
20 | + ); |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $itemId |
|
25 | - * @param array $attributes |
|
26 | - * @return mixed |
|
27 | - */ |
|
28 | - public function update($itemId, array $attributes) |
|
29 | - { |
|
30 | - return $this |
|
31 | - ->getHttp() |
|
32 | - ->put( |
|
33 | - $this->makeRequestUrl($itemId), |
|
34 | - $attributes, |
|
35 | - $this->getHeaders() |
|
36 | - ); |
|
37 | - } |
|
23 | + /** |
|
24 | + * @param string $itemId |
|
25 | + * @param array $attributes |
|
26 | + * @return mixed |
|
27 | + */ |
|
28 | + public function update($itemId, array $attributes) |
|
29 | + { |
|
30 | + return $this |
|
31 | + ->getHttp() |
|
32 | + ->put( |
|
33 | + $this->makeRequestUrl($itemId), |
|
34 | + $attributes, |
|
35 | + $this->getHeaders() |
|
36 | + ); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param string $itemId |
|
41 | - * @return mixed |
|
42 | - */ |
|
43 | - public function delete($itemId) |
|
44 | - { |
|
45 | - return $this |
|
46 | - ->getHttp() |
|
47 | - ->delete( |
|
48 | - $this->makeRequestUrl($itemId), |
|
49 | - [], |
|
50 | - $this->getHeaders() |
|
51 | - ); |
|
52 | - } |
|
39 | + /** |
|
40 | + * @param string $itemId |
|
41 | + * @return mixed |
|
42 | + */ |
|
43 | + public function delete($itemId) |
|
44 | + { |
|
45 | + return $this |
|
46 | + ->getHttp() |
|
47 | + ->delete( |
|
48 | + $this->makeRequestUrl($itemId), |
|
49 | + [], |
|
50 | + $this->getHeaders() |
|
51 | + ); |
|
52 | + } |
|
53 | 53 | } |
@@ -8,28 +8,28 @@ |
||
8 | 8 | class Widgets extends Endpoint |
9 | 9 | { |
10 | 10 | |
11 | - use BelongsToOrganization, CrudEndpoint; |
|
11 | + use BelongsToOrganization, CrudEndpoint; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @var string |
|
15 | - */ |
|
16 | - protected $endpoint = 'widgets'; |
|
13 | + /** |
|
14 | + * @var string |
|
15 | + */ |
|
16 | + protected $endpoint = 'widgets'; |
|
17 | 17 | |
18 | - /** |
|
19 | - * @param string $itemId |
|
20 | - * @param string|null $collectionId |
|
21 | - * @return mixed |
|
22 | - */ |
|
23 | - public function delete($itemId, $collectionId = null) |
|
24 | - { |
|
25 | - $attributes = $collectionId ? ['collectionId' => $collectionId] : []; |
|
18 | + /** |
|
19 | + * @param string $itemId |
|
20 | + * @param string|null $collectionId |
|
21 | + * @return mixed |
|
22 | + */ |
|
23 | + public function delete($itemId, $collectionId = null) |
|
24 | + { |
|
25 | + $attributes = $collectionId ? ['collectionId' => $collectionId] : []; |
|
26 | 26 | |
27 | - return $this |
|
28 | - ->getHttp() |
|
29 | - ->delete( |
|
30 | - $this->makeRequestUrl($itemId), |
|
31 | - $attributes, |
|
32 | - $this->getHeaders() |
|
33 | - ); |
|
34 | - } |
|
27 | + return $this |
|
28 | + ->getHttp() |
|
29 | + ->delete( |
|
30 | + $this->makeRequestUrl($itemId), |
|
31 | + $attributes, |
|
32 | + $this->getHeaders() |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -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,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 HttpClient $http |
|
25 | - */ |
|
26 | - public function __construct(HttpClient $http) |
|
27 | - { |
|
28 | - $this->http = $http; |
|
29 | - } |
|
23 | + /** |
|
24 | + * @param HttpClient $http |
|
25 | + */ |
|
26 | + public function __construct(HttpClient $http) |
|
27 | + { |
|
28 | + $this->http = $http; |
|
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->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 |
@@ -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 |
@@ -4,41 +4,41 @@ |
||
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 $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 | 45 | \ No newline at end of file |