|
28 | 28 | use Exception; |
29 | 29 | use WpOrg\Requests\Requests; |
30 | 30 |
|
31 | | -/** |
32 | | - * todo self::get_artist_releases() https://www.discogs.com/developers/#page:database,header:database-artist-releases-get |
33 | | - * todo self::get_master_versions() https://www.discogs.com/developers/#page:database,header:database-master-release-versions-get |
34 | | - * todo self::get_label() https://www.discogs.com/developers/#page:database,header:database-label-get |
35 | | - * todo self::get_label_releases() https://www.discogs.com/developers/#page:database,header:database-all-label-releases-get |
36 | | - * todo self::get_identity() https://www.discogs.com/developers/#page:user-identity,header:user-identity-identity-get |
37 | | - * todo self::get_profile() https://www.discogs.com/developers/#page:user-identity,header:user-identity-profile-get |
38 | | - * todo self::add_inventory() https://www.discogs.com/developers/#page:inventory-upload,header:inventory-upload-add-inventory-post |
39 | | - * todo self::delete_inventory() https://www.discogs.com/developers/#page:inventory-upload,header:inventory-upload-delete-inventory-post |
40 | | - * todo self::get_collection_folders() https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-get |
41 | | - * todo self::get_collection_folder() https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-folder-get |
42 | | - * todo self::get_collection_items_by_folder() https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-items-by-folder-get |
43 | | - * todo self::get_user_lists() https://www.discogs.com/developers/index.html#page:user-lists,header:user-lists-user-lists |
44 | | - * todo self::get_lists() https://www.discogs.com/developers/index.html#page:user-lists,header:user-lists-list |
45 | | - * todo self::get_wantlist() https://www.discogs.com/developers/#page:user-wantlist,header:user-wantlist-wantlist |
46 | | - */ |
47 | 31 | class Discogs |
48 | 32 | { |
49 | | - public const VERSION = '0.1.0'; |
| 33 | + public const VERSION = '0.2.0'; |
50 | 34 |
|
51 | 35 | private const DISCOGS_URL = 'https://api.discogs.com/'; |
52 | 36 |
|
53 | 37 | private readonly string $api_key; |
54 | 38 |
|
55 | 39 | private readonly string $secret; |
56 | 40 |
|
57 | | - private string $userAgent; |
| 41 | + private readonly string $userAgent; |
58 | 42 |
|
59 | 43 | /** |
60 | 44 | * Constructor |
@@ -107,6 +91,7 @@ public function search(array $parameters): array |
107 | 91 | if (!isset($parameters['per_page'])) { |
108 | 92 | $parameters['per_page'] = 10; |
109 | 93 | } |
| 94 | + |
110 | 95 | $query = http_build_query($parameters); |
111 | 96 |
|
112 | 97 | return $this->_query_discogs('database/search', $query); |
@@ -197,6 +182,140 @@ public function get_master(int $object_id): array |
197 | 182 | */ |
198 | 183 | public function get_artist(int $object_id): array |
199 | 184 | { |
200 | | - return $this->_query_discogs('artists/' . $object_id); |
| 185 | + $query = sprintf("artists/%d", $object_id); |
| 186 | + |
| 187 | + return $this->_query_discogs($query); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * https://www.discogs.com/developers/#page:database,header:database-artist-releases-get |
| 192 | + * @return array<string, mixed> |
| 193 | + * @throws Exception |
| 194 | + */ |
| 195 | + public function get_artist_releases(int $artist_id): array |
| 196 | + { |
| 197 | + $query = sprintf("artists/%d/releases", $artist_id); |
| 198 | + |
| 199 | + return $this->_query_discogs($query); |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * https://www.discogs.com/developers/#page:database,header:database-master-release-versions-get |
| 204 | + * @return array<string, mixed> |
| 205 | + * @throws Exception |
| 206 | + */ |
| 207 | + public function get_master_versions(int $master_id): array |
| 208 | + { |
| 209 | + $query = sprintf("masters/%d/versions", $master_id); |
| 210 | + |
| 211 | + return $this->_query_discogs($query); |
| 212 | + } |
| 213 | + |
| 214 | + /** |
| 215 | + * https://www.discogs.com/developers/#page:database,header:database-label-get |
| 216 | + * @return array<string, mixed> |
| 217 | + * @throws Exception |
| 218 | + */ |
| 219 | + public function get_label(int $label_id): array |
| 220 | + { |
| 221 | + $query = sprintf("labels/%d", $label_id); |
| 222 | + |
| 223 | + return $this->_query_discogs($query); |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * https://www.discogs.com/developers/#page:database,header:database-all-label-releases-get |
| 228 | + * @return array<string, mixed> |
| 229 | + * @throws Exception |
| 230 | + */ |
| 231 | + public function get_label_releases(int $label_id): array |
| 232 | + { |
| 233 | + $query = sprintf("labels/%d/releases", $label_id); |
| 234 | + |
| 235 | + return $this->_query_discogs($query); |
| 236 | + } |
| 237 | + |
| 238 | + /** |
| 239 | + * https://www.discogs.com/developers/#page:user-identity,header:user-identity-profile-get |
| 240 | + * @return array<string, mixed> |
| 241 | + * @throws Exception |
| 242 | + */ |
| 243 | + public function get_profile(string $username): array |
| 244 | + { |
| 245 | + $query = sprintf("users/%s", $username); |
| 246 | + |
| 247 | + return $this->_query_discogs($query); |
| 248 | + } |
| 249 | + |
| 250 | + /** |
| 251 | + * https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-get |
| 252 | + * @return array<string, mixed> |
| 253 | + * @throws Exception |
| 254 | + */ |
| 255 | + public function get_collection_folders(string $username): array |
| 256 | + { |
| 257 | + $query = sprintf("users/%s/collection/folders", $username); |
| 258 | + |
| 259 | + return $this->_query_discogs($query); |
| 260 | + } |
| 261 | + |
| 262 | + /** |
| 263 | + * https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-folder-get |
| 264 | + * @return array<string, mixed> |
| 265 | + * @throws Exception |
| 266 | + */ |
| 267 | + public function get_collection_folder(string $username, int $folder_id): array |
| 268 | + { |
| 269 | + $query = sprintf("users/%s/collection/folders/%s", $username, $folder_id); |
| 270 | + |
| 271 | + return $this->_query_discogs($query); |
| 272 | + } |
| 273 | + |
| 274 | + /** |
| 275 | + * https://www.discogs.com/developers/#page:user-collection,header:user-collection-collection-items-by-folder-get |
| 276 | + * @return array<string, mixed> |
| 277 | + * @throws Exception |
| 278 | + */ |
| 279 | + public function get_collection_items_by_folder(string $username, int $folder_id): array |
| 280 | + { |
| 281 | + $query = sprintf("users/%s/collection/folders/%s/releases", $username, $folder_id); |
| 282 | + |
| 283 | + return $this->_query_discogs($query); |
| 284 | + } |
| 285 | + |
| 286 | + /** |
| 287 | + * https://www.discogs.com/developers/index.html#page:user-lists,header:user-lists-user-lists |
| 288 | + * @return array<string, mixed> |
| 289 | + * @throws Exception |
| 290 | + */ |
| 291 | + public function get_user_lists(string $username): array |
| 292 | + { |
| 293 | + $query = sprintf("users/%s/lists", $username); |
| 294 | + |
| 295 | + return $this->_query_discogs($query); |
| 296 | + } |
| 297 | + |
| 298 | + /** |
| 299 | + * https://www.discogs.com/developers/index.html#page:user-lists,header:user-lists-list |
| 300 | + * @return array<string, mixed> |
| 301 | + * @throws Exception |
| 302 | + */ |
| 303 | + public function get_list(int $list_id): array |
| 304 | + { |
| 305 | + $query = sprintf("lists/%d", $list_id); |
| 306 | + |
| 307 | + return $this->_query_discogs($query); |
| 308 | + } |
| 309 | + |
| 310 | + /** |
| 311 | + * https://www.discogs.com/developers/#page:user-wantlist,header:user-wantlist-wantlist |
| 312 | + * @return array<string, mixed> |
| 313 | + * @throws Exception |
| 314 | + */ |
| 315 | + public function get_wantlist(string $username): array |
| 316 | + { |
| 317 | + $query = sprintf("users/%s/wants", $username); |
| 318 | + |
| 319 | + return $this->_query_discogs($query); |
201 | 320 | } |
202 | 321 | } |
0 commit comments