Socket
Socket
Sign inDemoInstall

lastfm

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lastfm - npm Package Compare versions

Comparing version 0.8.1 to 0.8.3

.gitignore

10

History.md
# Changelog
## 0.8.3
* Fix issue where undefined mbid in track object would cause scrobble
to fail. (maxkueng)
* Fix issue where all undefined and null parameters would cause signatures
to fail.
## 0.8.2
* Use http.request instead of deprecated http.createClient. (xhochy)
* lastfm-node now requires node v0.4.10 and above.
## 0.8.1

@@ -4,0 +14,0 @@ * Automatically set album parameter from track details when available.

39

lib/lastfm/lastfm-request.js

@@ -33,20 +33,22 @@ if (global.GENTLY_HIJACK) require = GENTLY_HIJACK.hijack(require);

var httpVerb = isWriteRequest() ? "POST" : "GET"
, port = 80
, connection = http.createClient(port, host)
, requestParams = buildRequestParams(params)
, data = querystring.stringify(requestParams);
connection.on("error", function(error) {
that.emit("error", error);
});
var requestParams = buildRequestParams(params);
var data = querystring.stringify(requestParams);
if (httpVerb == "GET") {
url += "?" + data;
}
var headers = requestHeaders(httpVerb, host, data);
var request = connection.request(httpVerb, url, headers);
var options = {
host: host,
port: 80,
path: url,
method: httpVerb,
headers: requestHeaders(httpVerb, host, data)
};
var req = http.request(options, chunkedResponse);
req.on("error", function(error) {
that.emit("error", error);
});
if (httpVerb == "POST") {
request.write(data);
req.write(data);
}
request.on("response", chunkedResponse);
request.end();
req.end()
}

@@ -62,3 +64,5 @@

requestParams.track = params.track.name;
requestParams.mbid = params.track.mbid;
if (params.track.mbid) {
requestParams.mbid = params.track.mbid;
}
if (params.track.album) {

@@ -92,5 +96,5 @@ requestParams.album = requestParams.album || params.track.album["#text"];

var headers = {
host: host
"User-Agent": lastfm.useragent
};
headers["User-Agent"] = lastfm.useragent;
if (httpVerb == "POST") {

@@ -132,3 +136,4 @@ headers["Content-Length"] = data.length;

if (key != "format") {
sig += key + params[key];
var value = typeof params[key] !== "undefined" && params[key] !== null ? params[key] : "";
sig += key + value;
}

@@ -135,0 +140,0 @@ });

