Code Monkey home page Code Monkey logo

setlistfm-js's Introduction

Build Status

setlist.fm API Wrapper for Node.js

This is an easy implementation of the setlist.fm API for Node.js and React. To start right away enter the following lines to your command line:

npm install setlistfm-js --save

This wrapper covers the brand new API of setlist.fm. To use the API, you need an API key of setlist.fm. You can apply for an API key here: https://www.setlist.fm/settings/api (Please note that you need an setlist.fm account to procede)

Function Reference

One quick information before we start: The whole wrapper is written for a Promise based implementation. And another thing: The whole documentation for the API can be found here, so if you have any questions about allowed search parameters this is your destination: https://api.setlist.fm/docs/1.0/index.html#resources

Okay, enough said - let's code!

Setup

var setlistfmClient = new setlistfm({
	key: "", // Insert your personal key here
	format: "json", // "json" or "xml", defaults to "json"
	language: "de", // defaults to "en"
});

Get Artist Profile

setlistfmClient.getArtist("8538e728-ca0b-4321-b7e5-cff6565dd4c0")
	.then(function(artist) {
		// Returns the artist profile of Depeche Mode
	})
	.catch(function(error) {
		// Returns error
	});

Get Setlists of Artist

setlistfmClient.getArtistSetlists("8538e728-ca0b-4321-b7e5-cff6565dd4c0", {
	p: 1
})
	.then(function(setlists) {
		// Returns page one of all Depeche Mode setlists
	})
	.catch(function(error) {
		// Returns error
	});

Get City

setlistfmClient.getCity("2921466")
	.then(function(city) {
		// Returns city profile
	})
	.catch(function(error) {
		// Returns error
	});

Search for Artists

setlistfmClient.searchArtists({
	artistName: "Linkin Park"
})
	.then(function(results) {
		// Returns results of the search
	})
	.catch(function(error) {
		// Returns error
	});

Search for Cities

setlistfmClient.searchCities({
	name: "New York"
})
	.then(function(results) {
		// Returns results of the search
	})
	.catch(function(error) {
		// Returns error
	});

Search Countries

setlistfmClient.searchCountries()
	.then(function(results) {
		// Returns a list of available countries
	})
	.catch(function(error) {
		// Returns error
	});

Search for Setlists

setlistfmClient.searchSetlists({
	artistName: "Linkin Park"
})
	.then(function(results) {
		// Returns matching setlists of Linkin Park
	})
	.catch(function(error) {
		// Returns error
	});

Search for Venues

setlistfmClient.searchVenues({
	name: "Gruenspan"
})
	.then(function(results) {
		// Returns results of the search
	})
	.catch(function(error) {
		// Returns error
	});

Get Setlist by specific Version

setlistfmClient.getSetlistByVersion("43596f23")
	.then(function(setlist) {
		// Returns version of setlist
	})
	.catch(function(error) {
		// Returns error
	});

Get Setlist

setlistfmClient.getSetlist("53e493bd")
	.then(function(setlist) {
		// Returns setlist
	})
	.catch(function(error) {
		// Returns error
	});

Get User

setlistfmClient.getUser("terhuerne")
	.then(function(user) {
		// Returns my own setlist.fm profile ;)
	})
	.catch(function(error) {
		// Returns error
	});

Get Concerts a User has attended to

setlistfmClient.getUserAttended("terhuerne", {
	p: 1
})
	.then(function(setlists) {
		// Returns setlists of concerts that I have attended to
	})
	.catch(function(error) {
		// Returns error
	});

Get Setlists a User has edited

setlistfmClient.getUserEdited("terhuerne", {
	p: 1
})
	.then(function(setlists) {
		// Returns setlists that a user has edited	
	})
	.catch(function(error) {
		// Returns error
	});

Get Venue

setlistfmClient.getVenue("4bd78fbe")
	.then(function(venue) {
		// Returns venue
	})
	.catch(function(error) {
		// Returns error
	});

Get Setlists of a Venue

setlistfmClient.getVenueSetlists("4bd78fbe", {
	p: 1
})
	.then(function(setlists) {
		// Returns setlists of concerts that have happened at the given venue
	})
	.catch(function(error) {
		// Returns error
	});

setlistfm-js's People

Contributors

dependabot[bot] avatar jamsea avatar terhuerne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

jamsea jotasprout

setlistfm-js's Issues

Unable to use from Typescript code

Hey,

I'm trying to use this .js npm package from within a .ts, but there some way that the exports are set up that it's really not liking.

The default setup of this library in a regular node.js file run from the command line:

const sfm = require("setlistfm-js");

console.log(sfm.prototype);
var client = new sfm({
    key: process.env.SETLIST_FM_API_KEY,
    format: "json"
});
console.log(client);

That first console.log(sim) prints [Function: SetlistFmApi]. The second one, console.log(client) prints:

SetlistFmApi {
  key: false,
  format: 'application/json',
  language: 'en',
  getArtist: [Function (anonymous)],
  getArtistSetlists: [Function (anonymous)],
  getCity: [Function (anonymous)],
  searchArtists: [Function (anonymous)],
  searchCities: [Function (anonymous)],
  searchCountries: [Function (anonymous)],
  searchSetlists: [Function (anonymous)],
  searchVenues: [Function (anonymous)],
  getSetlistByVersion: [Function (anonymous)],
  getSetlist: [Function (anonymous)],
  getUser: [Function (anonymous)],
  getUserAttended: [Function (anonymous)],
  getUserEdited: [Function (anonymous)],
  getVenue: [Function (anonymous)],
  getVenueSetlists: [Function (anonymous)]
}

Perfect! Everything looks good there. Now here's the same example from within typescript (note the slightly different import syntax).

import sfm = require("setlistfm-js");

console.log(sfm);
const client = sfm({
    key : process.env.SETLIST_FM_API_KEY,
    format : "json",
    language : "en",
});
console.log(client);

Here, the first log output is identical to the .js one, so I know the same correct thing is getting pulled in and it's actually reading the js source (since it prints out SetlistFmApi). The second one is undefined though. So something to do with how javascript handles its default exports compared to typescript gets the wires crossed somewhere in there.

I've used js libraries with typescript before, so I know it can be done. I just don't know enough about the package ecosystem of both to know what's messed up here. Any thoughts? Happy to put up a PR if you can just point me in the direction of a cross-compatible fix.

Error when creating the setup

When copying the instructions to setup a setlist client, i receive the following error:
ReferenceError: Setlistfm is not defined. This also occurs when I try in the npm playground. Any guidance would be greatly appreciated @terhuerne

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.