ReviewOS

also looking at this

meemalabs/meema-client-php

Teams model

#12
Merged glennmichael123 wants to merge teams-model into main
3 files +130 -1
src/Client.phpmodified+11-0
Changes to src/Client.php
@@ -6,6 +6,7 @@ use Dotenv\Dotenv;
66use GuzzleHttp\Client as GuzzleClient;
77use Meema\MeemaApi\Models\Folder;
88use Meema\MeemaApi\Models\Media;
9use Meema\MeemaApi\Models\Team;
910
1011class Client
1112{
@@ -105,4 +106,14 @@ class Client
105106 {
106107 return new Media($this);
107108 }
109
110 /**
111 * Initialize the team model.
112 *
113 * @return Meema\MeemaApi\Models\Team
114 */
115 public function teams(): Team
116 {
117 return new Team($this);
118 }
108119}
src/Models/Team.phpadded+118-0
Changes to src/Models/Team.php
@@ -0,0 +1,118 @@
1<?php
2
3namespace Meema\MeemaApi\Models;
4
5use Meema\MeemaApi\Client;
6use Meema\MeemaApi\Response\Response;
7
8class Team
9{
10 /**
11 * @var Meema\MeemaApi\Client
12 */
13 protected $client;
14
15 /**
16 * Construct Folder model.
17 *
18 * @param Meema\MeemaApi\Client $client
19 * @param int $teamId
20 */
21 public function __construct(Client $client)
22 {
23 $this->client = $client;
24 }
25
26 /**
27 * List all teams.
28 *
29 * @return array
30 */
31 public function all(): array
32 {
33 return $this->client->request('GET', 'teams');
34 }
35
36 /**
37 * Get specific teams.
38 *
39 * @param int $id
40 *
41 * @return array
42 */
43 public function get($id = null)
44 {
45 if (! $id) {
46 return $this->all();
47 }
48
49 $ids = is_array($id) ? $id : func_get_args();
50
51 return $this->client->request('GET', 'teams', ['team_ids' => $ids]);
52 }
53
54 /**
55 * Get specific teams.
56 *
57 * @param int $id
58 *
59 * @return array
60 */
61 public function find($id)
62 {
63 $response = $this->client->request('GET', "teams/${id}");
64
65 return new Response($this, $response);
66 }
67
68 /**
69 * Create folder.
70 *
71 * @param string $name
72 *
73 * @return array
74 */
75 public function create($data)
76 {
77 return $this->client->request('POST', 'teams', $data);
78 }
79
80 /**
81 * Update folder.
82 *
83 * @param string $name
84 * @param int $id
85 *
86 * @return array
87 */
88 public function update($id, $name): array
89 {
90 $name = is_array($name) ? $name : compact('name');
91
92 return $this->client->request('PATCH', "teams/{$id}", $name);
93 }
94
95 /**
96 * Delete a folder.
97 *
98 * @param int $id
99 *
100 * @return null
101 */
102 public function delete($id)
103 {
104 return $this->client->request('DELETE', "teams/{$id}");
105 }
106
107 /**
108 * Delete a folder.
109 *
110 * @param int $id
111 *
112 * @return null
113 */
114 public function toggleMediaRecognition($id, $status)
115 {
116 return $this->client->request('POST', "teams/{$id}/toggle-media-recognition", compact('status'));
117 }
118}
src/Response/Response.phpmodified+1-1
Changes to src/Response/Response.php
@@ -57,7 +57,7 @@ class Response
5757 */
5858 public function getKey()
5959 {
60 return $this->getData($this->getKeyName());
60 return $this->getData($this->getKeyName()) ?: $this->getContent($this->getKeyName());
6161 }
6262
6363 /**