Class: RubyHackernews::LoginService

Inherits:
Object
  • Object
show all
Includes:
MechanizeContext
Defined in:
lib/ruby-hackernews/services/login_service.rb

Instance Method Summary collapse

Methods included from MechanizeContext

#[], #agent, agent=, #authenticated?, #require_authentication

Instance Method Details

#login(username, password) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/ruby-hackernews/services/login_service.rb', line 6

def (username, password)
  page = agent.get(ConfigurationService.base_url)
   = page.search(".pagetop/a").last['href'].sub("/","")
   = agent.get(ConfigurationService.base_url + )
  form = .forms.first
  form.acct = username
  form.pw = password
  page = form.submit
  return page.title != nil
end

#logoutObject



17
18
19
20
21
22
23
24
# File 'lib/ruby-hackernews/services/login_service.rb', line 17

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