2017 © Pedro Peláez
 

library php-discogs-api

The Discogs API makes it easy for developers to communicate with the Discogs platform

image

ricbra/php-discogs-api

The Discogs API makes it easy for developers to communicate with the Discogs platform

  • Wednesday, June 20, 2018
  • by ricbra
  • Repository
  • 20 Watchers
  • 112 Stars
  • 3,631 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 46 Forks
  • 5 Open issues
  • 16 Versions
  • 5 % Grown

The README.md

Discogs Api

Build Status Latest Stable Version Total Downloads License Quality, (*1)

This library is a PHP 5.4 implementation of the Discogs API v2.0. The Discogs API is a REST-based interface. By using this library you don't have to worry about communicating with the API: all the hard work has already be done., (*2)

This API is build upon the shoulders of a giant: Guzzle 4.0. This is an absolutely awesome library., (*3)

Deprecated

This repository is outdated and not maintained anymore. Please see https://github.com/calliostro/php-discogs-api for a more up to date version., (*4)

License

This library is released under the MIT license. See the complete license in the LICENSE file., (*5)

Installation

Start by installing composer. Next do:, (*6)

$ composer require ricbra/php-discogs-api

Requirements

PHP >=5.4.0, (*7)

Usage

Creating a new instance is as simple as:, (*8)

<?php
$client = Discogs\ClientFactory::factory([]);

User-Agent

Discogs requires that you supply a User-Agent. You can do this easily:, (*9)

<?php
$client = Discogs\ClientFactory::factory([
    'defaults' => [
        'headers' => ['User-Agent' => 'your-app-name/0.1 +https://www.awesomesite.com'],
    ]
]);

Throttling

Discogs doesn't like it when you hit their API at a too high connection rate. Use the ThrottleSubscriber to prevent getting errors or banned:, (*10)

<?php

$client = Discogs\ClientFactory::factory();
$client->getHttpClient()->getEmitter()->attach(new Discogs\Subscriber\ThrottleSubscriber());

Authentication

Discogs API allow to access protected endpoints with either a simple Discogs Auth Flow or a more advanced (and more complex) Oauth Flow, (*11)

Discogs Auth

As stated in the Discogs Authentication documentation:, (*12)

In order to access protected endpoints, you’ll need to register for either a consumer key and secret or user token, depending on your situation: - To easily access your own user account information, use a User token. - To get access to an endpoint that requires authentication and build 3rd party apps, use a Consumer Key and Secret., (*13)

With the Discogs Php API you can add your credentials to each request by adding a query key to your own defaults like this:, (*14)

$client = ClientFactory::factory([
    'defaults' => [
        'query' => [
            'key' => 'my-key',
            'secret' => 'my-secret',
        ],
    ]
]);

OAuth

There are a lot of endpoints which require OAuth. Lucky for you using Guzzle this is peanuts. If you're having trouble obtaining the token and token_secret, please check out my example implementation., (*15)

<?php

$client = Discogs\ClientFactory::factory([]);
$oauth = new GuzzleHttp\Subscriber\Oauth\Oauth1([
    'consumer_key'    => $consumerKey, // from Discogs developer page
    'consumer_secret' => $consumerSecret, // from Discogs developer page
    'token'           => $token['oauth_token'], // get this using a OAuth library
    'token_secret'    => $token['oauth_token_secret'] // get this using a OAuth library
]);
$client->getHttpClient()->getEmitter()->attach($oauth);

$response = $client->search([
    'q' => 'searchstring'
]);

History

Another cool plugin is the History plugin:, (*16)

<?php

$client = Discogs\ClientFactory::factory([]);
$history = new GuzzleHttp\Subscriber\History();
$client->getHttpClient()->getEmitter()->attach($history);

$response = $client->search([
    'q' => 'searchstring'
]);

foreach ($history as $row) {
    print (string) $row['request'];
    print (string) $row['response'];
}

More info and plugins

For more information about Guzzle and its plugins checkout the docs., (*17)

Perform a search:

Per august 2014 a signed OAuth request is required for this endpoint., (*18)

<?php

$response = $client->search([
    'q' => 'Meagashira'
]);
// Loop through results
foreach ($response['results'] as $result) {
    var_dump($result['title']);
}
// Pagination data
var_dump($response['pagination']);

// Dump all data
var_dump($response->toArray());

Get information about a label:

<?php

$label = $service->getLabel([
    'id' => 1
]);

Get information about an artist:

<?php

$artist = $service->getArtist([
    'id' => 1
]);

Get information about a release:

<?php

$release = $service->getRelease([
    'id' => 1
]);

echo $release['title']."\n";

Get information about a master release:

<?php

$master  = $service->getMaster([
    'id' => 1
]);

echo $master['title']."\n";

Get image

Discogs returns the full url to images so just use the internal client to get those:, (*19)

php

$release = $client->getRelease([
    'id' => 1
]);
foreach ($release['images'] as $image) {
    $response = $client->getHttpClient()->get($image['uri']);
    // response code
    echo $response->getStatusCode();
    // image blob itself
    echo $client->getHttpClient()->get($image['uri'])->getBody()->getContents();
}

User Collection

Authorization is required when folder_id is not 0., (*20)

Get collection folders

<?php

$folders = $service->getCollectionFolders([
    'username' => 'example'
]);

Get collection folder

<?php

$folder = $service->getCollectionFolder([
    'username' => 'example',
    'folder_id' => 1
]);

Get collection items by folder

<?php

$items = $service->getCollectionItemsByFolder([
    'username' => 'example',
    'folder_id' => 3
]);

Documentation

Further documentation can be found at the Discogs API v2.0 Documentation., (*21)

Contributing

Implemented a missing call? PR's are welcome!, (*22)

Bitdeli Badge, (*23)

The Versions

20/06 2018

dev-master

9999999-dev

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

09/03 2018

1.4.0

1.4.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

27/02 2017

1.3.0

1.3.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

18/03 2016

1.2.0

1.2.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

17/10 2014

1.1.0

1.1.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

08/08 2014

1.0.3

1.0.3.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

06/08 2014

1.0.2

1.0.2.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

05/08 2014

1.0.1

1.0.1.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

05/08 2014

v1.0.0

1.0.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

18/07 2014

dev-deprecated

dev-deprecated

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

The Development Requires

by Richard van den Brand

api discogs

09/05 2014

v0.6

0.6.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs

19/12 2012

v0.5

0.5.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs

01/10 2012

v0.4

0.4.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs

17/09 2012

v0.3

0.3.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs

22/04 2012

v0.2

0.2.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs

12/04 2012

v0.1

0.1.0.0

The Discogs API makes it easy for developers to communicate with the Discogs platform

  Sources   Download

MIT

The Requires

 

by Richard van den Brand

api discogs