Блог пользователя sh19910711

Автор sh19910711, 10 лет назад, По-английски

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,

  • Проголосовать: нравится
  • +42
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Here is a gif:

demo

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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://codeforces.me/contest/#{contest.id}"
end

Here is a GIF:

gif

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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