Permalink
Browse files

Initial Commit

  • Loading branch information...
0 parents commit 91a87520fa58498166715221691f993b17235821 @brussell98 committed Aug 27, 2016
Showing with 423 additions and 0 deletions.
  1. +28 −0 .eslintrc
  2. +3 −0 .gitignore
  3. +21 −0 LICENSE
  4. +10 −0 index.js
  5. +75 −0 lib/Api.js
  6. +13 −0 lib/Base/Beatmap.js
  7. +19 −0 lib/Base/Event.js
  8. +11 −0 lib/Base/Match.js
  9. +40 −0 lib/Base/Score.js
  10. +37 −0 lib/Base/User.js
  11. +80 −0 lib/Constants.js
  12. +31 −0 package.json
  13. +55 −0 test/test.js
@@ -0,0 +1,28 @@
+{
+ "ecmaVersion": 6,
+ "env": {
+ "es6": true,
+ "node": true,
+ "mocha": true
+ },
+ "ecmaFeatures": {
+ "modules": true
+ },
+ "rules": {
+ "no-console": 0,
+ "no-control-regex": 0,
+ "no-alert": 1,
+ "no-else-return": 1,
+ "no-redeclare": 2,
+ "no-useless-escape": 1,
+ "no-inner-declarations": 0,
+ "array-bracket-spacing": ["warn", "never"],
+ "brace-style": ["warn", "1tbs", { "allowSingleLine": true }],
+ "no-trailing-spaces": 1,
+ "space-before-function-paren": ["warn", "never"],
+ "arrow-spacing": 1,
+ "comma-spacing": ["warn", { "before": false, "after": true }],
+ "no-mixed-spaces-and-tabs": ["error", "smart-tabs"]
+ },
+ extends: "eslint:recommended"
+}
@@ -0,0 +1,3 @@
+test/auth.txt
+node_modules
+*.tmp
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2016 Brandon Russell
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,10 @@
+"use strict";
+
+const Api = require('./lib/Api.js'),
+ Constants = require('./lib/Constants.js'),
+ Beatmap = require('./lib/Base/Beatmap.js'),
+ Score = require('./lib/Base/Score.js'),
+ User = require('./lib/Base/User.js'),
+ Event = require('./lib/Base/Event.js');
+
+module.exports = {Api, Constants, Beatmap, Score, User, Event};
@@ -0,0 +1,75 @@
+"use strict";
+
+var request = require('superagent'),
+ Beatmap = require('./Base/Beatmap.js'),
+ Score = require('./Base/Score.js'),
+ User = require('./Base/User.js');
+
+class Api {
+
+ constructor(apiKey) {
+ this.apiKey = apiKey;
+ this.baseUrl = 'https://osu.ppy.sh/api'
+ }
+
+ apiCall(endpoint, options) {
+ return new Promise((resolve, reject) => {
+ if (!this.apiKey)
+ return reject(new Error('apiKey not set'));
+ options['k'] = this.apiKey;
+ request.get(this.baseUrl + endpoint)
+ .query(options)
+ .end((error, response) => {
+ if (!error && response.status === 200) {
+ resolve(response.body);
+ } else
+ reject(new Error(error.status || error.response));
+ });
+ });
+ }
+
+ getBeatmaps(options) {
+ return this.apiCall('/get_beatmaps', options);
+ }
+
+ getUser(options) {
+ return new Promise((resolve, reject) => {
+ this.apiCall('/get_user', options).then(response => {
+ if (response.length === 0)
+ return reject(new Error('User not found'));
+ resolve(new User(response[0]));
+ }).catch(reject);
+ });
+ }
+
+ getScores(options) {
+ return new Promise((resolve, reject) => {
+ this.apiCall('/get_scores', options).then(response => {
+ resolve(response.map(sc => new Score(sc)));
+ }).catch(reject);
+ });
+ }
+
+ getUserBest(options) {
+ return this.apiCall('/get_user_best', options);
+ }
+
+ getUserRecent(options) {
+ return this.apiCall('/get_user_recent', options);
+ }
+
+ getMatch(options) {
+ return new Promise((resolve, reject) => {
+ this.apiCall('/get_match', options).then(response => {
+ resolve(response[0]);
+ }).catch(reject);
+ });
+ }
+
+ getReplay(options) {
+ return this.apiCall('/get_replay', options);
+ }
+
+}
+
+module.exports = Api;
@@ -0,0 +1,13 @@
+"use strict";
+
+const Constants = require('../Constants.js');
+
+class Beatmap {
+
+ constructor(data) {
+ this.data = data;
+ }
+
+}
+
+module.exports = Beatmap;
@@ -0,0 +1,19 @@
+"use strict";
+
+class Event {
+
+ constructor(data) {
+ this.html = data.display_html;
+ this.beatmapId = data.beatmap_id;
+ this.beatmapsetId = data.beatmapset_id;
+ this.date = data.date // UTC+8
+ this.epicfactor = data.epicfactor; // 1-32
+ }
+
+ get dateUTC() {
+ return new Date(Date.parse(this.date) - 28800000 - (new Date().getTimezoneOffset() * 60000)); // UTC+8 so we subtract 28,800,000 (8 hours) to get the UTC time
+ }
+
+}
+
+module.exports = Event;
@@ -0,0 +1,11 @@
+"use strict";
+
+class Match {
+
+ constructor(data) {
+ this.data = data;
+ }
+
+}
+
+module.exports = Match;
@@ -0,0 +1,40 @@
+"use strict";
+
+const Mods = require('../Constants.js').Mods;
+
+class Score {
+
+ constructor(data) {
+ this.score = data.score;
+ this.user = {
+ 'name': data.username,
+ 'id': data.user_id
+ }
+ this.counts = {
+ '300': data.count300,
+ '100': data.count100,
+ '50': data.count50,
+ 'geki': data.countgeki,
+ 'katu': data.countkatu,
+ 'miss': data.countmiss
+ };
+ this.maxCombo = data.maxcombo;
+ this.perfect = data.perfect === '1';
+ this.date = data.date;
+ this.rank = data.rank;
+ this.pp = data.pp || null
+
+ this.mods = [];
+ for (let mod in Mods) {
+ if (data.enabled_mods & Mods[mod])
+ this.mods.push(mod);
+ }
+ }
+
+ get dateUTC() {
+ return new Date(Date.parse(this.date) - 28800000 - (new Date().getTimezoneOffset() * 60000)); // UTC+8 so we subtract 28,800,000 (8 hours) to get the UTC time
+ }
+
+}
+
+module.exports = Score;
@@ -0,0 +1,37 @@
+"use strict";
+
+const Event = require('./Event.js');
+
+class User {
+
+ constructor(data) {
+ this.id = data.user_id;
+ this.username = data.username;
+ this.counts = {
+ '300': data.count300,
+ '100': data.count100,
+ '50': data.count50,
+ 'SS': data.count_rank_ss,
+ 'S': data.count_rank_s,
+ 'A': data.count_rank_a,
+ 'plays': data.playcount
+ };
+ this.scores = {
+ ranked: data.ranked_score,
+ total: data.total_score
+ };
+ this.pp = {
+ raw: data.pp_raw,
+ rank: data.pp_rank,
+ countryRank: data.pp_country_rank
+ };
+ this.country = data.country;
+ this.level = data.level;
+ this.accuracy = data.accuracy;
+ this.accuracyFormatted = parseFloat(data.accuracy).toFixed(2) + '%';
+ this.events = data.events.map(ev => new Event(ev));
+ }
+
+}
+
+module.exports = User;
@@ -0,0 +1,80 @@
+"use strict";
+
+module.exports = {
+ Mods: {
+ "None" : 0,
+ "NoFail" : 1,
+ "Easy" : 2,
+ "NoVideo" : 4,
+ "Hidden" : 8,
+ "HardRock" : 16,
+ "SuddenDeath" : 32,
+ "DoubleTime" : 64,
+ "Relax" : 128,
+ "HalfTime" : 256,
+ "Nightcore" : 512,
+ "Flashlight" : 1024,
+ "Autoplay" : 2048,
+ "SpunOut" : 4096,
+ "Autopilot" : 8192,
+ "Perfect" : 16384,
+ "Key4" : 32768,
+ "Key5" : 65536,
+ "Key6" : 131072,
+ "Key7" : 262144,
+ "Key8" : 524288,
+ "keyMod" : 1015808,
+ "FadeIn" : 1048576,
+ "Random" : 2097152,
+ "LastMod" : 4194304,
+ "FreeModAllowed": 2077883,
+ "Key9" : 16777216,
+ "Key10" : 33554432,
+ "Key1" : 67108864,
+ "Key3" : 134217728,
+ "Key2" : 268435456
+ },
+ URLSchemas: {
+ multiplayerMatch: (id, password) => `osu://mp/${id}${password !== undefined ? '/' + password : ''}`,
+ edit: (position, objects) => `osu://edit/${position}${objects !== undefined ? ' ' + objects : ''}`,
+ channel: (name) => `osu://chan/#${name}`,
+ download: (id) => `osu://dl/${id}`,
+ spectate: (user) => `osu://spectate/${user}`
+ },
+ Beatmaps: {
+ "approved": {
+ "-2": "Graveyard",
+ "-1": "WIP",
+ "0": "Pending",
+ "1": "Ranked",
+ "2": "Approved",
+ "3": "Qualified"
+ },
+ "genre": {
+ "0": "any",
+ "1": "unspecified",
+ "2": "video game",
+ "3": "anime",
+ "4": "rock",
+ "5": "pop",
+ "6": "other",
+ "7": "novelty",
+ "9": "hip hop",
+ "10": "electronic"
+ },
+ "language": {
+ "0": "any",
+ "1": "other",
+ "2": "english",
+ "3": "japanese",
+ "4": "chinese",
+ "5": "instrumental",
+ "6": "korean",
+ "7": "french",
+ "8": "german",
+ "9": "swedish",
+ "10": "spanish",
+ "11": "italian"
+ }
+ }
+}
@@ -0,0 +1,31 @@
+{
+ "name": "node-osu",
+ "version": "0.1.0",
+ "description": "An object-oriented library for easy interaction with the osu!api",
+ "main": "index.js",
+ "scripts": {
+ "test": "./node_modules/.bin/mocha --reporter spec"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/brussell98/node-osu.git"
+ },
+ "keywords": [
+ "osu",
+ "api",
+ "es6"
+ ],
+ "author": "brussell98",
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/brussell98/node-osu/issues"
+ },
+ "homepage": "https://github.com/brussell98/node-osu#readme",
+ "dependencies": {
+ "superagent": "^2.1.0"
+ },
+ "devDependencies": {
+ "chai": "^3.5.0",
+ "mocha": "^3.0.2"
+ }
+}
Oops, something went wrong.

0 comments on commit 91a8752

Please sign in to comment.