2017 © Pedro Peláez
 

library lastfm

Last.fm API client for PHP 7+

image

barryvanveen/lastfm

Last.fm API client for PHP 7+

  • Monday, October 9, 2017
  • by barryvanveen
  • Repository
  • 3 Watchers
  • 7 Stars
  • 369 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 9 Versions
  • 22 % Grown

The README.md

Last.fm API client for PHP 8

Latest Version on Packagist ![Software License][ico-license] Total Downloads, (*1)

API keys

You can create a last.fm API account at http://www.last.fm/api/account/create., (*2)

Installation

Via Composer, (*3)

``` bash $ composer require barryvanveen/lastfm, (*4)


## Laravel installation Add a LASTFM_API_KEY variable to your .env configuration. You could also publish the default configuration and alter it yourself: ```php php artisan vendor:publish --provider="Barryvanveen\Lastfm\LastfmServiceProvider"

Update config/app.php by adding the LastfmServiceProvider:, (*5)

'providers' => [
    ...
    Barryvanveen\Lastfm\LastfmServiceProvider::class,
];

If you are using Laravel 5.5 or higher, the service provider will be detected automagically by Laravel's package discovery., (*6)

Tested against Laravel 5.* but probably works in most versions because it is so simple. Please create an issue if it doesn't work for you., (*7)

Usage

Basic example

use Barryvanveen\Lastfm\Lastfm;
use GuzzleHttp\Client;

$lastfm = new Lastfm(new Client(), 'YourApiKey');

$albums = $lastfm->userTopAlbums('AnyUsername')->get();

Laravel example

use Barryvanveen\Lastfm\Lastfm;

public function index(Lastfm $lastfm)
{
    $albums = $lastfm->userTopAlbums('AnyUsername')->get();

    return view('home', compact('albums'));
}

All available methods

// Get top albums for user
$albums = $lastfm->userTopAlbums('AnyUsername')->get();

// Get top artists for user
$artists = $lastfm->userTopArtists('AnyUsername')->get();

// Get recent tracks for user
$tracks = $lastfm->userRecentTracks('AnyUsername')->get();

// Get user info
$info = $lastfm->userInfo('AnyUsername')->get();

// Get track that user is now listening to, or FALSE
$trackOrFalse = $lastfm->nowListening('AnyUsername'); 

// Get the weekly top albums given a starting day 
$albums = $lastfm->userWeeklyTopAlbums('AnyUsername', new \DateTime('2017-01-01'));                      

// Get the weekly top artists given a starting day 
$artists = $lastfm->userWeeklyTopArtists('AnyUsername', new \DateTime('2017-01-01'));

// Get the weekly top tracks given a starting day 
$tracks = $lastfm->userWeeklyTopTracks('AnyUsername', new \DateTime('2017-01-01'));

Filtering results

// Define time period for results
$lastfm->userTopAlbums('AnyUsername')
       ->period(Barryvanveen\Lastfm\Constants::PERIOD_WEEK)
       ->get();

// Limit number of results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->get();     

// Retrieve paginated results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->page(2)
       ->get();     

Valid time periods

// use these constants as an argument to ->period()
Barryvanveen\Lastfm\Constants::PERIOD_WEEK     = '7day';
Barryvanveen\Lastfm\Constants::PERIOD_MONTH    = '1month';
Barryvanveen\Lastfm\Constants::PERIOD_3_MONTHS = '3month';
Barryvanveen\Lastfm\Constants::PERIOD_6_MONTHS = '6month';
Barryvanveen\Lastfm\Constants::PERIOD_YEAR     = '12month';
Barryvanveen\Lastfm\Constants::PERIOD_OVERALL  = 'overall';

Official API docs

Read the official API documentation at http://www.last.fm/api., (*8)

Change log

Please see CHANGELOG for more information what has changed recently., (*9)

Testing

Copy phpunit.xml.dist to phpunit.xml. Then run the tests using:, (*10)

bash $ composer test, (*11)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*12)

Security

If you discover any security related issues, please email barryvanveen@gmail.com instead of using the issue tracker., (*13)

Credits

License

The MIT License (MIT). Please see License File for more information., (*14)

The Versions

09/10 2017

dev-master

9999999-dev https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

09/10 2017

v1.2.0

1.2.0.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

04/09 2017

dev-develop

dev-develop https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

04/09 2017

1.1.2

1.1.2.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

04/09 2017

1.1.1

1.1.1.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

04/09 2017

1.1.0

1.1.0.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

18/03 2017

1.0.2

1.0.2.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

14/03 2017

1.0.1

1.0.1.0 https://github.com/barryvanveen/lastfm

Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel api client php7 laravel5 service provider lastfm last.fm

13/03 2017

1.0.0

1.0.0.0 https://github.com/barryvanveen/lastfm

A Last.fm API client for PHP 7+

  Sources   Download

MIT

The Requires

 

The Development Requires

lastfm barryvanveen