php library for baelor.io.
$ composer install --no-dev -o
baelorphp is a php library for the baelor.io Taylor Swift API.
To obtain an API key for baelor.io, run the Create new API User example.
Let's load all of Taylor Swift's albums.
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$albumCollection = $api->getAlbums();
You can also wrap it around try/catch tags to see what (if any) errors are thrown.
Here is what we can do, also see the baelor.io docs for a full API endpoint list.
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI();
$user = $api->createUser('myUsername', 'myEmail', 'myPassword');
$ourNewAPIKey = $user->api_key;
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI();
$api->login('myUsername', 'myPassword');
$response = $api->getAlbums(); // Returns full set of Albums.
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$album = $api->getAlbums('1989');
Extending from the above example.
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$album = $api->getAlbums('1989');
$songs = $album->attributes;
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$songCollection = $api->getSongs();
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$song = $api->getSongs('style');
$length = $song->length; // We can access attributes directly.
Lyrics works slightly differently. But equally as easy.
use Duffleman\baelor\BaelorAPI;
use Duffleman\baelor\Results\Lyrics;
$api = new BaelorAPI('api-key');
$song = $api->getSongs('style');
$lyrics = new Lyrics($song, $api);
echo($lyrics->toHTML());
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$bae = $api->getBae('word');
// or
$bae = $api->getBae();
var_dump($bae);
use Duffleman\baelor\BaelorAPI;
use Duffleman\baelor\Results\Lyrics;
$api = new BaelorAPI('api-key');
$song = $api->getSongs('style');
$lyrics = new Lyrics($song, $api);
$lines = $lyrics->toArray(true); // true because we do want to strip empty lines.
$longestLength = 0;
$longestLine = '';
foreach($lines as $line) {
$lineLength = strlen($line);
if($lineLength > $longestLength) {
$longestLength = $lineLength;
$longestLine = $line;
}
}
echo("The longest line is {$lineLength} characters long. It reads: {$longestLine}.");
Baelor API created by Alex Forbes-Reed @0xdeafcafe
baelorjs libary created by Jamie Davies @viralpickaxe
baelorphp libary created by George Miller @duffleman