disconnect
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -0,1 +1,7 @@ | ||
0.5.1 / 2014-10-29 | ||
================== | ||
* Fixed a test which was failing due to changes in `0.5.0` and `npm test` now runs the tests (@Trott) | ||
* Added the possibility to set a custom configuration object with `DiscogsClient.setConfig()` for Browserify + CORS or Proxy use cases (@Trott) | ||
* Updated `README.md` to explain the `app` variable | ||
0.5.0 / 2014-10-22 | ||
@@ -2,0 +8,0 @@ ================== |
@@ -15,9 +15,15 @@ 'use strict'; | ||
/** | ||
* Merge two objects (shallow) and return the result | ||
* @param {object} source | ||
* @param {object} target | ||
* Deep merge two objects and return the result | ||
* @param {object} target - The target object (by reference!) | ||
* @param {object} source - The source object | ||
*/ | ||
var merge = function(target, source){ | ||
for(var key in source){ target[key] = source[key]; } | ||
for(var key in source){ | ||
if(source[key] && (typeof source[key] === 'object')){ | ||
target[key] = merge((Array.isArray(source[key]) ? [] : {}), source[key]); | ||
}else{ | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
@@ -30,3 +36,3 @@ }; | ||
var config = { | ||
var defaultConfig = { | ||
host: 'api.discogs.com', | ||
@@ -53,3 +59,3 @@ oauthRequestUrl: 'https://api.discogs.com/oauth/request_token', | ||
// Allow the class to be called as a function, returning an instance | ||
if(!(this instanceof DiscogsClient)) { | ||
if(!(this instanceof DiscogsClient)){ | ||
return new DiscogsClient(userAgent, oauth); | ||
@@ -66,2 +72,12 @@ } | ||
/** | ||
* Override the default configuration | ||
* @param {object} customConfig - Custom configuration object for Browserify/CORS/Proxy use cases | ||
* @returns {DiscogsClient} | ||
*/ | ||
DiscogsClient.prototype.setConfig = function(customConfig){ | ||
this.customConfig = merge(merge({}, defaultConfig), customConfig); | ||
return this; | ||
}; | ||
/** | ||
* Get an OAuth request token from Discogs | ||
@@ -76,3 +92,3 @@ * @param {string} consumerKey - The Discogs consumer key | ||
DiscogsClient.prototype.getRequestToken = function(consumerKey, consumerSecret, callbackUrl, callback){ | ||
var oauth = this.oauth, oa = new OAuth({consumer: {public: consumerKey, secret: consumerSecret}}); | ||
var oauth = this.oauth, config = (this.customConfig||defaultConfig), oa = new OAuth({consumer: {public: consumerKey, secret: consumerSecret}}); | ||
oauth.consumerKey = consumerKey; | ||
@@ -103,3 +119,3 @@ oauth.consumerSecret = consumerSecret; | ||
oauth.status = 'access'; | ||
this._rawRequest({url: config.oauthAccessUrl+'?oauth_verifier='+oa.percentEncode(verifier)}, function(err, data){ | ||
this._rawRequest({url: (this.customConfig||defaultConfig).oauthAccessUrl+'?oauth_verifier='+oa.percentEncode(verifier)}, function(err, data){ | ||
if(!err){ | ||
@@ -143,3 +159,3 @@ data&&(data = queryString.parse(data)); | ||
this.get('', function(err, data){ | ||
if(data){ data.disconnect = { version: pkg.version, userAgent: (self.userAgent||config.customHeaders['User-Agent']) }; } | ||
if(data){ data.disconnect = { version: pkg.version, userAgent: (self.userAgent||(this.customConfig||defaultConfig).customHeaders['User-Agent']) }; } | ||
callback(err, data); | ||
@@ -165,3 +181,4 @@ }); | ||
urlParts = url.parse(options.url), | ||
encoding = options.encoding||'utf8'; | ||
encoding = options.encoding||'utf8', | ||
config = (this.customConfig||defaultConfig); | ||
@@ -168,0 +185,0 @@ // Build request headers |
{ | ||
"name": "disconnect", | ||
"description": "An easy to use client library to connect with the discogs.com API v2.0", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"keywords": ["discogs", "api", "client", "oauth"], | ||
@@ -18,3 +18,5 @@ "homepage": "https://github.com/bartve/disconnect", | ||
}, | ||
"scripts": {}, | ||
"scripts": { | ||
"test": "node test/all.js" | ||
}, | ||
"dependencies": { | ||
@@ -24,3 +26,4 @@ "oauth-1.0a": "0.1.x" | ||
"devDependencies": { | ||
"wru": "0.2.x" | ||
"nock": "^0.48.1", | ||
"wru": "0.2.x" | ||
}, | ||
@@ -27,0 +30,0 @@ "engines": { |
@@ -51,3 +51,3 @@ ## About | ||
Get release data. | ||
Get release data. Note that in the following examples the `app` variable is an [Express instance](http://expressjs.com/starter/hello-world.html) to handle incoming HTTP requests. | ||
```javascript | ||
@@ -54,0 +54,0 @@ app.get('/release/:id', function(req, res){ |
var wru = require('wru'), | ||
nock = require('nock'), | ||
DiscogsClient = require('../lib/client.js'), | ||
@@ -20,3 +21,3 @@ queue = require('../lib/queue.js'); | ||
var client = new DiscogsClient(); | ||
client._request('/labels/1', wru.async(function(err, data){ | ||
client._request({url: '/labels/1'}, wru.async(function(err, data){ | ||
wru.assert('No error', !err); | ||
@@ -26,2 +27,16 @@ wru.assert('Correct response data', (data.id && (data.id === 1))); | ||
} | ||
},{ | ||
name: 'Test DiscogsClient with custom configuration', | ||
test: function(){ | ||
nock('https://www.example.com').get('/labels/1').reply(200, '{"result": "success"}'); | ||
var client = new DiscogsClient().setConfig({host: 'www.example.com'}); | ||
client._request({url: '/labels/1'}, wru.async(function(err, data){ | ||
wru.assert('No error', !err); | ||
wru.assert('Correct response data', (data && data.result === 'success')); | ||
})); | ||
}, | ||
teardown: function () { | ||
nock.cleanAll(); | ||
} | ||
} | ||
@@ -28,0 +43,0 @@ ]; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47455
1048
2