@@ -9,10 +9,10 @@ |
||
9 | 9 | class Tasks extends Endpoint |
10 | 10 | { |
11 | 11 | |
12 | - use BelongsToOrganization, BelongsToCard, CrudEndpoint; |
|
12 | + use BelongsToOrganization, BelongsToCard, CrudEndpoint; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $endpoint = 'tasks'; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $endpoint = 'tasks'; |
|
18 | 18 | } |
19 | 19 | \ 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 |
@@ -8,10 +8,10 @@ |
||
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 | 18 | \ 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 |
@@ -6,93 +6,93 @@ |
||
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 | - ]; |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $allowedMethods = [ |
|
13 | + 'getById', |
|
14 | + 'getAll', |
|
15 | + 'create', |
|
16 | + 'update', |
|
17 | + 'delete', |
|
18 | + ]; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $endpoint; |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $endpoint; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $headers = []; |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $headers = []; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var HttpInterface |
|
32 | - */ |
|
33 | - protected $http; |
|
30 | + /** |
|
31 | + * @var HttpInterface |
|
32 | + */ |
|
33 | + protected $http; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param HttpInterface $http |
|
37 | - */ |
|
38 | - public function __construct(HttpInterface $http) |
|
39 | - { |
|
40 | - $this->http = $http; |
|
41 | - } |
|
35 | + /** |
|
36 | + * @param HttpInterface $http |
|
37 | + */ |
|
38 | + public function __construct(HttpInterface $http) |
|
39 | + { |
|
40 | + $this->http = $http; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param string $verb |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function makeRequestUrl($verb = '') |
|
48 | - { |
|
49 | - return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
50 | - } |
|
43 | + /** |
|
44 | + * @param string $verb |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function makeRequestUrl($verb = '') |
|
48 | + { |
|
49 | + return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param string $method |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function isMethodAllowed($method) |
|
57 | - { |
|
58 | - return in_array($method, $this->allowedMethods); |
|
59 | - } |
|
52 | + /** |
|
53 | + * @param string $method |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function isMethodAllowed($method) |
|
57 | + { |
|
58 | + return in_array($method, $this->allowedMethods); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return HttpInterface |
|
63 | - */ |
|
64 | - public function getHttp() |
|
65 | - { |
|
66 | - return $this->http; |
|
67 | - } |
|
61 | + /** |
|
62 | + * @return HttpInterface |
|
63 | + */ |
|
64 | + public function getHttp() |
|
65 | + { |
|
66 | + return $this->http; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param array $params |
|
71 | - * @return array |
|
72 | - */ |
|
73 | - public function getAll(array $params = []) |
|
74 | - { |
|
75 | - return $this->getHttp()->get( |
|
76 | - $this->makeRequestUrl(), $params, $this->getHeaders() |
|
77 | - ); |
|
78 | - } |
|
69 | + /** |
|
70 | + * @param array $params |
|
71 | + * @return array |
|
72 | + */ |
|
73 | + public function getAll(array $params = []) |
|
74 | + { |
|
75 | + return $this->getHttp()->get( |
|
76 | + $this->makeRequestUrl(), $params, $this->getHeaders() |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @param string $id |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function getById($id) |
|
85 | - { |
|
86 | - return $this->getHttp()->get( |
|
87 | - $this->makeRequestUrl($id), [], $this->getHeaders() |
|
88 | - ); |
|
89 | - } |
|
80 | + /** |
|
81 | + * @param string $id |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function getById($id) |
|
85 | + { |
|
86 | + return $this->getHttp()->get( |
|
87 | + $this->makeRequestUrl($id), [], $this->getHeaders() |
|
88 | + ); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - protected function getHeaders() |
|
95 | - { |
|
96 | - return $this->headers; |
|
97 | - } |
|
91 | + /** |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + protected function getHeaders() |
|
95 | + { |
|
96 | + return $this->headers; |
|
97 | + } |
|
98 | 98 | } |
99 | 99 | \ No newline at end of file |
@@ -25,55 +25,55 @@ |
||
25 | 25 | */ |
26 | 26 | class Api |
27 | 27 | { |
28 | - /** |
|
29 | - * @var EndpointsContainer |
|
30 | - */ |
|
31 | - protected $endpointsContainer; |
|
28 | + /** |
|
29 | + * @var EndpointsContainer |
|
30 | + */ |
|
31 | + protected $endpointsContainer; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var string |
|
35 | - */ |
|
36 | - protected $organizationId; |
|
33 | + /** |
|
34 | + * @var string |
|
35 | + */ |
|
36 | + protected $organizationId; |
|
37 | 37 | |
38 | - public function __construct(EndpointsContainer $endpointsContainer) |
|
39 | - { |
|
40 | - $this->endpointsContainer = $endpointsContainer; |
|
41 | - } |
|
38 | + public function __construct(EndpointsContainer $endpointsContainer) |
|
39 | + { |
|
40 | + $this->endpointsContainer = $endpointsContainer; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Magic method to access different endpoints. |
|
45 | - * |
|
46 | - * @param string $endpoint |
|
47 | - * |
|
48 | - * @return Endpoint |
|
49 | - */ |
|
50 | - public function __get($endpoint) |
|
51 | - { |
|
52 | - $endpoint = $this->endpointsContainer->resolveEndpoint($endpoint); |
|
43 | + /** |
|
44 | + * Magic method to access different endpoints. |
|
45 | + * |
|
46 | + * @param string $endpoint |
|
47 | + * |
|
48 | + * @return Endpoint |
|
49 | + */ |
|
50 | + public function __get($endpoint) |
|
51 | + { |
|
52 | + $endpoint = $this->endpointsContainer->resolveEndpoint($endpoint); |
|
53 | 53 | |
54 | - if (method_exists($endpoint, 'setOrganizationId')) { |
|
55 | - $endpoint->setOrganizationId($this->organizationId); |
|
56 | - } |
|
54 | + if (method_exists($endpoint, 'setOrganizationId')) { |
|
55 | + $endpoint->setOrganizationId($this->organizationId); |
|
56 | + } |
|
57 | 57 | |
58 | - return $endpoint; |
|
59 | - } |
|
58 | + return $endpoint; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param int $organizationId |
|
63 | - * @return $this |
|
64 | - */ |
|
65 | - public function setOrganization($organizationId) |
|
66 | - { |
|
67 | - $this->organizationId = $organizationId; |
|
61 | + /** |
|
62 | + * @param int $organizationId |
|
63 | + * @return $this |
|
64 | + */ |
|
65 | + public function setOrganization($organizationId) |
|
66 | + { |
|
67 | + $this->organizationId = $organizationId; |
|
68 | 68 | |
69 | - return $this; |
|
70 | - } |
|
69 | + return $this; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getOrganizationId() |
|
76 | - { |
|
77 | - return $this->organizationId; |
|
78 | - } |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getOrganizationId() |
|
76 | + { |
|
77 | + return $this->organizationId; |
|
78 | + } |
|
79 | 79 | } |
80 | 80 | \ No newline at end of file |
@@ -5,48 +5,48 @@ |
||
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 | - $this->getHeaders() |
|
50 | - ); |
|
51 | - } |
|
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 | + $this->getHeaders() |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | } |