Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
Started REST wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
CommandString committed May 24, 2023
1 parent 47080ee commit 4322425
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Rest/Albums.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Tnapf\Spotify\Rest;

use Tnapf\Spotify\Abstractions\Album\Album;
use Tnapf\Spotify\Enums\Method;
use Tnapf\Spotify\Http;

class Albums extends RestBase
{
public function get(string $id): Album
{
return $this->http->mapRequest(
Album::class,
Method::GET,
Http::BASE_URI."/albums/{$id}",
headers: $this->http->mergeHeaders()
);
}

/** @return Album[] */
public function getSeveral(string ...$ids): array
{
return $this->http->arrayMapRequest(
Album::class,
Method::GET,
Http::BASE_URI.'/albums?'.http_build_query(['ids' => implode(',', $ids)], '', '&'),
headers: $this->http->mergeHeaders(),
callback: static fn (array $array): array => $array['albums']
);
}
}
14 changes: 14 additions & 0 deletions src/Rest/RestBase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tnapf\Spotify\Rest;

use Tnapf\Spotify\Http;

class RestBase
{
public function __construct(
protected readonly Http $http
) {

}
}
20 changes: 20 additions & 0 deletions src/Rest/Tracks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tnapf\Spotify\Rest;

use Tnapf\Spotify\Abstractions\Track;
use Tnapf\Spotify\Enums\Method;
use Tnapf\Spotify\Http;

class Tracks extends RestBase
{
public function getTrack(string $id): Track
{
return $this->http->mapRequest(
Track::class,
Method::GET,
Http::BASE_URI."tracks/{$id}",
headers: $this->http->mergeHeaders()
);
}
}

0 comments on commit 4322425

Please sign in to comment.