{
"name": "lastfm",
"description": "Read and write to Last.fm",
"version": "0.8.1",
"version": "0.8.3",
"author": "James Scott <jammus@gmail.com>",
"contributors": [
"Garrett Wilkin <garrett.wilkin@gmail.com> (http://geethink.com)"
"Garrett Wilkin <garrett.wilkin@gmail.com> (http://geethink.com)",
"Uwe L. Korn <uwelk@xhochy.com> (http://xhochy.com/)",
"Max Kueng (http://maxkueng.com/)"
],

@@ -14,3 +16,3 @@ "repository": {

"engine": [
"node >= 0.2.6"
"node >= 0.4.10"
],

@@ -17,0 +19,0 @@ "directories": {

@@ -299,1 +299,7 @@ # lastfm-node

http://github.com/technoweenie/twitter-node
## Contributors
* Garret Wilkin (garrettwilkin) - http://geethink.com
* Uwe L. Korn (xhochy) - http://xhochy.com
* Max Kueng (maxkueng) - http://maxkueng.com

@@ -9,3 +9,3 @@ require('./common');

(function() {
var gently, lastfm, client;
var gently, lastfm;
var options, expectations;

@@ -30,17 +30,12 @@ var notExpected;

});
client = new fakes.Client();
gently.expect(GENTLY_HIJACK.hijacked.http, "createClient", function(port, host) {
verifyCreateClient(port, host);
return client;
});
gently.expect(client, "request", function(method, url, header) {
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
verifyCreateClient(options.port, options.host);
var request = new fakes.ClientRequest();
if (method == "POST") {
gently.expect(request, "write", function(data) {
verifyRequest(method, url, header, data);
});
if (options.method == "POST") {
gently.expect(request, "write", function(data) {
verifyRequest(options.method, options.path, options.headers, data);
});
} else {
verifyRequest(options.method, options.path, options.headers);
}
else {
verifyRequest(method, url, header);
}
return request;

@@ -324,2 +319,14 @@ });

it("signature hash treats undefined values as blank", function() {
whenMethodIs("any.method");
andParamsAre({ signed: true, track: 'Replicating Networks', artist: 'Rabbit Milk', albumArtist: undefined });
expectSignatureHashOf("albumArtistapi_keykeyartistRabbit Milkmethodany.methodtrackReplicating Networkssecret");
});
it("signature hash treats null values as blank", function() {
whenMethodIs("any.method");
andParamsAre({ signed: true, track: 'Replicating Networks', artist: 'Rabbit Milk', albumArtist: null });
expectSignatureHashOf("albumArtistapi_keykeyartistRabbit Milkmethodany.methodtrackReplicating Networkssecret");
});
it("write requests use post", function() {

@@ -326,0 +333,0 @@ whenMethodIs("any.method");

@@ -16,10 +16,7 @@ require("./common");

gently = new Gently();
gently.expect(GENTLY_HIJACK.hijacked.http, "createClient", function() {
return connection;
});
});
it("creates a get request", function() {
gently.expect(connection, "request", function(method, url, options) {
assert.equal("GET", method);
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
assert.equal("GET", options.method);
assert.equal(lastfm.host, options.host);

@@ -32,4 +29,4 @@ return request;

it("ends the request", function() {
gently.expect(connection, "request", function() {
return request;
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function() {
return request;
});

@@ -41,4 +38,4 @@ gently.expect(request, "end");

it("defaults user agent to lastfm-node", function() {
gently.expect(connection, "request", function(method, url, options) {
assert.equal("lastfm-node", options["User-Agent"]);
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
assert.equal("lastfm-node", options.headers["User-Agent"]);
return request;

@@ -51,4 +48,4 @@ });

var useragent = "custom-user-agent";
gently.expect(connection, "request", function(method, url, options) {
assert.equal(useragent, options["User-Agent"]);
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
assert.equal(useragent, options.headers["User-Agent"]);
return request;

@@ -62,6 +59,6 @@ });

var message = "Bubbled error";
gently.expect(connection, "request", function() {
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
return request;
});
var lastfmRequest = new LastFmRequest(lastfm);
var lastfmRequest = new LastFmRequest(lastfm, "any.method");
gently.expect(lastfmRequest, "emit", function(event, error) {

@@ -71,3 +68,3 @@ assert.equal("error", event);

});
connection.emit("error", new Error(message));
request.emit("error", new Error(message));
});

@@ -87,11 +84,8 @@ })();

params = { foo:"bar" };
gently.expect(GENTLY_HIJACK.hijacked.http, "createClient", function() {
return connection;
});
});
it("write parameter forces a post request", function() {
gently.expect(connection, "request", function(method, url, options) {
assert.equal("POST", method);
assert.equal(lastfm.url, url);
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
assert.equal("POST", options.method);
assert.equal(lastfm.url, options.path);
assert.equal(lastfm.host, options.host);

@@ -105,5 +99,5 @@ return request;

it("post requests includes additional headers", function() {
gently.expect(connection, "request", function(method, url, options) {
assert.ok(options["Content-Length"]);
assert.equal("application/x-www-form-urlencoded", options["Content-Type"]);
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
assert.ok(options.headers["Content-Length"]);
assert.equal("application/x-www-form-urlencoded", options.headers["Content-Type"]);
return request;

@@ -116,4 +110,4 @@ });

it("writes body to request", function() {
gently.expect(connection, "request", function() {
return request;
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function() {
return request;
});

@@ -138,5 +132,2 @@ gently.expect(request, "write", function(data) {

gently = new Gently();
gently.expect(GENTLY_HIJACK.hijacked.http, "createClient", function() {
return connection;
});
});

@@ -193,9 +184,9 @@

function expectRequestToEmit(expectation) {
gently.expect(connection, "request", function() {
return request;
var response = new fakes.ClientResponse();
gently.expect(GENTLY_HIJACK.hijacked.http, "request", function(options, cb) {
cb(response);
return request;
});
var lastfmRequest = new LastFmRequest(lastfm);
gently.expect(lastfmRequest, "emit", expectation);
var response = new fakes.ClientResponse();
request.emit("response", response);
_(receivedData).each(function(data) {

@@ -202,0 +193,0 @@ response.emit("data", data);

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