Sha256: e00f822e997153d82c6603d5a855bc4d599a2c385ee48335fcb0bba378a2a031

Contents?: true

Size: 820 Bytes

Versions: 6

Compression:

Stored size: 820 Bytes

Contents

class LoginService
  include MechanizeContext

  def login(username, password)
    raise "You are logged in already - logout first." if authenticated?
    page = agent.get(ConfigurationService.base_url)
    login_url = page.search(".pagetop/a").last['href'].sub("/","")
    login_page = agent.get(ConfigurationService.base_url + login_url)
    form = login_page.forms.first
    form.u = username
    form.p = password
    page = form.submit
    return page.title != nil
  end

  def logout
    require_authentication
    page = agent.get(ConfigurationService.base_url)
    login_url = page.search(".pagetop/a").last['href'].sub("/","")
    logout_page = agent.get(ConfigurationService.base_url + login_url)
    agent.cookie_jar.jar.clear
    return logout_page.search(".pagetop/a").last.inner_html == "login"
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-hackernews-1.1.3 lib/ruby-hackernews/services/login_service.rb
ruby-hackernews-1.1.2 lib/ruby-hackernews/services/login_service.rb
ruby-hackernews-1.1.1 lib/ruby-hackernews/services/login_service.rb
ruby-hackernews-1.1.0 lib/ruby-hackernews/services/login_service.rb
ruby-hackernews-1.0.1 lib/ruby-hackernews/services/login_service.rb
ruby-hackernews-1.0.0 lib/HNAPI/services/login_service.rb