New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

disconnect

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disconnect

Easy to use client with OAuth support to connect with the discogs.com API v.2.0

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
212
increased by17.78%
Maintainers
1
Weekly downloads
 
Created
Source

About

disconnect is a Node.js client library that connects with the Discogs.com API v2.0.

Features

  • Covers all API endpoints (well, soon anyway ;)
  • All functions implement the standard function(err, data) format for the callback
  • Includes OAuth 1.0a tools. Just plug in your consumer key and secret and do the OAuth dance
  • API functions grouped in their own namespace for easy access and isolation

Todo

  • Add collection folder functions (soon)
  • Add rate limiting support
  • Add tests

Installation

$ npm install disconnect

Structure

The global structure of disconnect looks as follows:

require('disconnect') -> new Client() -> database()
                                      -> marketplace()
                                      -> user() -> collection()
                                                -> wantlist()
                      -> util

To get the user wantlist functions:

var Discogs = require('disconnect').Client;
var wantlist = new Discogs().user().wantlist();

More examples below.

Usage

Basic

Here are some basic usage examples that connect with the public API. Error handling has been left out for demonstrational purposes.

Init
var Discogs = require('disconnect').Client;
Go

Get release data

app.get('/release/:id', function(req, res){
	var db = new Discogs().database();
	db.release(req.params.id, function(err, data){
		res.send(data);
	});
});

Get page 2 of user's public collection showing 75 releases. The second param is the collection folder ID where 0 is always the "All" folder.

app.get('/collection/:user', function(req, res){
	var col = new Discogs().user().collection();
	col.releases(req.params.user, 0, {page:2, per_page:75}, function(err, data){
		res.send(data);
	});
});

Easy!

OAuth

Below are the steps that involve getting a valid OAuth access token from Discogs.

1. Get a request token
app.get('/authorize', function(req, res){
	var dis = new Discogs();
	dis.getRequestToken(
		'CONSUMER_KEY', 
		'CONSUMER_SECRET', 
		'http://your-script-url/callback', 
		function(err, requestData){
			// Persist "requestData" here so that the callback handler can 
			// access it later after returning from the authorize url
			res.redirect(requestData.authorizeUrl);
		}
	);
});
2. Authorize

After redirection to the Discogs authorize URL in step 1, authorize the application.

3. Get an access token
app.get('/callback', function(req, res){
	var dis = new Discogs();
	dis.getAccessToken(
		requestData, 
		req.query.oauth_verifier, // Verification code sent back by Discogs
		function(err, accessData){
			// From this point on we no longer need "requestData", so it can be deleted
			// Persist "accessData" here so that it can be used to make further OAuth calls 
			res.send('Received access token!');
		}
	);
});
4. Make OAuth calls
app.get('/identity', function(req, res){
	var dis = new Discogs(accessData);
	dis.identity(function(err, data){
		res.send(data);
	});
});

Now that wasn't too hard, was it?

Resources

License

MIT

Keywords

FAQs

Package last updated on 17 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc