1.0.3 • Published 8 years ago

codeforces-api v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

NodeJS Client Library for Codeforces API

Build Status Coverage Status npm version Dependency Status

codeforces-api-node is a simple NodeJS library for Codeforces Api with streaming support.

Install

$ npm install codeforces-api

Usage

codeforces-api-node supports both ES5 and ES6.

Basic

//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 );

Usage

Codeforces.user.rating({ handle: 'user_handle' } , function (err, data) {

    if (err) {
        //handle error and return
    }

    //use data
});

Methods & Parameters

Full description of the API can be found on : Official API Doc

MethodParametersDescription
blogEntry.comments*blogEntryIdMore
blogEntry.view*blogEntryIdMore
contest.hackscontestIdMore
contest.listgymMore
contest.ratingChanges*contestIdMore
contest.standings*contestId , from , count , handles , room , showUnofficialMore
contest.status*contestId , handle , from , countMore
problemset.problemstagsMore
problemset.recentStatus*countMore
recentActions*maxCountMore
user.blogEntries*handleMore
user.friendsonlyOnlineMore
user.info*handlesMore
user.ratedListactiveOnlyMore
user.rating*handleMore
user.status*handle , from , countMore

*required parameters

Note

handles and tags can be multiple.There are two different ways to set: 1. Semicilon-separated string:

tags: 'greedy;dp;graphs'
  1. As array:

    tags: ['greedy','dp','graphs']

Authorization

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

Return Data

All data return in JSON format.For full description of data format visit: Return Objects

Streaming

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') );

Contributing

Everyone wellcome!

  • Create an issue > Fork > Create own branch > Commit changes > Push the branch > Creat pull request

Test

Before running test, must set API and SECRET key in environment variable.Keys are:

CFK = API Key
CFS = API Secret

After setting keys, simply run

npm test

License

MIT © Ahmed Dinar