Skip to content

ahmed-dinar/codeforces-api-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

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

About

Codeforces API Client Library for Node.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published