CollectionsCollections Database

Discogs Javascript library

The Discogs Javascript library is a wrapper for the Discogs API.

The source code is available in the GitHub repository.

app.api.discogs
The library is accessible from the app.api.discogs object.
search(query app.query object) array of search results
The function searches releases and returns an array of search results.
getRelease(id integer) release
The function gets a release by ID. It returns a release or undefined if it doesn't exist.
releaseClass class
Set a custom class for the release, the class must extend app.classes.api.discogs.release
// Discogs search (1.0)
// https://github.com/risolvipro/collections

let results = app.api.discogs.search(app.query);
app.result(results);

Release

app.classes.api.discogs.release
This class manages a release.
data json
The Json data returned by the API.
id integer
ID of the release.
title string
Title of the release.
artists array of document builders
Artists as an array of document builders.
imageURL string
Image URL for the release.
requestImage() image
Request the image for the release, it returns an image object or undefined if the request fails.
tracklist array of document builders
Tracklist as an array of document builders.
genres array of list item suggestions
Genres as an array of list item suggestions.
styles array of list item suggestions
Styles as an array of list item suggestions.
format list item suggestions
Format as a list item suggestion (CD, Vinyl, ...)
year integer
Year as an integer number.
configureArtist(artist document, data json)
Implement this method in your custom class to configure an artist before it's added to the artists array.
configureTrack(track document, data json)
Implement this method in your custom class to configure a track before it's added to the tracklist array.
// Discogs document (1.0)
// https://github.com/risolvipro/collections

let release = app.api.discogs.getRelease(app.params.id);

if(release == undefined) {
    app.fail();
}

let builder = app.document.builder();

builder.setString(release.title, "title");
builder.setDocuments(release.artists, "artists");
builder.setImage(release.requestImage(), "cover");
builder.setManagedDocuments(release.tracklist, "tracks");
builder.setListItem(release.format, "format");
builder.setListItems(release.genres, "genre");
builder.setListItems(release.styles, "style");
builder.setInteger(release.year, "year");
builder.setString(app.params.barcode, "barcode");

app.result(builder);