metalmatze / lastfm-api-wrapper
Dead simple wrapper for the Last.fm API which returns the json.
Requires
- php: >=5.3.0
- kriswallsmith/buzz: dev-master
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2016-02-11 09:27:18 UTC
README
Introduction
When I searched for an awesome PHP Class that could make it easy to access the lastfm api I found dandelionmood/lastfm.
Sadly I could not test with this class. So I started to modify it and came up with this.
Instead of setting the api key when creating an new instance, which is bad for
dependency injection, I injecet the Buzz\Browser. To set the api key use the
setApiKey($key)
method.
For now there is no authentication build in.
The key idea is that the official documentation is very good, and you shoudn't need anything else to work with the API.
Installation
You should install it through Composer / Packagist, because … Well, it's awesome !
The package is available here on Packagist.
Standard methods
Let's dive into the meat of this project. First, you need to register your application to key an API key and secret.
Once it's done, here's how you get an instance to work with :
$lastfm = new \MetalMatze\LastFm\LastFm(new \Buzz\Browser); $lastfm->setApiKey('73af4867ed96f8631cc43145c87d276e');
Now let's say you want to get info on a given artist ? If you look into the
API documentation, you can find the method artist.getInfo
that will
give us what we need (see here).
// Note that the dot is replaced by an underscore in the PHP API. $pink_floyd = $lastfm->artist_getInfo( array( 'artist' => 'Pink Floyd' ) );
What you'll get in return is a standard PHP Object.
Last words
The unit tests can be found in tests/MetalMatze/LastFm/LastFmUnitTest.php
to run them start PHPUnit with ./phpunit
.