duffleman/baelorphp

There is no license information available for the latest version (2.0.0) of this package.

PHP Wrapper for baelor.io API

2.0.0 2015-04-16 13:00 UTC

This package is not auto-updated.

Last update: 2022-08-04 13:41:44 UTC


README

php library for baelor.io.

Contents

Installation

$ composer install --no-dev -o

Introduction

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.

Quick 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.

Endpoints

Here is what we can do, also see the baelor.io docs for a full API endpoint list.

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.

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.

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

baelorjs libary created by Jamie Davies @viralpickaxe

baelorphp libary created by George Miller @duffleman