white-label-js
v1.0.4
Published
Create a music platform on the web with whitelabel.js
Downloads
21
Maintainers
Readme
whitelabel.js
Create a music platform on the web with whitelabel.js
Usage
This library is available as an npm package or UMD module.
UMD module for Browser
Include this script tag somewhere on the page.
<script src="https://unpkg.com/white-label-js"></script>
This will expose the global class WhiteLabel
. After the page has been loaded, initialize an instance providing your White Label client id.
var wl = new WhiteLabel(CLIENT_ID);
NPM Library
npm i --save white-label-js
var WhiteLabel = require('white-label-js');
var wl = new WhiteLabel(CLIENT_ID);
This library requires the regeneratorRuntime
method to be available. It is available in ES6 but can be loaded by using the babel-polyfill.
Examples
Getting array of all Mixtape objects in the collection with slug "collection-slug"
wl.getCollectionMixtapes("collection-slug", {
all: true,
results: true
}).then(function(mixtapes) {
// Do something with array of mixtapes
});
Get array of Track objects for mixtape with slug "mixtape-slug"
wl.getMixtapeTracks("mixtape-slug", {
results: true
}).then(function(tracks) {
// Do something with array of tracks
});
Get all mixtapes for a collection with slug "collection-slug" ordered by mixtape title descending.
wl.getCollectionMixtapes("collection-slug", {
all: true,
results: true,
filters: {
ordering: "-title"
}
}).then(function(mixtapes) {
// Do something with array of mixtapes
});
Get array of all tracks from artist "Cool Artist"
wl.getAllTracks({
results: true,
all: true,
filters: {
search: "Cool Artist"
}
}).then(function(tracks) {
// Do something with array of tracks
});
Get array of first 20 Mixtape responses in the collection with slug "collection-slug". Note: each item in the array will contain a count
, next
, previous
and results
field
wl.getCollectionMixtapes("collection-slug").then(function(mixtapes) {
// Do something with array of mixtapes
});
Documentation
This library returns Promise's for all of its methods. They will resolve when the request is successful and reject with any errors.
All requests take in an optional options object as the last parameter. Options has the following defaults, which is overridden when an object is provided.
options = {
page: 1,
all: false,
results: false,
filters: {}
}
- page: The page to request when fetching from White Label API. Results are paginated every 20 records.
- all: Whether or not to recursively follow the next url in the response. If
page=1
andall=true
then method will resolve with an array of all results from the collection. - results: If true, the method will resolve with
result.results
(if exists) from the White Label API. This is useful if you just want a flat array of collections/mixtapes/tracks when requesting your Collections, Mixtapes, or Tracks.- If
all=true
andresults=true
, the method will return a flat array of all results from the requests endpoint.
- If
- filters: An object containing all white label filters to use with the API request. Common filters include ordering and search
To clarify what the results option does: In some responses from the White Label API, there is a count
, next
, previous
and results
field. If results
is true
, the method will only return what is in the results
array.
All of the methods use either the collection/mixtape/track id
or slug
as parameters.
getAllCollections(options)
getCollection(collection, options)
collection
is a Collection id or slug.
getAllMixtapes(options)
getCollectionMixtapes(collection, options)
collection
is a Collection id or slug.
getMixtape(mixtape, options)
mixtape
is a Mixtape id or slug.
getLatestMixtape()
Retrieve the most recently published Mixtape object.
getAllTracks(options)
getMixtapeTracks(mixtape, options)
mixtape
is a Mixtape id or slug.
getTrack(track, options)
track
is a Track id or slug.
recordPlay(track)
track
is a Track id or slug.
Development
To start contributing to this repository please follow these steps
- Ensure you have
yarn
installed globally.npm i -g yarn
- Clone this repo.
git clone https://github.com/NoonPacific/White-Label-JS.git
- Navigate to cloned directory.
cd White-Label-JS
- Install dependencies.
yarn install
- Copy
public/secrets_example.js
topublic/secrets.js
and fill in yourCLIENT_ID
- Start the development server which watches the source directory.
npm run dev
- In a new terminal tab start the testing server. This serves the current directory which is used for testing the library in the browser.
npm run sandbox
- Navigate to localhost:8080/public and open the developer console. You should see the results from the library.
- Run
npm run build
to create a minified file which is used for production. This can be found atbrowser/whiteLabel.min.js
. - Run
npm run build-npm
to create an ES5 compatible module to be used with npm found inlib/
.
All source files are in src/
. Browser ready files are in browser/
and the npm main entry is found in lib/
. The source is built with Webpack and uses mutliple ES6 features as well as ES7 Async/Await.
Tests
Before running any tests you need to provide your White Label Client ID. Copy public/secrets_example.js
to public/secrets.js
and fill in your CLIENT_ID
.
Run tests with npm test
. All tests are located in test/
and are run with mocha and tested in phantomjs. test/test.html
can be opened in the browser to run the tests against that specific browser.