sh19910711's blog

By sh19910711, 6 years ago, In English

Hi there. Today, I wrote codeforces API client library in Ruby. Check it out ;-)

0. Installation

We can install it by typing:

$ gem install codeforces

1. Usage

Example Code

Here is an example code for getting a user's information:

# first, load client library
require "codeforces"

# and then call web api you need
tourist = Codeforces.user("tourist")
puts tourist.rating  # -> 3254
puts tourist.rank    # -> international grandmaster

API Compatibility

The library has interface compatible with Codeforces API:

# get contest list
Codeforces.api.contest.list.each do |contest|
# same as below:
Codeforces.each_contest {|contest| puts }

2. Contributing

We can:

  1. Fork it ( )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

The library's API reference is here. See also here

Thank you,

  • Vote: I like it
  • +42
  • Vote: I do not like it

6 years ago, # |
  Vote: I like it +11 Vote: I do not like it

Here is a gif:


6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

v0.0.7: The contests#grep() function is supported now . It allows that we can find contests by using regexp or string:

# Example: Find Testing Round
require "codeforces"
Codeforces.contests.grep(:name => /Test/).each do |contest|
  puts "#{}:{}"

Here is a GIF:


6 years ago, # |
  Vote: I like it 0 Vote: I do not like it

New version of codeforces ruby gem is out :-)

Changelog: v0.0.9
  • Ability to search problems by tags
  • Ability to filter contests by division
  • Ability to get problems of contest
  • Improve some performances
Examples of New Features
  require "codeforces"

  # Get "Rockethon 2015"'s problem set
  rockethon = Codeforces.contest("Rockethon 2015").problems
  rockethon.each {|p| puts "#{p.index}: #{}" }

  # Are there `dp` problem?
  rockethon_dp = rockethon.grep(:tags => "dp")
  puts rockethon_dp.length # => 4
  # OK, show the urls of that problems
  rockethon_dp.each do |problem|
    puts "{problem.contestId}/#{problem.index}"