From 0b9362d4468c5f1e2870aa4306244c50a2a9b3fe Mon Sep 17 00:00:00 2001 From: Bart van Eijck Date: Mon, 20 Oct 2014 10:20:08 +0200 Subject: [PATCH] 0.4.2 --- HISTORY.md | 5 +++++ lib/client.js | 21 +++++++++++---------- lib/database.js | 4 ++-- package.json | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ee13fd6..c6f2d93 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +0.4.2 / 2014-10-20 +================== + * Fixed `this` scoping in `about()` + * Switched from `http` to the newly implemented `https` Discogs API connection for added security + 0.4.1 / 2014-10-16 ================== * Fixed "Unexpected token u" error when trying to parse an `undefined` response value to JSON diff --git a/lib/client.js b/lib/client.js index 9db7f88..0c00c1e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,6 +1,6 @@ 'use strict'; -var http = require('http'), +var https = require('https'), zlib = require('zlib'), url = require('url'), queryString = require('querystring'), @@ -28,10 +28,10 @@ var merge = function(target, source){ var config = { host: 'api.discogs.com', - oauthRequestUrl: 'http://api.discogs.com/oauth/request_token', - oauthAccessUrl: 'http://api.discogs.com/oauth/access_token', - oauthAuthorizeUrl: 'http://www.discogs.com/oauth/authorize', - port: 80, + oauthRequestUrl: 'https://api.discogs.com/oauth/request_token', + oauthAccessUrl: 'https://api.discogs.com/oauth/access_token', + oauthAuthorizeUrl: 'https://www.discogs.com/oauth/authorize', + port: 443, customHeaders: { 'Accept': 'application/json; application/octet-stream', 'Accept-Encoding': 'gzip,deflate', @@ -148,8 +148,9 @@ DiscogsClient.prototype.identity = function(callback){ */ DiscogsClient.prototype.about = function(callback){ + var self = this; this.get('', function(err, data){ - if(data){ data.disconnect = { version: pkg.version, userAgent: (this.userAgent||config.customHeaders['User-Agent']) }; } + if(data){ data.disconnect = { version: pkg.version, userAgent: (self.userAgent||config.customHeaders['User-Agent']) }; } (typeof callback === 'function')&&callback(err, data); }); }; @@ -193,12 +194,12 @@ DiscogsClient.prototype._rawRequest = function(options, callback){ // Add Authorization header when authenticated or in the process of authenticating if(oauth.status){ var oa = new OAuth({consumer: {public: oauth.consumerKey, secret: oauth.consumerSecret}}), - fullUrl = (urlParts.protocol && urlParts.host) ? urlParts.href : 'http://'+config.host+urlParts.path, + fullUrl = (urlParts.protocol && urlParts.host) ? urlParts.href : 'https://'+config.host+urlParts.path, authObj = oa.authorize({method: method, url: fullUrl}, {public: oauth.token, secret: oauth.tokenSecret}); headers['Authorization'] = oa.toHeader(authObj).Authorization; } - // Set the HTTP request options + // Set the HTTPS request options var options = { host: urlParts.host||config.host, port: urlParts.port||config.port, @@ -207,8 +208,8 @@ DiscogsClient.prototype._rawRequest = function(options, callback){ headers: headers }; - // Build the HTTP request - var req = http.request(options, function(res){ + // Build the HTTPS request + var req = https.request(options, function(res){ var data = '', rateLimit = null, add = function(chunk){ data += chunk.toString(); }; diff --git a/lib/database.js b/lib/database.js index 48182fe..7cd9593 100644 --- a/lib/database.js +++ b/lib/database.js @@ -101,9 +101,9 @@ module.exports = function(client){ }; /** - * Search the database (requires authentication starting 2014-10-14) + * Search the database * @param {String} query - The search query - * @param {Object} [params] - Search parameters as defined on http://www.discogs.com/developers/resources/database/search-endpoint.html + * @param {Object} [params] - Search parameters as defined on http://www.discogs.com/developers/#page:database,header:database-search * @param {Function} [callback] - Callback function */ diff --git a/package.json b/package.json index 92c1589..85c2ca7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "disconnect", "description": "An easy to use client library to connect with the discogs.com API v2.0", - "version": "0.4.1", + "version": "0.4.2", "keywords": ["discogs", "api", "client", "oauth"], "homepage": "https://github.com/bartve/disconnect", "bugs": "https://github.com/bartve/disconnect/issues",