diff --git a/LICENSE b/LICENSE index 56bdc3b..13c2ed9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Shaun +Copyright (c) 2019 Shaun Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 8f3e52f..f9aece3 100644 --- a/README.md +++ b/README.md @@ -19,26 +19,30 @@ With npm: ## Usage -1. `require()` *overwatchleague.js* within your application: +1. `require("overwatchleague.js")` within your application: ```javascript -const OWL= require('overwatchleague.js'); +const OverwatchLeague= require("overwatchleague.js"); +let owl = new OverwatchLeague("en_US"); ``` 2. Call the API method of your choice listed below ```javascript -OWL.getSchedule().then(response => { +owl.getSchedule().then(response => { console.log(response.data); }); ``` or the async way (NodeJS v8 and above) ```javascript (async () => { - let players = await OWL.getPlayers(); - console.log(players); -}); + let players = await owl.getPlayers(); + console.log(players.data); +})(); ``` + +## Constructor +- `new OverwatchLeague(locale);` - set default locale (default: en_US) ## Methods - `getAppData`- Retrieve current app information - `getSchedule` - Retrieve upcoming matches' schedule diff --git a/index.js b/index.js index b4daa51..a637733 100644 --- a/index.js +++ b/index.js @@ -1,72 +1,77 @@ -var axios = require("axios"); -var OverwatchLeague = function OverwatchLeague() { - this.axios = axios.create({ - baseURL: "https://api.overwatchleague.com/", - }); -}; - -OverwatchLeague.prototype.getAppData = function fetchToken(origin, params) { - return this.axios.get("about"); -}; - -OverwatchLeague.prototype.getSchedule = function () { - return this.axios.get("schedule"); -}; - -OverwatchLeague.prototype.getLiveStreams = function () { - return this.axios.get("streams"); -}; - -OverwatchLeague.prototype.getMatch = function (id) { - return this.axios.get(`match/${id}`); -}; - -OverwatchLeague.prototype.getTeam = function (id) { - return this.axios.get(`team/${id}`); -}; - -OverwatchLeague.prototype.getTeams = function () { - return this.axios.get(`teams?expand=team.content&locale=en_US`); -}; - -OverwatchLeague.prototype.getNews = function () { - return this.axios.get("news"); -}; - -OverwatchLeague.prototype.getPlaylistVideos = function (name) { // todo: are we the app? - return this.axios.get(`playlist/${name}`); -}; - -OverwatchLeague.prototype.getRankings = function () { - return this.axios.get("ranking"); -}; - -OverwatchLeague.prototype.getStandings = function () { - return this.axios.get("standings"); -}; - -OverwatchLeague.prototype.getVideos = function () { - return this.axios.get("vods"); -}; - -OverwatchLeague.prototype.getMatchStats = function (matchId, mapNumber) { - return this.axios.get(`stats/matches/${matchId}/maps/${mapNumber}`); -}; - -OverwatchLeague.prototype.getPlayers = function () { - return this.axios.get("stats/players"); -}; - -OverwatchLeague.prototype.getPlayer = function (id) { - return this.axios.get(`players/${id}?expand=stats,stats.ranks`); -}; - -OverwatchLeague.prototype.getUpcomingLiveMatches = function () { - return this.axios.get("live-match?expand=team.content&locale=en-us"); -}; - -OverwatchLeague.prototype.getMaps = function () { - return this.axios.get("maps"); -}; - -module.exports = new OverwatchLeague(); \ No newline at end of file +const axios = require("axios"); +class OverwatchLeague { + constructor(locale = "en_US") { + this.axios = axios.create({ + baseURL: "https://api.overwatchleague.com/", + params: { + locale + } + }); + } + + getAppData() { + return this.axios.get("about"); + }; + + getSchedule() { + return this.axios.get("schedule"); + }; + + getLiveStreams() { + return this.axios.get("streams"); + }; + + getMatch(id) { + return this.axios.get(`match/${id}`); + }; + + getTeam(id) { + return this.axios.get(`team/${id}`); + }; + + getTeams() { + return this.axios.get(`teams?expand=team.content&locale=en_US`); + }; + + getNews() { + return this.axios.get("news"); + }; + + getPlaylistVideos(name) { // todo: are we the app? + return this.axios.get(`playlist/${name}`); + }; + + getRankings() { + return this.axios.get("ranking"); + }; + + getStandings() { + return this.axios.get("standings"); + }; + + getVideos() { + return this.axios.get("vods"); + }; + + getMatchStats(matchId, mapNumber) { + return this.axios.get(`stats/matches/${matchId}/maps/${mapNumber}`); + }; + + getPlayers() { + return this.axios.get("stats/players"); + }; + + getPlayer(id) { + return this.axios.get(`players/${id}?expand=stats,stats.ranks`); + }; + + getUpcomingLiveMatches() { + return this.axios.get("live-match?expand=team.content&locale=en-us"); + }; + + getMaps() { + return this.axios.get("maps"); + }; +} + +module.exports = OverwatchLeague; \ No newline at end of file diff --git a/package.json b/package.json index 490ef69..e691f04 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,20 @@ "author": "Shaun (https://github.com/ShaunLWM)", "name": "overwatchleague.js", "description": "A Node.js library for the OverwatchLeague API", - "version": "0.0.4", + "version": "0.0.5", "homepage": "https://github.com/ShaunLWM/OverwatchLeague.js", "license": "MIT", + "engines": { + "node": ">= 8" + }, "keywords": [ "blizzard", "battlenet", "battle.net", "bnet", - "api", "overwatch", - "overwatchleague" + "overwatchleague", + "overwatchapi" ], "repository": { "type": "git", @@ -30,4 +33,4 @@ "LICENSE", "index.js" ] -} +} \ No newline at end of file