Class: WifiLogin::Providers::Docomo
- Inherits:
-
Object
- Object
- WifiLogin::Providers::Docomo
- Defined in:
- lib/wifi_login/providers/docomo.rb
Instance Method Summary collapse
Instance Method Details
#login(id, password) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wifi_login/providers/docomo.rb', line 9 def login(id, password) url = 'https://wlan.m-zone.jp/wlan/portal.jsp' agent = Mechanize.new page = agent.get(url) if status(page) == :success_auth return true end form = page.form form.user = id form.password = password page = agent.submit(form) if status(page) != :success_auth raise WifiLogin::Error.new('Login failure. (incorrect id/password?)') end true end |
#status(page) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wifi_login/providers/docomo.rb', line 26 def status(page) case page.title when 'Login' :before_auth when 'Top page' :success_auth when /^Login error/ :fail_auth else raise WifiLogin::Error.new("cannot parse page: #{page.title}") end end |