Skip to content

Commit

Permalink
Finished create, getMatchHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
booxood committed Nov 9, 2014
1 parent 5e6eec9 commit ccc8b16
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .npmignore
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/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TESTS = $(shell find test -type f -name "*.js")
REPORTER = spec
TIMEOUT = 5000
TIMEOUT = 10000
MOCHA_OPTS =

install:
Expand Down
44 changes: 44 additions & 0 deletions README.md
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)
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/dota2-api');
59 changes: 59 additions & 0 deletions lib/dota2-api.js
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;
22 changes: 20 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "node-dota2-api",
"name": "dota2-api",
"version": "0.0.1",
"description": "Dota2 web api node.js version",
"main": "index.js",
Expand All @@ -21,5 +21,23 @@
"bugs": {
"url": "https://github.com/booxood/node-dota2-api/issues"
},
"homepage": "https://github.com/booxood/node-dota2-api"
"homepage": "https://github.com/booxood/node-dota2-api",
"config": {
"blanket": {
"pattern": "//^((?!(node_modules|test)).)*$/"
},
"travis-cov": {
"threshold": 90
}
},
"dependencies": {
"request": "^2.47.0",
"underscore": "^1.7.0"
},
"devDependencies": {
"blanket": "^1.1.6",
"mocha": "^2.0.1",
"should": "^4.2.1",
"travis-cov": "^0.2.5"
}
}
43 changes: 43 additions & 0 deletions test/dota2-api.js
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);
});
});

});

0 comments on commit ccc8b16

Please sign in to comment.