GithubHelp home page GithubHelp logo

parrfolio / discojs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aknorw/discojs

0.0 1.0 0.0 141 KB

Easiest way to use the Discogs API in Javascript :musical_note:

License: MIT License

JavaScript 100.00%

discojs's Introduction

Discojs

Easiest way to use the Discogs API in Javascript ๐ŸŽต

CircleCI Coverage Status

Installation

npm install --save discojs

Usage example

import Discojs from 'discojs'

const client = new Discojs({
  userToken: process.env.USER_TOKEN,
})

// Methods return promises

client
  .searchArtist('Jacob Desvarieux')
  .then((data) => {
    doSomethingWith(data)
  })
  .catch((error) => {
    console.warn('Oops, something went wrong!', error)
  })

// If you're using ES7, you can use async functions

async function notifyShipmentForOrder(orderId) {
  const result = await client.sendMessageForOrder(orderId, {
    message: 'Your order is dispatched!',
    status: 'Shipped',
  })
  return result.timestamp
}

// Just chain methods!

client
  .getIdentity()
  .then((identity) => {
    const { username } = identity
    return client.addToWantlist({
      username,
      releaseId: 1189932,
      notes: 'Must buy this!',
      rating: 4,
    })
  })
  .then((data) => {
    console.log(data)
  })
  .catch((error) => {
    console.warn(error)
  })

API Reference

Discojs instance

const options = {
  userAgent,
  outputFormat,
  userToken,
  consumerKey,
  consumerSecret,
  requestLimit,
  requestLimitAuth,
  requestLimitInterval,
  fetchOptions,
}

const client = new Discojs(options)
Key Type Default Details
userAgent string Discojs/1.1.0
outputFormat string discogs Must be discogs, plaintext or html
userToken string - For auth purposes
consumerKey string - For auth purposes
consumerSecret string - For auth purposes
requestLimit int 25 For API throttling purposes when not authenticated
requestLimitAuth int 60 For API throttling purposes when authenticated
requestLimitInterval int 60000
fetchOptions object {} Options to be passed to fetch

Methods

Documentation about methods is available in the wiki.

Tests

As several methods need authentication, you'll need 2 environment variables: DGS_USERNAME and USER_TOKEN.

Create a .env file at the root of the directory, and add the following lines:

DGS_USERNAME=0ctocat
USER_TOKEN=7h1515myu53r70k3n

โš ๏ธ Use a test account as public information will be edited.

As stated by Discogs API, some methods need a seller account. As I do not have one, I could not test them (which explains the coverage).

npm run test

When running tests, go grab a cup of coffee as this may be long because of Discogs API rate limiting.

Credits

Inspired by disconnect from @bartve

discojs's People

Contributors

aknorw avatar parrfolio avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.