@@ -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 |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Cards extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'cards'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'cards'; |
|
13 | + } |
|
14 | 14 | } |
@@ -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,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Tasks extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'tasks'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'tasks'; |
|
13 | + } |
|
14 | 14 | } |
@@ -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 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Columns extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'columns'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'columns'; |
|
13 | + } |
|
14 | 14 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class TaskLists extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'tasklists'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'tasklists'; |
|
13 | + } |
|
14 | 14 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Users extends Endpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'users'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'users'; |
|
13 | + } |
|
14 | 14 | } |
@@ -4,11 +4,11 @@ |
||
4 | 4 | |
5 | 5 | class Comments extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @return string |
|
9 | - */ |
|
10 | - public function endpoint() |
|
11 | - { |
|
12 | - return 'comments'; |
|
13 | - } |
|
7 | + /** |
|
8 | + * @return string |
|
9 | + */ |
|
10 | + public function endpoint() |
|
11 | + { |
|
12 | + return 'comments'; |
|
13 | + } |
|
14 | 14 | } |