@@ -5,8 +5,8 @@ |
||
5 | 5 | class Comments extends CrudEndpoint |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @var string |
|
10 | - */ |
|
11 | - protected $endpoint = 'comments'; |
|
8 | + /** |
|
9 | + * @var string |
|
10 | + */ |
|
11 | + protected $endpoint = 'comments'; |
|
12 | 12 | } |
13 | 13 | \ No newline at end of file |
@@ -4,49 +4,49 @@ |
||
4 | 4 | |
5 | 5 | 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 | - * @return mixed |
|
41 | - */ |
|
42 | - public function delete($itemId) |
|
43 | - { |
|
44 | - return $this |
|
45 | - ->getHttp() |
|
46 | - ->delete( |
|
47 | - $this->makeRequestUrl($itemId), |
|
48 | - [], |
|
49 | - $this->getHeaders() |
|
50 | - ); |
|
51 | - } |
|
38 | + /** |
|
39 | + * @param string $itemId |
|
40 | + * @return mixed |
|
41 | + */ |
|
42 | + public function delete($itemId) |
|
43 | + { |
|
44 | + return $this |
|
45 | + ->getHttp() |
|
46 | + ->delete( |
|
47 | + $this->makeRequestUrl($itemId), |
|
48 | + [], |
|
49 | + $this->getHeaders() |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Columns extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - protected $endpoint = 'columns'; |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + protected $endpoint = 'columns'; |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Tasks extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - protected $endpoint = 'tasks'; |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + protected $endpoint = 'tasks'; |
|
11 | 11 | } |
12 | 12 | \ No newline at end of file |
@@ -4,26 +4,26 @@ |
||
4 | 4 | |
5 | 5 | class Widgets extends CrudEndpoint |
6 | 6 | { |
7 | - /** |
|
8 | - * @var string |
|
9 | - */ |
|
10 | - protected $endpoint = 'widgets'; |
|
7 | + /** |
|
8 | + * @var string |
|
9 | + */ |
|
10 | + protected $endpoint = 'widgets'; |
|
11 | 11 | |
12 | - /** |
|
13 | - * @param string $itemId |
|
14 | - * @param string|null $collectionId |
|
15 | - * @return mixed |
|
16 | - */ |
|
17 | - public function delete($itemId, $collectionId = null) |
|
18 | - { |
|
19 | - $attributes = $collectionId ? ['collectionId' => $collectionId] : []; |
|
12 | + /** |
|
13 | + * @param string $itemId |
|
14 | + * @param string|null $collectionId |
|
15 | + * @return mixed |
|
16 | + */ |
|
17 | + public function delete($itemId, $collectionId = null) |
|
18 | + { |
|
19 | + $attributes = $collectionId ? ['collectionId' => $collectionId] : []; |
|
20 | 20 | |
21 | - return $this |
|
22 | - ->getHttp() |
|
23 | - ->delete( |
|
24 | - $this->makeRequestUrl($itemId), |
|
25 | - $attributes, |
|
26 | - $this->getHeaders() |
|
27 | - ); |
|
28 | - } |
|
21 | + return $this |
|
22 | + ->getHttp() |
|
23 | + ->delete( |
|
24 | + $this->makeRequestUrl($itemId), |
|
25 | + $attributes, |
|
26 | + $this->getHeaders() |
|
27 | + ); |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -5,31 +5,31 @@ |
||
5 | 5 | |
6 | 6 | class Organizations extends CrudEndpoint |
7 | 7 | { |
8 | - /** |
|
9 | - * @var string |
|
10 | - */ |
|
11 | - protected $endpoint = 'organizations'; |
|
8 | + /** |
|
9 | + * @var string |
|
10 | + */ |
|
11 | + protected $endpoint = 'organizations'; |
|
12 | 12 | |
13 | - /** |
|
14 | - * @param string $id |
|
15 | - * @return array |
|
16 | - */ |
|
17 | - public function getById($id) |
|
18 | - { |
|
19 | - $this->headers['organizationId'] = $id; |
|
13 | + /** |
|
14 | + * @param string $id |
|
15 | + * @return array |
|
16 | + */ |
|
17 | + public function getById($id) |
|
18 | + { |
|
19 | + $this->headers['organizationId'] = $id; |
|
20 | 20 | |
21 | - return parent::getById($id); |
|
22 | - } |
|
21 | + return parent::getById($id); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * @param string $itemId |
|
26 | - * @param array $attributes |
|
27 | - * @return mixed |
|
28 | - */ |
|
29 | - public function update($itemId, array $attributes) |
|
30 | - { |
|
31 | - $this->headers['organizationId'] = $itemId; |
|
24 | + /** |
|
25 | + * @param string $itemId |
|
26 | + * @param array $attributes |
|
27 | + * @return mixed |
|
28 | + */ |
|
29 | + public function update($itemId, array $attributes) |
|
30 | + { |
|
31 | + $this->headers['organizationId'] = $itemId; |
|
32 | 32 | |
33 | - return parent::update($itemId, $attributes); |
|
34 | - } |
|
33 | + return parent::update($itemId, $attributes); |
|
34 | + } |
|
35 | 35 | } |
36 | 36 | \ No newline at end of file |
@@ -6,120 +6,120 @@ |
||
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 | - ]; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $endpoint; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - protected $headers = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var HttpClient |
|
32 | - */ |
|
33 | - protected $http; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $organizationId; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param HttpClient $http |
|
42 | - */ |
|
43 | - public function __construct(HttpClient $http) |
|
44 | - { |
|
45 | - $this->http = $http; |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * @param string $verb |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function makeRequestUrl($verb = '') |
|
53 | - { |
|
54 | - return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param string $method |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function isMethodAllowed($method) |
|
62 | - { |
|
63 | - return in_array($method, $this->allowedMethods); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @return HttpClient |
|
68 | - */ |
|
69 | - public function getHttp() |
|
70 | - { |
|
71 | - return $this->http; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param array $params |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getAll(array $params = []) |
|
79 | - { |
|
80 | - return $this |
|
81 | - ->getHttp() |
|
82 | - ->get( |
|
83 | - $this->makeRequestUrl(), |
|
84 | - $params, |
|
85 | - $this->getHeaders() |
|
86 | - ); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @param string $id |
|
91 | - * @return array |
|
92 | - */ |
|
93 | - public function getById($id) |
|
94 | - { |
|
95 | - return $this |
|
96 | - ->getHttp() |
|
97 | - ->get( |
|
98 | - $this->makeRequestUrl($id), |
|
99 | - [], |
|
100 | - $this->getHeaders() |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return array |
|
106 | - */ |
|
107 | - protected function getHeaders() |
|
108 | - { |
|
109 | - return array_merge( |
|
110 | - ['organizationId' => $this->organizationId], |
|
111 | - $this->headers |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $organizationId |
|
117 | - * @return $this |
|
118 | - */ |
|
119 | - public function setOrganizationId($organizationId) |
|
120 | - { |
|
121 | - $this->organizationId = $organizationId; |
|
122 | - |
|
123 | - return $this; |
|
124 | - } |
|
9 | + /** |
|
10 | + * @var array |
|
11 | + */ |
|
12 | + protected $allowedMethods = [ |
|
13 | + 'getById', |
|
14 | + 'getAll', |
|
15 | + 'create', |
|
16 | + 'update', |
|
17 | + 'delete', |
|
18 | + ]; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $endpoint; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + protected $headers = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var HttpClient |
|
32 | + */ |
|
33 | + protected $http; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $organizationId; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param HttpClient $http |
|
42 | + */ |
|
43 | + public function __construct(HttpClient $http) |
|
44 | + { |
|
45 | + $this->http = $http; |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * @param string $verb |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function makeRequestUrl($verb = '') |
|
53 | + { |
|
54 | + return "https://favro.com/api/v1/{$this->endpoint}/$verb"; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param string $method |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function isMethodAllowed($method) |
|
62 | + { |
|
63 | + return in_array($method, $this->allowedMethods); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @return HttpClient |
|
68 | + */ |
|
69 | + public function getHttp() |
|
70 | + { |
|
71 | + return $this->http; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param array $params |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getAll(array $params = []) |
|
79 | + { |
|
80 | + return $this |
|
81 | + ->getHttp() |
|
82 | + ->get( |
|
83 | + $this->makeRequestUrl(), |
|
84 | + $params, |
|
85 | + $this->getHeaders() |
|
86 | + ); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @param string $id |
|
91 | + * @return array |
|
92 | + */ |
|
93 | + public function getById($id) |
|
94 | + { |
|
95 | + return $this |
|
96 | + ->getHttp() |
|
97 | + ->get( |
|
98 | + $this->makeRequestUrl($id), |
|
99 | + [], |
|
100 | + $this->getHeaders() |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return array |
|
106 | + */ |
|
107 | + protected function getHeaders() |
|
108 | + { |
|
109 | + return array_merge( |
|
110 | + ['organizationId' => $this->organizationId], |
|
111 | + $this->headers |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $organizationId |
|
117 | + * @return $this |
|
118 | + */ |
|
119 | + public function setOrganizationId($organizationId) |
|
120 | + { |
|
121 | + $this->organizationId = $organizationId; |
|
122 | + |
|
123 | + return $this; |
|
124 | + } |
|
125 | 125 | } |
126 | 126 | \ No newline at end of file |