| @@ -87,13 +89,7 @@ class Folder |
| 87 | 89 | { |
| 88 | 90 | $name = is_array($name) ? $name : compact('name'); |
| 89 | 91 | |
| 90 | | - if ($this->model) { |
| 91 | | - $folderName = ['folder_name' => $name['name']]; |
| 92 | | - |
| 93 | | - return $this->addFolderToMedia($this->model->getId(), $folderName); |
| 94 | | - } |
| 95 | | - |
| 96 | | - return $this->client->request('POST', "folders/{$this->client->getAccessKey()}", $name); |
| 92 | + return $this->client->request('POST', "tags/{$this->client->getAccessKey()}", $name); |
| 97 | 93 | } |
| 98 | 94 | |
| 99 | 95 | |
| @@ -104,11 +100,9 @@ class Folder |
| 104 | 100 | |
| 105 | 101 | |
| 106 | 102 | |
| 107 | | - public function update($id, $name): array |
| 103 | + public function update($id, $data): array |
| 108 | 104 | { |
| 109 | | - $name = is_array($name) ? $name : compact('name'); |
| 110 | | - |
| 111 | | - return $this->client->request('PATCH', "folders/{$id}", $name); |
| 105 | + return $this->client->request('PATCH', 'tags/color', $data); |
| 112 | 106 | } |
| 113 | 107 | |
| 114 | 108 | |
| @@ -116,75 +110,73 @@ class Folder |
| 116 | 110 | |
| 117 | 111 | |
| 118 | 112 | |
| 119 | | - |
| 113 | + |
| 120 | 114 | |
| 121 | 115 | public function delete($id) |
| 122 | 116 | { |
| 123 | | - if ($this->model) { |
| 124 | | - return $this->deleteFolderFromMedia($this->model->getId(), $id); |
| 125 | | - } |
| 126 | | - |
| 127 | | - return $this->client->request('DELETE', "folders/{$id}"); |
| 117 | + return $this->client->request('DELETE', "tags/{$id}"); |
| 128 | 118 | } |
| 129 | 119 | |
| 130 | 120 | |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 121 | + |
| 134 | 122 | |
| 135 | | - |
| 123 | + |
| 136 | 124 | |
| 137 | | - public function archive($id): array |
| 125 | + public function media($id = null): Media |
| 138 | 126 | { |
| 139 | | - return $this->client->request('POST', "folders/{$id}/archive"); |
| 127 | + $this->id = $id; |
| 128 | + |
| 129 | + return (new Media($this->client))->setTag($this); |
| 140 | 130 | } |
| 141 | 131 | |
| 142 | 132 | |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 133 | + |
| 146 | 134 | |
| 147 | | - |
| 135 | + |
| 148 | 136 | |
| 149 | | - public function unarchive($id): array |
| 137 | + public function folders($id = null): Folder |
| 150 | 138 | { |
| 151 | | - return $this->client->request('POST', "folders/{$id}/unarchive"); |
| 139 | + $this->id = $id; |
| 140 | + |
| 141 | + return (new Folder($this->client))->setTag($this); |
| 152 | 142 | } |
| 153 | 143 | |
| 154 | 144 | |
| 155 | | - |
| 145 | + |
| 156 | 146 | |
| 157 | 147 | |
| 158 | 148 | |
| 159 | 149 | |
| 160 | 150 | |
| 161 | | - public function duplicate($id): array |
| 151 | + public function fetchTagsForMedia($id): array |
| 162 | 152 | { |
| 163 | | - return $this->client->request('POST', "folders/{$id}/duplicate"); |
| 153 | + return $this->client->request('GET', "media/{$id}/tags"); |
| 164 | 154 | } |
| 165 | 155 | |
| 166 | 156 | |
| 167 | | - |
| 157 | + |
| 168 | 158 | |
| 169 | 159 | |
| 170 | 160 | |
| 171 | 161 | |
| 172 | 162 | |
| 173 | | - public function addFolderToMedia($id, $name): array |
| 163 | + public function fetchTagsForFolder($id): array |
| 174 | 164 | { |
| 175 | | - return $this->client->request('POST', "media/{$id}/folders", $name); |
| 165 | + return $this->client->request('GET', "folders/{$id}/tags"); |
| 176 | 166 | } |
| 177 | 167 | |
| 178 | 168 | |
| 179 | | - |
| 169 | + |
| 180 | 170 | |
| 181 | | - |
| 171 | + |
| 182 | 172 | |
| 183 | | - |
| 173 | + |
| 184 | 174 | |
| 185 | | - public function deleteFolderFromMedia($mediaId, $folderId) |
| 175 | + public function setFolder($folder): self |
| 186 | 176 | { |
| 187 | | - return $this->client->request('DELETE', "media/{$mediaId}/folders/{$folderId}"); |
| 177 | + $this->model = $folder; |
| 178 | + |
| 179 | + return $this; |
| 188 | 180 | } |
| 189 | 181 | |
| 190 | 182 | |
| @@ -206,20 +198,31 @@ class Folder |
| 206 | 198 | |
| 207 | 199 | |
| 208 | 200 | |
| 209 | | - public function getId(): int |
| 201 | + public function getId() |
| 210 | 202 | { |
| 211 | 203 | return $this->id; |
| 212 | 204 | } |
| 213 | 205 | |
| 214 | 206 | |
| 215 | | - |
| 207 | + |
| 216 | 208 | |
| 217 | | - |
| 209 | + |
| 218 | 210 | |
| 219 | | - public function media($id = null): Media |
| 211 | + public function fetchForModel(): array |
| 220 | 212 | { |
| 221 | | - $this->id = $id; |
| 213 | + $data = []; |
| 214 | + |
| 215 | + switch (get_class($this->model)) { |
| 216 | + case Folder::class: |
| 217 | + $data = $this->fetchTagsForFolder($this->model->getId()); |
| 218 | + break; |
| 219 | + case Media::class: |
| 220 | + $data = $this->fetchTagsForMedia($this->model->getId()); |
| 221 | + break; |
| 222 | + default: |
| 223 | + $data = []; |
| 224 | + } |
| 222 | 225 | |
| 223 | | - return (new Media($this->client))->setFolder($this); |
| 226 | + return $data; |
| 224 | 227 | } |
| 225 | 228 | } |