NodeJS Client Library for Codeforces API
codeforces-api-node is a simple NodeJS library for Codeforces Api with streaming support.
$ npm install codeforces-api codeforces-api-node supports both ES5 and ES6.
//ES5 var Codeforces = require('codeforces-api'); //ES2015 import Codeforces from 'codeforces-api'; //set API keys for authentication Codeforces.setApis('your_codeforces_api_key', 'your_codeforces_api_secret'); Codeforces.method( parameters , callback );Codeforces.user.rating({ handle: 'user_handle' } , function (err, data) { if (err) { //handle error and return } //use data });Full description of the API can be found on : Official API Doc
| Method | Parameters | Description |
|---|---|---|
| blogEntry.comments | *blogEntryId | More |
| blogEntry.view | *blogEntryId | More |
| contest.hacks | contestId | More |
| contest.list | gym | More |
| contest.ratingChanges | *contestId | More |
| contest.standings | *contestId , from , count , handles , room , showUnofficial | More |
| contest.status | *contestId , handle , from , count | More |
| problemset.problems | tags | More |
| problemset.recentStatus | *count | More |
| recentActions | *maxCount | More |
| user.blogEntries | *handle | More |
| user.friends | onlyOnline | More |
| user.info | *handles | More |
| user.ratedList | activeOnly | More |
| user.rating | *handle | More |
| user.status | *handle , from , count | More |
*required parameters
handles and tags can be multiple.There are two different ways to set:
- Semicilon-separated string:
tags: 'greedy;dp;graphs'- As array:
tags: ['greedy','dp','graphs']Although most of the method of the API supports anonymously request, codeforces-api-node does not allow anonymous request yet.To access API data, must set API and SECRET key before calling methods.To generate API and SECRET KEY visit: API Settings
All data return in JSON format.For full description of data format visit: Return Objects
This feature and example from npm request package. For more have a look : Request Package Doc
You can stream responses to a file stream.When json data is huge, you may need this feature.
Codeforces.user.ratedList( parameters, callback ) .pipe( fs.createWriteStream('./rateedList.json') ); //version >= 1.0.2 (with or without callback) Codeforces.user.ratedList( parameters ) .pipe( fs.createWriteStream('./ratedList.json') );Also emits response events.
Codeforces.user.ratedList( parameters, function(err, data){ if(err){ //request error } //data also available here }).on('data', function(data) { // decompressed data as it is received console.log('decoded chunk: ' + data) }) .on('response', function(response) { // unmodified http.IncomingMessage object response.on('data', function(data) { // compressed data as it is received console.log('received ' + data.length + ' bytes of compressed data') }); }).pipe( fs.createWriteStream('./ratedList.json') );Everyone wellcome!
- Create an issue > Fork > Create own branch > Commit changes > Push the branch > Creat pull request
Before running test, must set API and SECRET key in environment variable.Keys are:
CFK = API Key CFS = API SecretAfter setting keys, simply run
npm test