snapshotpl/last-fm-client

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

1.0 2015-01-06 15:44 UTC

This package is auto-updated.

Last update: 2024-10-29 04:04:01 UTC


README

Modern Last.fm API client for php

Last.fm API documentation

Usage

You can call API methods using existing services:

<?php

require __DIR__ . '/vendor/autoload.php';

$auth = new LastFmClient\Auth();
$auth->setApiKey('your-api-key');
$auth->setSecret('your-secret');
$auth->setToken('user-token');
$auth->setSession('user-session');

$transport = new LastFmClient\Transport\Curl();

$client = new LastFmClient\Client($auth, $transport);

$trackService = new LastFmClient\Service\Track();
$trackService->setClient($client);

$response = $trackService->getInfo('Numb', 'Linkin Park');

var_dump($response->getData());

If you want to call custom method use LastFmClient\Client:

$client->call('resource.getAwesomeness', [], LastFmClient\Transport\TransportInterface::METHOD_GET);

How to scrobble?

It's very simple! Prepare LastFmClient\Auth object with api key, secret, token and session key. Then just call method from LastFmClient\Service\Track:

$trackService->scrobble('Seven Lions', 'Days to Come', $timestamp);

$timestamp is optional and can be integer with timestamp time or DateTime object.

You can scrobble multiple tracks in one request:

$trackService->scrobbleBatch([
    [
        'artist' => 'Linkin Park',
        'track' => 'Numb',
        'timestamp' => time()-1000,
    ],
    [
        'artist' => 'Seven Lions',
        'track' => 'Days to Come',
        'timestamp' => time()-1200,
    ],
]);

How to get Token and Session

You need to redirect user to auth page in Last.Fm:

$url = $client->getAuthUrl();
header('Location: '.$url);

In callback url you will receive query string parameter token.

$authService = LastFmClient\Service\Auth();
$authService->setClient($client);
$data = $authService->getSession()->getData();
var_dump($data);

More information:

Transport

To make calls in API we provide simple CURL transport. We have in plan implements others transports like:

  • Guzzle
  • Httpfull
  • Zend\Http

To use own transport just implement LastFmClient\Transport\TransportInterface

Installation

Add to composer.json:

{
    "require": {
        "snapshotpl/last-fm-client": "~1.0"
    }
}