Huge News!Announcing our $40M Series B led by Abstract Ventures.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 - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

5

HISTORY.md

@@ -0,1 +1,6 @@

0.2.0 / 2014-06-19
==================
* Implemented/fixed broken `image` function from `0.1.1`
* Added rate limiting header info to the callback params
0.1.1 / 2014-06-18

@@ -2,0 +7,0 @@ ==================

37

lib/client.js

@@ -32,3 +32,3 @@ var http = require('http'),

customHeaders: {
'Accept': 'application/json',
'Accept': 'application/json; application/octet-stream',
'Accept-Encoding': 'gzip,deflate',

@@ -158,3 +158,4 @@ 'User-Agent': 'DisConnectClient/'+package.version

urlParts = url.parse(options.url),
oauth = options.oauth||this.oauth;
oauth = options.oauth||this.oauth,
encoding = options.encoding||'utf8';

@@ -198,15 +199,30 @@ // Build request headers

var data = '',
rateLimit = null,
add = function(chunk){ data += chunk.toString(); },
parse = function(){ (typeof callback === 'function')&&callback(null, data); };
passData = function(){ (typeof callback === 'function')&&callback(null, data, rateLimit); };
// Set encoding
res.setEncoding(encoding);
// Find and add rate limiting when present
if(res.headers['x-ratelimit-type']){
rateLimit = {
type: res.headers['x-ratelimit-type'],
limit: res.headers['x-ratelimit-limit'],
reset: res.headers['x-ratelimit-reset'],
remaining: res.headers['x-ratelimit-remaining']
};
}
// Get the response content and pass it to the callback
switch(res.headers['content-encoding']){
case 'gzip':
var gunzip = zlib.createGunzip().on('data', add).on('end', parse);
var gunzip = zlib.createGunzip().on('data', add).on('end', passData);
res.pipe(gunzip);
break;
case 'deflate':
var inflate = zlib.createInflate().on('data', add).on('end', parse);
var inflate = zlib.createInflate().on('data', add).on('end', passData);
res.pipe(inflate);
break;
default:
res.on('data', add).on('end', parse);
res.on('data', add).on('end', passData);
}

@@ -222,3 +238,3 @@ }).on('error', function(err){

/**
* Send a request and parse the JSON response data
* Send a request and parse text response to JSON
* @param {Object|String} options - Request options or just the URL as a string for a quick GET

@@ -235,4 +251,7 @@ * {

(typeof options === 'string')&&(options = {url: options});
return this._rawRequest(options, function(err, data){
(typeof callback === 'function')&&callback(err, (data ? JSON.parse(data) : null));
return this._rawRequest(options, function(err, data, rateLimit){
if((typeof options === 'string') || (options.encoding !== 'binary')){
data = JSON.parse(data)
}
(typeof callback === 'function')&&callback(err, data, rateLimit);
});

@@ -239,0 +258,0 @@ };

@@ -94,3 +94,3 @@ var util = require('./util.js');

if(client.authenticated()){
client.get('/images/'+file, callback);
client.get({url: '/image/'+file, encoding: 'binary'}, callback);
}else{

@@ -97,0 +97,0 @@ callback(new Error('You must be authenticated in order to retrieve an image.'));

{
"name": "disconnect",
"description": "Easy to use client with OAuth support to connect with the discogs.com API v2.0",
"version": "0.1.1",
"keywords": [
"discogs",
"api",
"client",
"oauth"
],
"description": "Easy to use client to connect with the discogs.com API v2.0",
"version": "0.2.0",
"keywords": ["discogs", "api", "client", "oauth"],
"homepage": "https://github.com/bartve/disconnect",
"bugs": "https://github.com/bartve/disconnect/issues",
"license": "MIT",
"author": "Bart van Eijck <voodoo107@hotmail.com>",
"main": "index.js",

@@ -15,6 +14,2 @@ "directories": {

},
"author": {
"name": "Bart van Eijck",
"email": "voodoo107@hotmail.com"
},
"repository": {

@@ -24,3 +19,3 @@ "type": "git",

},
"license": "MIT",
"scripts": {},
"dependencies": {

@@ -32,13 +27,3 @@ "oauth-1.0a": "0.1.x"

"node": ">= 0.10.0"
},
"bugs": {
"url": "https://github.com/bartve/disconnect/issues"
},
"homepage": "https://github.com/bartve/disconnect",
"readme": "## About\r\n\r\n`disconnect` is a [Node.js](http://www.nodejs.org) client library that connects with the [Discogs.com API v2.0](http://www.discogs.com/developers/).\r\n\r\n## Features\r\n\r\n * Covers all API endpoints (well, soon anyway ;)\r\n * All functions implement the standard `function(err, data)` format for the callback\r\n * Includes OAuth 1.0a tools. Just plug in your consumer key and secret and do the OAuth dance\r\n * API functions grouped in their own namespace for easy access and isolation\r\n \r\n## Todo\r\n\r\n * Add collection folder functions (soon)\r\n * Add [rate limiting](http://www.discogs.com/developers/accessing.html#rate-limiting) support\r\n * Add tests\r\n\r\n## Installation\r\n\r\n`$ npm install disconnect`\r\n\r\n## Structure\r\nThe global structure of `disconnect` looks as follows:\r\n```\r\nrequire('disconnect') -> new Client() -> database()\r\n -> marketplace()\r\n -> user() -> collection()\r\n -> wantlist()\r\n -> util\r\n```\r\nTo get the user wantlist functions: \r\n```javascript\r\nvar Discogs = require('disconnect').Client;\r\nvar wantlist = new Discogs().user().wantlist();\r\n```\r\nMore examples below.\r\n\r\n## Usage\r\n\r\n### Basic\r\nHere are some basic usage examples that connect with the public API. Error handling has been left out for demonstrational purposes.\r\n\r\n#### Init\r\n\r\n```javascript\r\nvar Discogs = require('disconnect').Client;\r\n```\r\n#### Go\r\n\r\nGet release data\r\n```javascript\r\napp.get('/release/:id', function(req, res){\r\n\tvar db = new Discogs().database();\r\n\tdb.release(req.params.id, function(err, data){\r\n\t\tres.send(data);\r\n\t});\r\n});\r\n```\r\n\r\nGet page 2 of user's public collection showing 75 releases.\r\nThe second param is the collection folder ID where 0 is always the \"All\" folder.\r\n```javascript\r\napp.get('/collection/:user', function(req, res){\r\n\tvar col = new Discogs().user().collection();\r\n\tcol.releases(req.params.user, 0, {page:2, per_page:75}, function(err, data){\r\n\t\tres.send(data);\r\n\t});\r\n});\r\n```\r\n\r\nEasy!\r\n\r\n### OAuth\r\nBelow are the steps that involve getting a valid OAuth access token from Discogs.\r\n\r\n#### 1. Get a request token\r\n```javascript\r\napp.get('/authorize', function(req, res){\r\n\tvar dis = new Discogs();\r\n\tdis.getRequestToken(\r\n\t\t'CONSUMER_KEY', \r\n\t\t'CONSUMER_SECRET', \r\n\t\t'http://your-script-url/callback', \r\n\t\tfunction(err, requestData){\r\n\t\t\t// Persist \"requestData\" here so that the callback handler can \r\n\t\t\t// access it later after returning from the authorize url\r\n\t\t\tres.redirect(requestData.authorizeUrl);\r\n\t\t}\r\n\t);\r\n});\r\n```\r\n#### 2. Authorize\r\nAfter redirection to the Discogs authorize URL in step 1, authorize the application.\r\n\r\n#### 3. Get an access token\r\n```javascript\r\napp.get('/callback', function(req, res){\r\n\tvar dis = new Discogs();\r\n\tdis.getAccessToken(\r\n\t\trequestData, \r\n\t\treq.query.oauth_verifier, // Verification code sent back by Discogs\r\n\t\tfunction(err, accessData){\r\n\t\t\t// From this point on we no longer need \"requestData\", so it can be deleted\r\n\t\t\t// Persist \"accessData\" here so that it can be used to make further OAuth calls \r\n\t\t\tres.send('Received access token!');\r\n\t\t}\r\n\t);\r\n});\r\n```\r\n#### 4. Make OAuth calls\r\n```javascript\r\napp.get('/identity', function(req, res){\r\n\tvar dis = new Discogs(accessData);\r\n\tdis.identity(function(err, data){\r\n\t\tres.send(data);\r\n\t});\r\n});\r\n```\r\n\r\nNow that wasn't too hard, was it?\r\n\r\n## Resources\r\n\r\n * [Discogs API 2.0 documentation](http://www.discogs.com/developers/)\r\n * [The OAuth Bible](http://oauthbible.com/)\r\n\r\n## License\r\n\r\nMIT",
"readmeFilename": "README.md",
"_id": "disconnect@0.1.0",
"scripts": {},
"_shasum": "a420a4a24288a1a5aed329555620b0db63f42921",
"_from": "disconnect@"
}
}
}

@@ -1,4 +0,1 @@

[![NPM version](https://badge.fury.io/js/disconnect.svg)](http://badge.fury.io/js/disconnect)
[![Dependency Status](https://david-dm.org/bartve/disconnect.png)](https://david-dm.org/bartve/disconnect)
## About

@@ -8,6 +5,9 @@

[![NPM version](https://badge.fury.io/js/disconnect.svg)](http://badge.fury.io/js/disconnect) [![Dependency Status](https://david-dm.org/bartve/disconnect.png)](https://david-dm.org/bartve/disconnect)
## Features
* Covers all API endpoints
* All functions implement the standard `function(err, data)` format for the callback
* Supports [pagination](http://www.discogs.com/developers/accessing.html#pagination), [rate limiting](http://www.discogs.com/developers/accessing.html#rate-limiting), etc.
* All functions implement a standard `function(err, data, rateLimit)` format for the callback
* Includes OAuth 1.0a tools. Just plug in your consumer key and secret and do the OAuth dance

@@ -18,4 +18,3 @@ * API functions grouped in their own namespace for easy access and isolation

* Add [rate limiting](http://www.discogs.com/developers/accessing.html#rate-limiting) support
* Add tests
* Add tests!

@@ -117,2 +116,3 @@ ## Installation

```
#### 4. Make OAuth calls

@@ -133,2 +133,19 @@ Simply provide the constructor with the access data object persisted in step 3.

### Images
Image requests require authentication and are subject to [rate limiting](http://www.discogs.com/developers/accessing.html#rate-limiting).
```javascript
app.get('/image/:filename', function(req, res){
var db = new Discogs(accessData).database(),
file = req.params.filename;
db.image(file, function(err, data, rateLimit){
// Data contains the raw binary image data
require('fs').writeFile(file, data, 'binary', function(err){
// See your current limits
console.log(rateLimit);
res.send('Image saved!');
});
});
});
```
## Resources

@@ -135,0 +152,0 @@

Sorry, the diff of this file is not supported yet

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