JolitaGrazyte / discogs-api

A simple Discogs Api Wrapper that uses Guzzle7.
MIT License
10 stars 6 forks source link

A simple php Discogs Api.

Latest Version on Packagist Software License Quality Score Total Downloads

This package makes it easy to communicate with discogs-api. It uses Guzzle 7 and is very simple to install and to use.

You can use it with any PHP framework or just simply in your naked PHP application.

However, if you want to use it in Laravel framework, I'd suggest to also install jolitagrazyte/laravel-discogs package, which provides a facade for even an easier way to play with it.

Installation

You can install the package via composer:

composer require jolitagrazyte/discogs-api

Usage

Endpoints with no authentication required

For the endpoints, where token is not required, first argument can be easily left empty.

$discogs = new DiscogsApi();

//get artist with id 1
$artist = $discogs->artist('1');

//get releases of the artist with id 1
$artistReleases = $discogs->artistReleases('1');

//get label with id 1 
$label = $discogs->label('1');

//get releases of the label with id 1
$labelReleases = $discogs->labelReleases('1');

//get release with id 1
$releases = $discogs->releases('1');

//get master release with id 1
$masterRelease = $discogs->masterRelease('1');

Endpoints where authentication is required

For the endpoints, where token is required, you must add your discogs-token.

You can obtain it at https://www.discogs.com/settings/developers.

Orders

To get your orders, you can use getMyOrders()-method.

Orders list comes paginated with a default - 50 orders per page, but it can be changed.

If you need, you can add some optional parameters: page, perPage (with a max of 100), order status as status, sort and sortOrder.

If you need more information about the parameters you can read about it at https://www.discogs.com/developers.

$discogs = new DiscogsApi('discogs-token', 'app-name');

//get orders
$orders = $discogs->getMyOrders();

/**
* get orders with parameters: 
* in this example page = 3, perPage = 25, status = shipped, sort = created, sortOrder = desc
*/
$ordersWithOptions = $discogs->getMyOrders(3, 25, "shipped", "created", "desc");

For getting one specific order by id:

$discogs = new DiscogsApi('discogs-token', 'app-name');

//get order with id
$order = $discogs->orderWithId('123');

It is also possible to retrieve the messages of an order:

$discogs = new DiscogsApi('discogs-token', 'app-name');

//get messages  of an order with id
$ordersMessages = $discogs->orderMessages('123');

For changing the status of the order or adding the shipping to the order.

$discogs = new DiscogsApi('discogs-token', 'app-name');

//change order status to 'Shipped'
$orders = $discogs->changeOrderStatus('123', 'Shipped');

//add shipping to an order with id
$order = $discogs->addShipping('123', '12.60');

Search

If you want to add some extra search parameters you can do it by first creating a SearchParameters object and then chaining as many options as you want.

$discogs = new DiscogsApi('discogs-token', 'app-name');

// create a SearchParameters object and chain some search paramater
$searchParameters = SearchParameters::make()->format('LP')->year('1996');

//do a search request with a query = 'MoWax' and passing the SearchParameters object
$searchResult = $discogs->search('MoWax', $searchParameters);

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@jolitagrazyte.com instead of using the issue tracker.

Credits

License

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