2017 © Pedro Peláez
 

library last-fm-client

image

snapshotpl/last-fm-client

  • Wednesday, January 7, 2015
  • by snapshotpl
  • Repository
  • 2 Watchers
  • 1 Stars
  • 25 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 4 % Grown

The README.md

LastFmClient

Modern Last.fm API client for php, (*1)

Last.fm API documentation, (*2)

Usage

You can call API methods using existing services:, (*3)

<?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:, (*4)

$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:, (*5)

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

$timestamp is optional and can be integer with timestamp time or DateTime object., (*6)

You can scrobble multiple tracks in one request:, (*7)

$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:, (*8)

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

In callback url you will receive query string parameter token., (*9)

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

More information: * http://www.lastfm.pl/api/webauth * http://www.lastfm.pl/api/authspec, (*10)

Transport

To make calls in API we provide simple CURL transport. We have in plan implements others transports like: * Guzzle * Httpfull * Zend\Http, (*11)

To use own transport just implement LastFmClient\Transport\TransportInterface, (*12)

Installation

Add to composer.json:, (*13)

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

The Versions

07/01 2015

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *

 

06/01 2015

1.0

1.0.0.0

  Sources   Download

The Requires

  • php >=5.4.0
  • ext-curl *
  • ext-json *