Skip to content

Commit

Permalink
Add default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLWM committed Jun 8, 2019
1 parent 842be92 commit af990b0
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 83 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
149 changes: 77 additions & 72 deletions index.js
Original file line number Diff line number Diff line change
@@ -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();
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;
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,4 +33,4 @@
"LICENSE",
"index.js"
]
}
}

0 comments on commit af990b0

Please sign in to comment.