From 0a0858dac59dd81e5383bdc3e7e1f695b325cdc8 Mon Sep 17 00:00:00 2001 From: smiley Date: Tue, 5 Mar 2024 02:51:29 +0100 Subject: [PATCH] :octocat: examples cleanup --- examples/OAuthExampleSessionStorage.php | 2 +- .../GitHub/gist-spotify-top-tracks.php | 10 ++- examples/Providers/GitHub/github-common.php | 20 +----- examples/Providers/LastFM/cache/.gitkeep | 0 examples/Providers/LastFM/lastfm-common.php | 23 +------ .../Providers/LastFM/topalbum-patchwork.php | 64 +++++-------------- examples/Providers/LastFM/urlcache/.gitkeep | 0 .../Providers/Spotify/MixesDBTrackSearch.php | 27 ++------ examples/Providers/Spotify/SpotifyClient.php | 55 ++++++++-------- .../Providers/Spotify/SpotifyNewReleases.php | 29 ++------- examples/Providers/Spotify/mixesdb-scrape.php | 25 ++------ .../Spotify/mixesdb-track-search.php | 16 ++--- examples/Providers/Spotify/new-releases.php | 14 ++-- examples/Providers/Spotify/playlist-diff.php | 25 +++----- examples/Providers/Spotify/spotify-common.php | 22 ++----- .../Providers/provider-api-example-common.php | 17 ----- 16 files changed, 93 insertions(+), 256 deletions(-) create mode 100644 examples/Providers/LastFM/cache/.gitkeep create mode 100644 examples/Providers/LastFM/urlcache/.gitkeep delete mode 100644 examples/Providers/provider-api-example-common.php diff --git a/examples/OAuthExampleSessionStorage.php b/examples/OAuthExampleSessionStorage.php index c521df5..a5f2ca7 100644 --- a/examples/OAuthExampleSessionStorage.php +++ b/examples/OAuthExampleSessionStorage.php @@ -79,7 +79,7 @@ public function getAccessToken(string $service = null):AccessToken{ } } - throw new OAuthStorageException('token not found'); + throw new OAuthStorageException(sprintf('token for service "%s" not found', $service)); } } diff --git a/examples/Providers/GitHub/gist-spotify-top-tracks.php b/examples/Providers/GitHub/gist-spotify-top-tracks.php index a0aca46..ff9567c 100644 --- a/examples/Providers/GitHub/gist-spotify-top-tracks.php +++ b/examples/Providers/GitHub/gist-spotify-top-tracks.php @@ -8,11 +8,7 @@ * @license MIT */ -namespace chillerlan\OAuthAppExamples\GitHub; - use chillerlan\HTTP\Utils\MessageUtil; -use RuntimeException; -use function sprintf; /** * invoke the spotify client first @@ -22,12 +18,14 @@ require_once __DIR__.'/../Spotify/spotify-common.php'; /** - * @var \chillerlan\OAuth\Providers\GitHub $github - * @var \Psr\Log\LoggerInterface $logger + * @var \OAuthProviderFactory $factory + * @var \chillerlan\OAuth\Providers\GitHub $github */ require_once __DIR__.'/github-common.php'; +$logger = $factory->getLogger(); + $gistID = null; // set to null to create a new gist $gistname = '🎵 My Spotify Top Tracks'; $description = 'auto generated spotify track list'; diff --git a/examples/Providers/GitHub/github-common.php b/examples/Providers/GitHub/github-common.php index 185a8f7..7bcd717 100644 --- a/examples/Providers/GitHub/github-common.php +++ b/examples/Providers/GitHub/github-common.php @@ -6,27 +6,11 @@ * @license MIT */ -namespace chillerlan\OAuthAppExamples\GitHub; - -use chillerlan\OAuth\Core\AccessToken; use chillerlan\OAuth\Providers\GitHub; $ENVVAR = 'GITHUB'; -/** - * @var \Psr\Http\Client\ClientInterface $http - * @var \chillerlan\Settings\SettingsContainerInterface $options - * @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage - * @var \Psr\Log\LoggerInterface $logger - * @var string $CFGDIR - */ - require_once __DIR__.'/../../provider-example-common.php'; -$github = new GitHub($http, $options, $logger); -$github->setStorage($storage); - -if(!$storage->hasAccessToken('GitHub')){ - $token = (new AccessToken)->fromJSON(file_get_contents($CFGDIR.'/GitHub.token.json')); - $github->storeAccessToken($token); -} +/** @var \OAuthProviderFactory $factory */ +$github = $factory->getProvider(GitHub::class, $ENVVAR); diff --git a/examples/Providers/LastFM/cache/.gitkeep b/examples/Providers/LastFM/cache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/examples/Providers/LastFM/lastfm-common.php b/examples/Providers/LastFM/lastfm-common.php index 5a44139..56ee7e1 100644 --- a/examples/Providers/LastFM/lastfm-common.php +++ b/examples/Providers/LastFM/lastfm-common.php @@ -7,28 +7,11 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\LastFM; - -use chillerlan\OAuth\Core\AccessToken; use chillerlan\OAuth\Providers\LastFM; -use function file_get_contents; $ENVVAR = 'LASTFM'; -/** - * @var \Psr\Http\Client\ClientInterface $http - * @var \chillerlan\Settings\SettingsContainerInterface $options - * @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage - * @var \Psr\Log\LoggerInterface $logger - * @var string $CFGDIR - */ - -require_once __DIR__.'/../provider-api-example-common.php'; - -$lfm = new LastFM($http, $options, $logger); -$lfm->setStorage($storage); +require_once __DIR__.'/../../provider-example-common.php'; -if(!$storage->hasAccessToken()){ - $token = (new AccessToken)->fromJSON(file_get_contents(($CFGDIR ?? '').'/LastFM.token.json')); - $lfm->storeAccessToken($token); -} +/** @var \OAuthProviderFactory $factory */ +$lfm = $factory->getProvider(LastFM::class, $ENVVAR); diff --git a/examples/Providers/LastFM/topalbum-patchwork.php b/examples/Providers/LastFM/topalbum-patchwork.php index 5d7c4fc..d0e5b36 100644 --- a/examples/Providers/LastFM/topalbum-patchwork.php +++ b/examples/Providers/LastFM/topalbum-patchwork.php @@ -13,55 +13,16 @@ * @noinspection PhpComposerExtensionStubsInspection */ -namespace chillerlan\OAuthExamples\Providers\LastFM; - use chillerlan\HTTP\Utils\MessageUtil; -use Exception; -use function array_column; -use function array_shift; -use function count; -use function dirname; -use function file_exists; -use function file_get_contents; -use function file_put_contents; -use function header; -use function imagecolorallocate; -use function imagecopyresampled; -use function imagecreatefromgif; -use function imagecreatefromjpeg; -use function imagecreatefrompng; -use function imagecreatetruecolor; -use function imagedestroy; -use function imagefill; -use function imagejpeg; -use function imagesx; -use function imagesy; -use function intval; -use function json_decode; -use function json_encode; -use function max; -use function min; -use function mkdir; -use function parse_url; -use function sha1; -use function strlen; -use function substr; -use function trim; -use const JSON_PRETTY_PRINT; -use const PHP_URL_PATH; - -$ENVVAR = 'LASTFM'; /** - * @var \Psr\Log\LoggerInterface $logger * @var \chillerlan\OAuth\Providers\LastFM $lfm */ require_once __DIR__.'/lastfm-common.php'; -$urlcache = './urlcache'; -$imgcache = './cache'; // public access - +$urlcache = './urlcache'; // downloaded album covers +$imgcache = './cache'; // generated patchworks try{ $request = json_decode(file_get_contents('php://input')); @@ -115,13 +76,19 @@ continue; } - $path = getImage($img[(count($img) - 1)]->{'#text'}, $urlcache); - $ext = substr($path, (strlen($path) - 3)); - $res[] = match($ext){ - 'jpg' => imagecreatefromjpeg($path), - 'png' => imagecreatefrompng($path), - 'gif' => imagecreatefromgif($path), - }; + try{ + $path = getImage($img[(count($img) - 1)]->{'#text'}, $urlcache); + $ext = pathinfo($path, PATHINFO_EXTENSION); + + $res[] = match($ext){ + 'jpg' => imagecreatefromjpeg($path), + 'png' => imagecreatefrompng($path), + 'gif' => imagecreatefromgif($path), + }; + } + catch(Throwable){ + continue; + } } $patchwork = imagecreatetruecolor(($cols * $imageSize), ($rows * $imageSize)); @@ -160,7 +127,6 @@ exit; function getImage(string $url, string $urlcache):string{ - $path = parse_url($url, PHP_URL_PATH); if(file_exists($urlcache.$path)){ diff --git a/examples/Providers/LastFM/urlcache/.gitkeep b/examples/Providers/LastFM/urlcache/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/examples/Providers/Spotify/MixesDBTrackSearch.php b/examples/Providers/Spotify/MixesDBTrackSearch.php index 839b8bd..3c8d0a5 100644 --- a/examples/Providers/Spotify/MixesDBTrackSearch.php +++ b/examples/Providers/Spotify/MixesDBTrackSearch.php @@ -8,22 +8,7 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - use chillerlan\HTTP\Utils\MessageUtil; -use function array_column; -use function array_map; -use function array_merge; -use function explode; -use function file_get_contents; -use function implode; -use function json_decode; -use function preg_replace; -use function sprintf; -use function str_replace; -use function strtotime; -use function trim; -use function usleep; /** * @@ -35,11 +20,11 @@ class MixesDBTrackSearch extends SpotifyClient{ */ public function getTracks( string $clubnightsJSON, - int $since, - int $until, - array $find = [], - int $limit = 5, - bool $playlistPerSet = false, + int $since, + int $until, + array $find = [], + int $limit = 5, + bool $playlistPerSet = false, ):void{ $clubnights = json_decode(file_get_contents($clubnightsJSON), true); $tracks = []; @@ -69,7 +54,7 @@ public function getTracks( $this->logger->info(sprintf('search: %s', $track)); - $response = $this->spotify->request('/v1/search', [ + $response = $this->request('/v1/search', [ 'q' => $this->getSearchTerm($track), 'type' => 'track', 'limit' => $limit, diff --git a/examples/Providers/Spotify/SpotifyClient.php b/examples/Providers/Spotify/SpotifyClient.php index 5214376..c57db03 100644 --- a/examples/Providers/Spotify/SpotifyClient.php +++ b/examples/Providers/Spotify/SpotifyClient.php @@ -8,32 +8,23 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - use chillerlan\HTTP\Utils\MessageUtil; +use chillerlan\OAuth\OAuthOptions; use chillerlan\OAuth\Providers\Spotify; +use chillerlan\OAuth\Storage\MemoryStorage; +use chillerlan\OAuth\Storage\OAuthStorageInterface; +use chillerlan\Settings\SettingsContainerInterface; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; +use Psr\Http\Message\StreamFactoryInterface; +use Psr\Http\Message\UriFactoryInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -use RuntimeException; -use function array_chunk; -use function array_map; -use function array_values; -use function file_exists; -use function file_get_contents; -use function file_put_contents; -use function json_decode; -use function json_encode; -use function rtrim; -use function sprintf; -use function usleep; -use const JSON_PRETTY_PRINT; -use const JSON_UNESCAPED_SLASHES; -use const JSON_UNESCAPED_UNICODE; /** * */ -abstract class SpotifyClient{ +class SpotifyClient extends Spotify{ protected const sleepTimer = 250000; // sleep between requests (µs) @@ -43,13 +34,19 @@ abstract class SpotifyClient{ protected array $artists = []; protected array $albums = []; - /** - * - */ public function __construct( - protected Spotify $spotify, - protected LoggerInterface $logger = new NullLogger(), + OAuthOptions|SettingsContainerInterface $options, + ClientInterface $http, + RequestFactoryInterface $requestFactory, + StreamFactoryInterface $streamFactory, + UriFactoryInterface $uriFactory, + OAuthStorageInterface $storage = new MemoryStorage, + LoggerInterface $logger = new NullLogger ){ + parent::__construct($options, $http, $requestFactory, $streamFactory, $uriFactory, $storage, $logger); + + // set the servicename to the original provider's name so that we use the same tokens + $this->serviceName = 'Spotify'; $this->getMe(); } @@ -95,7 +92,7 @@ protected function loadFromFile(array $vars, string $dir):bool{ * fetch the currently authenticated user */ protected function getMe():void{ - $me = $this->spotify->request('/v1/me'); + $me = $this->me(); if($me->getStatusCode() !== 200){ throw new RuntimeException('could not fetch data from /me endpoint'); @@ -125,7 +122,7 @@ public function getFollowedArtists():array{ ]; do{ - $meFollowing = $this->spotify->request('/v1/me/following', $params); + $meFollowing = $this->request('/v1/me/following', $params); $data = MessageUtil::decodeJSON($meFollowing); if($meFollowing->getStatusCode() === 200){ @@ -167,7 +164,7 @@ public function getArtistReleases():array{ foreach($this->artists as $artistID => $artist){ // WTB bulk endpoint /artists/albums?ids=artist_id1,artist_id2,... - $artistAlbums = $this->spotify->request(sprintf('/v1/artists/%s/albums', $artistID), ['market' => $this->market]); + $artistAlbums = $this->request(sprintf('/v1/artists/%s/albums', $artistID), ['market' => $this->market]); if($artistAlbums->getStatusCode() !== 200){ $this->logger->warning(sprintf('could not fetch albums for artist "%s"', $artist->name)); @@ -212,7 +209,7 @@ public function getPlaylist(string $playlistID):array{ $retry = 0; do{ - $response = $this->spotify->request(sprintf('/v1/playlists/%s/tracks', $playlistID), $params); + $response = $this->request(sprintf('/v1/playlists/%s/tracks', $playlistID), $params); if($retry > 3){ throw new RuntimeException('error while retrieving playlist'); @@ -254,7 +251,7 @@ public function getPlaylist(string $playlistID):array{ */ public function createPlaylist(string $name, string $description):string{ - $createPlaylist = $this->spotify->request( + $createPlaylist = $this->request( path : sprintf('/v1/users/%s/playlists', $this->id), method : 'POST', body : [ @@ -296,7 +293,7 @@ public function addTracks(string $playlistID, array $trackIDs):static{ foreach($uris as $i => $chunk){ - $playlistAddTracks = $this->spotify->request( + $playlistAddTracks = $this->request( path : sprintf('/v1/playlists/%s/tracks', $playlistID), method : 'POST', body : ['uris' => $chunk], diff --git a/examples/Providers/Spotify/SpotifyNewReleases.php b/examples/Providers/Spotify/SpotifyNewReleases.php index 470e15a..9398927 100644 --- a/examples/Providers/Spotify/SpotifyNewReleases.php +++ b/examples/Providers/Spotify/SpotifyNewReleases.php @@ -8,22 +8,7 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - use chillerlan\HTTP\Utils\MessageUtil; -use function array_chunk; -use function array_column; -use function array_shift; -use function array_values; -use function date; -use function explode; -use function implode; -use function krsort; -use function mktime; -use function sprintf; -use function strtolower; -use function strtotime; -use function usleep; /** * @@ -36,12 +21,12 @@ class SpotifyNewReleases extends SpotifyClient{ * the script runner */ public function getNewReleases( - int $since, - int $until, - int $minTracks, - bool $skipVariousArtist, - bool $skipAppearsOn, - bool $fromCache, + int $since, + int $until, + int $minTracks, + bool $skipVariousArtist, + bool $skipAppearsOn, + bool $fromCache, string $cacheDir = __DIR__, ):void{ $loaded = $fromCache && $this->loadFromFile(['artists', 'albums'], $cacheDir); @@ -133,7 +118,7 @@ protected function getNewAlbumTracks(int $since, int $until):void{ // fetch the album tracks (why aren't the tracks in the albums response???) foreach(array_chunk(array_values($this->newAlbums), 20, true) as $chunk){ // API max = 20 albums - $albums = $this->spotify->request('/v1/albums', ['ids' => implode(',', $chunk), 'market' => $this->market]); + $albums = $this->request('/v1/albums', ['ids' => implode(',', $chunk), 'market' => $this->market]); $data = MessageUtil::decodeJSON($albums); if(!isset($data->albums)){ diff --git a/examples/Providers/Spotify/mixesdb-scrape.php b/examples/Providers/Spotify/mixesdb-scrape.php index c994109..d441ac6 100644 --- a/examples/Providers/Spotify/mixesdb-scrape.php +++ b/examples/Providers/Spotify/mixesdb-scrape.php @@ -16,30 +16,19 @@ * @noinspection PhpComposerExtensionStubsInspection */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - use chillerlan\HTTP\Utils\MessageUtil; -use DOMDocument; -use function file_put_contents; -use function json_encode; -use function libxml_use_internal_errors; -use function preg_match; -use function sprintf; -use function trim; -use function usleep; -use const JSON_PRETTY_PRINT; -use const JSON_UNESCAPED_SLASHES; -use const JSON_UNESCAPED_UNICODE; -use const XML_ELEMENT_NODE; /** - * @var \Psr\Http\Client\ClientInterface $http - * @var \Psr\Http\Message\RequestFactoryInterface $requestFactory + * @var \OAuthProviderFactory $factory + * @var \chillerlan\OAuth\Providers\Spotify $spotify * @var \Psr\Log\LoggerInterface $logger * @var string $file */ require_once __DIR__.'/spotify-common.php'; +$logger = $factory->getLogger(); +$requestFactory ??= $factory->getRequestFactory(); + $file ??= __DIR__.'/mixesdb-data.json'; $baseURL = 'https://www.mixesdb.com'; $catPath = '/db/index.php?title=Category:Clubnight'; @@ -53,7 +42,7 @@ // fetch the category page $catRequest = $requestFactory->createRequest('GET', $baseURL.$catPath); - $catResponse = $http->sendRequest($catRequest); + $catResponse = $spotify->sendRequest($catRequest); if($catResponse->getStatusCode() !== 200){ break; @@ -80,7 +69,7 @@ // fetch the page $pageRequest = $requestFactory->createRequest('GET', $baseURL.$page); - $pageResponse = $http->sendRequest($pageRequest); + $pageResponse = $spotify->sendRequest($pageRequest); if($pageResponse->getStatusCode() !== 200){ continue; diff --git a/examples/Providers/Spotify/mixesdb-track-search.php b/examples/Providers/Spotify/mixesdb-track-search.php index 776826f..53f9bbb 100644 --- a/examples/Providers/Spotify/mixesdb-track-search.php +++ b/examples/Providers/Spotify/mixesdb-track-search.php @@ -11,18 +11,13 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - -use function file_exists; -use function strtotime; - /** + * @var \OAuthProviderFactory $factory * @var \chillerlan\OAuth\Providers\Spotify $spotify - * @var \Psr\Http\Message\RequestFactoryInterface $requestFactory - * @var \Psr\Log\LoggerInterface $logger - * @var string $CFGDIR + * @var string $ENVVAR */ require_once __DIR__.'/spotify-common.php'; +require_once __DIR__.'/MixesDBTrackSearch.php'; $file = __DIR__.'/clubnights.json'; $since = strtotime('1990-05-05'); // first clubnight: 1990-05-05 @@ -35,8 +30,7 @@ include __DIR__.'/mixesdb-scrape.php'; } -$client = new MixesDBTrackSearch($spotify, $logger); - -$client->getTracks($file, $since, $until, $find, $limit, $playlistPerSet); +$spotify = $factory->getProvider(MixesDBTrackSearch::class, $ENVVAR); +$spotify->getTracks($file, $since, $until, $find, $limit, $playlistPerSet); exit; diff --git a/examples/Providers/Spotify/new-releases.php b/examples/Providers/Spotify/new-releases.php index 54f5115..1f096c0 100644 --- a/examples/Providers/Spotify/new-releases.php +++ b/examples/Providers/Spotify/new-releases.php @@ -12,17 +12,14 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - -use function strtotime; -use function time; - /** + * @var \OAuthProviderFactory $factory * @var \chillerlan\OAuth\Providers\Spotify $spotify - * @var \Psr\Log\LoggerInterface $logger + * @var string $ENVVAR */ require_once __DIR__.'/spotify-common.php'; +require_once __DIR__.'/SpotifyNewReleases.php'; $since = strtotime('last Saturday'); // (time() - 7 * 86400); // last week $until = time(); // adjust to your likes @@ -31,9 +28,8 @@ $skipVariousArtist = true; $fromCache = false; -$client = new SpotifyNewReleases($spotify, $logger); - -$client->getNewReleases($since, $until, $minTracks, $skipVariousArtist, $skipAppearsOn, $fromCache); +$spotify = $factory->getProvider(SpotifyNewReleases::class, $ENVVAR); +$spotify->getNewReleases($since, $until, $minTracks, $skipVariousArtist, $skipAppearsOn, $fromCache); /* // crawl for yearly album releases in the given range diff --git a/examples/Providers/Spotify/playlist-diff.php b/examples/Providers/Spotify/playlist-diff.php index c0fdb5a..ae7d9a5 100644 --- a/examples/Providers/Spotify/playlist-diff.php +++ b/examples/Providers/Spotify/playlist-diff.php @@ -8,28 +8,18 @@ * @license MIT */ -namespace chillerlan\OAuthExamples\Providers\Spotify; - -use function array_diff; -use function array_keys; -use function sprintf; - /** + * @var \OAuthProviderFactory $factory * @var \chillerlan\OAuth\Providers\Spotify $spotify - * @var \Psr\Http\Message\RequestFactoryInterface $requestFactory - * @var \Psr\Log\LoggerInterface $logger - * @var string $CFGDIR - * - * @phan-suppress PhanInvalidCommentForDeclarationType + * @var string $ENVVAR */ require_once __DIR__.'/spotify-common.php'; -$client = new class ($spotify, $logger) extends SpotifyClient{ - - public function playlistDiff(string $playlistID1, string $playlistID2, bool $createAsPlaylist = false):array{ - $p1 = array_keys($this->getPlaylist($playlistID1)); - $p2 = array_keys($this->getPlaylist($playlistID2)); +class PlaylistDiff extends SpotifyClient{ + public function diff(string $playlistID1, string $playlistID2, bool $createAsPlaylist = false):array{ + $p1 = array_keys($this->getPlaylist($playlistID1)); + $p2 = array_keys($this->getPlaylist($playlistID2)); $diff = array_diff($p1, $p2); if($createAsPlaylist){ @@ -45,4 +35,5 @@ public function playlistDiff(string $playlistID1, string $playlistID2, bool $cre }; -$client->playlistDiff('37i9dQZF1DX4UtSsGT1Sbe', '37i9dQZF1DXb57FjYWz00c', true); +$spotify = $factory->getProvider(PlaylistDiff::class, $ENVVAR); +$spotify->diff('37i9dQZF1DX4UtSsGT1Sbe', '37i9dQZF1DXb57FjYWz00c', true); diff --git a/examples/Providers/Spotify/spotify-common.php b/examples/Providers/Spotify/spotify-common.php index acdfaea..dd30048 100644 --- a/examples/Providers/Spotify/spotify-common.php +++ b/examples/Providers/Spotify/spotify-common.php @@ -10,26 +10,12 @@ namespace chillerlan\OAuthExamples\Providers\Spotify; -use chillerlan\OAuth\Core\AccessToken; use chillerlan\OAuth\Providers\Spotify; -use function file_get_contents; $ENVVAR = 'SPOTIFY'; -/** - * @var \Psr\Http\Client\ClientInterface $http - * @var \chillerlan\Settings\SettingsContainerInterface $options - * @var \chillerlan\OAuth\Storage\OAuthStorageInterface $storage - * @var \Psr\Log\LoggerInterface $logger - * @var string $CFGDIR - */ - -require_once __DIR__.'/../provider-api-example-common.php'; - -$spotify = new Spotify($http, $options, $logger); -$spotify->setStorage($storage); +require_once __DIR__.'/../../provider-example-common.php'; +require_once __DIR__.'/SpotifyClient.php'; -if(!$storage->hasAccessToken()){ - $token = (new AccessToken)->fromJSON(file_get_contents(($CFGDIR ?? '').'/Spotify.token.json')); - $spotify->storeAccessToken($token); -} +/** @var \OAuthProviderFactory $factory */ +$spotify = $factory->getProvider(Spotify::class, $ENVVAR); diff --git a/examples/Providers/provider-api-example-common.php b/examples/Providers/provider-api-example-common.php deleted file mode 100644 index 191e19d..0000000 --- a/examples/Providers/provider-api-example-common.php +++ /dev/null @@ -1,17 +0,0 @@ - - * @copyright 2023 smiley - * @license MIT - */ - -namespace chillerlan\OAuthExamples\Providers; - -use chillerlan\HTTP\Psr17\RequestFactory; - -require_once __DIR__.'/../provider-example-common.php'; - -$requestFactory = new RequestFactory;