-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
test/ | ||
coverage.html | ||
lib-cov/ | ||
Makefile | ||
.travis.yml | ||
logo.png | ||
.gitignore | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Dota2 Web Api | ||
|
||
|
||
[![Build Status](https://travis-ci.org/booxood/node-dota2-api.png?branch=master)](https://travis-ci.org/booxood/node-dota2-api) | ||
|
||
Dota2 web api node.js version.See detail [here](https://wiki.teamfortress.com/wiki/WebAPI#Dota_2) | ||
|
||
## Install | ||
|
||
``` | ||
npm install dota2-api | ||
``` | ||
|
||
|
||
Example: | ||
```javascript | ||
var Dota2Api = require('dota2-api'); | ||
var da = Dota2Api.create('a key'); | ||
da.getMatchHistory(function(err, result){ | ||
if(!err) | ||
console.log(result); | ||
}) | ||
``` | ||
|
||
|
||
## API | ||
|
||
### Dota2Api.create(key) | ||
Create Dota2Api instance,require a key.(if no, see [here](http://steamcommunity.com/dev/apikey)) | ||
```javascript | ||
var da = Dota2Api.create('a key'); | ||
``` | ||
|
||
### Dota2Api.prototype.getMatchHistory([options], callback) | ||
|
||
```javascript | ||
fd.readlines(filePath, function(err, lines){ | ||
console.log(lines); | ||
}); | ||
``` | ||
|
||
|
||
## License | ||
[The MIT License](https://github.com/booxood/node-dota2-api/blob/master/LICENSE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/dota2-api'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/*! | ||
* dota2-api - lib/dota2-api.js | ||
* | ||
* Copyright(c) 2014 Liucw <[email protected]> | ||
* MIT Licensed | ||
*/ | ||
|
||
"use strict"; | ||
|
||
var url = require('url'); | ||
|
||
var request = require('request'); | ||
var _ = require('underscore') | ||
|
||
var API_URL = 'https://api.steampowered.com/'; | ||
|
||
function Dota2Api(key) { | ||
if (!key) { | ||
throw new TypeError('required key (Get key from http://steamcommunity.com/dev/apikey)') | ||
} | ||
|
||
this.key = key; | ||
} | ||
|
||
Dota2Api.API_URL = API_URL; | ||
|
||
Dota2Api.create = function(key) { | ||
return new Dota2Api(key); | ||
}; | ||
|
||
|
||
Dota2Api.prototype.getMatchHistory = function(options, cb) { | ||
var validOptions = ['hero_id', 'game_mode', 'skill', 'min_players', 'account_id', | ||
'league_id', 'start_at_match_id', 'matches_requested', 'tournament_games_only' | ||
]; | ||
var path = 'IDOTA2Match_570/GetMatchHistory/V001'; | ||
|
||
if (typeof options == 'function') { | ||
cb = options; | ||
options = {}; | ||
} | ||
|
||
options = _.pick(options, validOptions); | ||
options['key'] = this.key; | ||
|
||
var uri = url.format({ | ||
pathname: API_URL + path, | ||
query: options | ||
}); | ||
|
||
request.get(uri, function(err, res, body) { | ||
return cb(err, body); | ||
}); | ||
|
||
|
||
}; | ||
|
||
|
||
module.exports = Dota2Api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
var should = require('should'); | ||
var Dota2Api = require('../index.js'); | ||
|
||
describe('Dota2Api test case', function() { | ||
|
||
describe('Dota2Api.create', function() { | ||
before(function() {}); | ||
|
||
it('should throw TypeError, create no key', function() { | ||
(function() { | ||
Dota2Api.create(); | ||
}).should.throw(/^required key/); | ||
}); | ||
|
||
it('should return Dota2Api instance, create no key', function() { | ||
var da = Dota2Api.create('a key'); | ||
da.should.be.an.instanceof(Dota2Api); | ||
}); | ||
}); | ||
|
||
describe('Dota2Api prototype function', function() { | ||
var da | ||
before(function() { | ||
da = Dota2Api.create('a key'); | ||
}); | ||
|
||
it('should return , getMatchHistory', function(done) { | ||
da.getMatchHistory(function(err, result){ | ||
should.not.exist(err); | ||
should.exist(result); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return Dota2Api instance, create no key', function() { | ||
var da = Dota2Api.create('a key'); | ||
da.should.be.an.instanceof(Dota2Api); | ||
}); | ||
}); | ||
|
||
}); |