Class: Atcoder
- Inherits:
-
Object
- Object
- Atcoder
- Defined in:
- lib/atcoder_greedy/lib/atcoder.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
Returns the value of attribute agent.
Instance Method Summary collapse
-
#initialize ⇒ Atcoder
constructor
A new instance of Atcoder.
- #login(url) ⇒ Object
Constructor Details
#initialize ⇒ Atcoder
Returns a new instance of Atcoder.
6 7 8 |
# File 'lib/atcoder_greedy/lib/atcoder.rb', line 6 def initialize @agent = Mechanize.new end |
Instance Attribute Details
#agent ⇒ Object
Returns the value of attribute agent.
5 6 7 |
# File 'lib/atcoder_greedy/lib/atcoder.rb', line 5 def agent @agent end |
Instance Method Details
#login(url) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/atcoder_greedy/lib/atcoder.rb', line 10 def login(url) print 'Login ... ' if AtcoderGreedy.config[:user_id].nil? || AtcoderGreedy.config[:user_id].size == 0 puts 'You still not set account info.' print 'Input User id: ' user_id = $stdin.gets.chomp! print 'Input password: ' password = $stdin.gets.chomp! else user_id = AtcoderGreedy.config[:user_id] password = AtcoderGreedy.config[:password] end response = nil @agent.get(url + '/login') do |page| response = page.form_with(action: '/login') do |f| f.field_with(name: 'name').value = user_id f.field_with(name: 'password').value = password end.submit raise 'Login error' unless response.response['x-imojudge-simpleauth'] == 'Passed' end puts 'Done!' response end |