Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
lastfm-node-client
Advanced tools
Readme
This is a Node.js JavaScript library for interfacing with the Last.fm API.
format
parameter, to deliver a consistent JSON response.See the Last.Fm API web page for information about the Last.Fm API, including details on how to register an account and get your API key, shared secret, and session key.
$ npm install lastfm-node-client
Node.js 8.10.0 or later is required.
First, you must instantiate the LastFm Class with arguments containing the details of your API account. apiKey
is required, however since many endpoints of the API do not require authentication, secret
and sessionKey
are optional.
const LastFm = require("lastfm-node-client");
const lastFm = new LastFm("API_KEY", "SECRET", "SESSION_KEY");
The Last.fm API is structured into packages and methods, accessed as Package.method
. The LastFm Class contains directly corresponding methods for each package method, written as lastFm.packageMethod()
. For example, endpoint User.getRecentTracks
is accessed as lastFm.userGetRecentTracks()
.
Parameters can be passed to the API through the params
argument as an object that will be sent directly with the request, either as a query for a GET request, or a body for a POST request. The property names will not be transformed or abstracted, and so they must match the endpoint parameters exactly.
lastFm.userGetRecentTracks({
user: "USER"
});
lastFm.authGetToken()
and lastFm.tagGetTopTags()
do not accept a params
argument, as endpoints Auth.getToken
and Tag.getTopTags
do not require additional parameters.
lastFm.userGetInfo()
params.user and params argument are optional and will default to the authenticated user in accordance with endpoint User.getInfo
.
Every method returns a promise of the pending request by default. To access the response, you can chain .then()
to the method, or use await
. Errors thrown while making a request or errors returned by the API will reject the promise.
Chaining .then()
:
lastFm.userGetRecentTracks({
user: "USER"
})
.then(data => {
console.log(data);
};
Using await
:
const data = await lastFm.userGetRecentTracks({
user: "USER"
});
console.log(data);
An optional callback can be passed as the last argument. It is invoked with conventional (err, data)
arguments; err
being any errors thrown while making a request or errors returned by the API, data
containing the JSON response of the API upon success.
lastFm.userGetRecentTracks({
user: "USER"
},
(err, data)) => {
console.log(data);
});
When callback is passed, methods do not return a promise
, instead return the LastFm instance the method was called on. This allows you to chain requests.
These methods do not correspond to an exact API endpoint, but are abstractions of the already provided methods to provide easier usage.
lastFm.trackScrobbleMany
This method takes an array of objects that match the params
parameter accepted by lastFm.trackScrobble
. It allows for multiple tracks to be submitted to the API in one request.
lastFm.trackScrobbleMany([
{
artist: "ARTIST",
album: "ALBUM",
track: "TRACK",
timestamp: "TIMESTAMP"
},
{
artist: "ARTIST",
album: "ALBUM",
track: "TRACK",
timestamp: "TIMESTAMP"
}
]);
FAQs
JavaScript library for interfacing with the Last.fm API
The npm package lastfm-node-client receives a total of 161 weekly downloads. As such, lastfm-node-client popularity was classified as not popular.
We found that lastfm-node-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.