sh19910711's blog

By sh19910711, 10 years ago, In English

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

https://github.com/sh19910711/codeforces-api-client


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|
  puts contest.name
end
# same as below:
Codeforces.each_contest {|contest| puts contest.name }

2. Contributing

We can:

  1. Fork it ( https://github.com/sh19910711/codeforces-api-client/fork )
  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

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

Here is a gif:

demo

»
10 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 "#{contest.name}: http://mirror.codeforces.com/contest/#{contest.id}"
end

Here is a GIF:

gif

»
10 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}: #{p.name}" }

  # 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 "http://mirror.codeforces.com/problemset/problem/#{problem.contestId}/#{problem.index}"
  end