Permalink
Browse files

Ask not to be given redirect to the audio when getting track previews.

  • Loading branch information...
1 parent 590cf78 commit b423ed46cc677b390ae01d7959da6c66f945cebf @raoulmillais raoulmillais committed Dec 16, 2011
Showing with 21 additions and 0 deletions.
  1. +13 −0 examples/trackpreview.js
  2. +8 −0 lib/request.js
View
@@ -0,0 +1,13 @@
+// Require the API wrapper, if you have npm installed it this would be:
+// var api= require('7digital-api');
+var api = require('../index'),
+ tracks = new api.Tracks();
+
+// Make a request using the wrapper and process the result
+tracks.getPreview({ trackId: 12345 }, function processPreview(err, data) {
+ if (err) {
+ throw new Error(err);
+ }
+
+ console.dir(data);
+});
View
@@ -130,6 +130,7 @@ Request.prototype.makeSecureRequest = function (url, httpMethod, data,
secret = is2Legged ? null : data.accesssecret;
data = this.prepare(data);
+
this.logger.info(httpMethod + ': ' + fullUrl + ' (' +
this.authtype + ' oauth)');
@@ -177,6 +178,13 @@ Request.prototype.makeRequest = function (url, httpMethod, data, callback) {
var apiRequest, headers, prop, self = this;
data = this.prepare(data);
+
+ // Special case for track previews: we explicitly request to be given
+ // the XMl response back instead of a redirect to the track download.
+ if (url.indexOf('track/preview') >= 0) {
+ data.redirect = "false";
+ }
+
if (httpMethod === 'GET') {
url = url + '?' + querystring.stringify(data);
}

0 comments on commit b423ed4

Please sign in to comment.