baelorphp
php library for baelor.io., (*1)
Contents
Installation
$ composer install --no-dev -o, (*2)
Introduction
baelorphp is a php library for the baelor.io Taylor Swift API., (*3)
To obtain an API key for baelor.io, run the Create new API User example., (*4)
Quick Example
Let's load all of Taylor Swift's albums., (*5)
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., (*6)
Endpoints
Here is what we can do, also see the baelor.io docs for a full API endpoint list., (*7)
Create a user
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI();
$user = $api->createUser('myUsername', 'myEmail', 'myPassword');
$ourNewAPIKey = $user->api_key;
Login as existing user
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI();
$api->login('myUsername', 'myPassword');
$response = $api->getAlbums(); // Returns full set of Albums.
Get a single album
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$album = $api->getAlbums('1989');
Songs from that Album
Extending from the above example., (*8)
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$album = $api->getAlbums('1989');
$songs = $album->attributes;
All songs
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$songCollection = $api->getSongs();
Get a single song
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$song = $api->getSongs('style');
$length = $song->length; // We can access attributes directly.
Lyrics
Lyrics works slightly differently. But equally as easy., (*9)
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());
Bae Status
use Duffleman\baelor\BaelorAPI;
$api = new BaelorAPI('api-key');
$bae = $api->getBae('word');
// or
$bae = $api->getBae();
var_dump($bae);
Examples
Find the longest line in a song
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}.");
Credits
Baelor API created by Alex Forbes-Reed @0xdeafcafe, (*10)
baelorjs libary created by Jamie Davies @viralpickaxe, (*11)
baelorphp libary created by George Miller @duffleman, (*12)