Skip to content

Commit

Permalink
Added all but get recommendations bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
CommandString committed May 24, 2023
1 parent 35188fd commit 1526442
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions src/Rest/Tracks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,71 @@

namespace Tnapf\Spotify\Rest;

use Tnapf\Spotify\Abstractions\Track;
use Tnapf\Spotify\Abstractions\Tracks\AudioAnalysis\AudioAnalysis;
use Tnapf\Spotify\Abstractions\Tracks\AudioFeatures;
use Tnapf\Spotify\Abstractions\Tracks\Track;
use Tnapf\Spotify\Enums\Method;
use Tnapf\Spotify\Http;

class Tracks extends RestBase
{
public function getTrack(string $id): Track
public function get(string $id, ?string $market = null): Track
{
return $this->http->mapRequest(
Track::class,
Method::GET,
Http::BASE_URI."tracks/{$id}",
Endpoint::bind(Endpoint::TRACKS_ID, compact('id'), market: $market),
headers: $this->http->mergeHeaders()
);
}

/** @return Track[] */
public function getSeveral(array $ids, ?string $market = null): array
{
$ids = implode(',', $ids);

return $this->http->arrayMapRequest(
Track::class,
Method::GET,
Endpoint::bind(Endpoint::TRACKS, getParams: compact('ids'), market: $market),
headers: $this->http->mergeHeaders(),
callback: static fn (array $data) => $data['tracks']
);
}

public function getAudioFeatures(string $id): AudioFeatures
{
return $this->http->mapRequest(
AudioFeatures::class,
Method::GET,
Endpoint::bind(Endpoint::TRACK_AUDIO_FEATURES_ID, compact('id')),
headers: $this->http->mergeHeaders()
);
}

/** @return AudioFeatures[] */
public function getSeveralAudioFeatures(array $ids): array
{
$ids = implode(',', $ids);

return $this->http->arrayMapRequest(
AudioFeatures::class,
Method::GET,
Endpoint::bind(Endpoint::TRACK_AUDIO_FEATURES, getParams: compact('ids')),
headers: $this->http->mergeHeaders(),
callback: static fn (array $data) => $data['audio_features']
);
}

/** @return AudioAnalysis[] */
public function getAudioAnalysis(string $id): AudioAnalysis
{
return $this->http->mapRequest(
AudioAnalysis::class,
Method::GET,
Endpoint::bind(Endpoint::TRACK_AUDIO_ANALYSIS, compact('id')),
headers: $this->http->mergeHeaders()
);
}

// TODO: Add Get Recommendations
}

0 comments on commit 1526442

Please sign in to comment.