Module: Misoni

Defined in:
lib/misoni.rb,
lib/misoni/cli.rb,
lib/misoni/version.rb

Defined Under Namespace

Classes: CLI, Error

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.authObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/misoni.rb', line 24

def self.auth
  agent = Mechanize.new { |agent|
    agent.user_agent_alias = 'Mac Safari'
    }
  
  begin
    agent.get('http://auth.zokei.ac.jp:16978/') do |page|
       = page.form_with(:action => '/cgi-bin/adeflogin.cgi') do |form|
        _config = config
        form.field_with(:name => 'name').value = _config["id"]
        form.field_with(:name => 'pass').value = _config["password"]
      end.submit
      success?()
    end
  rescue SocketError => e
    puts e.message
  end
end

.configObject



11
12
13
# File 'lib/misoni.rb', line 11

def self.config
  Pit.get("http://auth.zokei.ac.jp:16978", :require => { "id"=> "YOUR_UserID", "password"=> "YOUR_PASSWORD" })
end

.in_rbenv?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/misoni.rb', line 43

def self.in_rbenv?
  ENV.has_key?('RBENV_ROOT')
end

.success?(page) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
# File 'lib/misoni.rb', line 15

def self.success?(page)
  body = Nokogiri::HTML(page.body)
  body.css('table tr:nth-child(2) td').each do |child|
    unless child.text.include?("成功")
      raise Misoni::Error.new("authentication failed")
    end
  end
end