Class: Ubiquitously::Reddit::User

Inherits:
Base::User show all
Defined in:
lib/ubiquitously/reddit.rb

Instance Attribute Summary

Attributes inherited from Base::User

#agent, #password, #username

Instance Method Summary collapse

Methods inherited from Base::User

#initialize, #logged_in?

Methods included from Ubiquitously::Resourceful

included

Constructor Details

This class inherits a constructor from Ubiquitously::Base::User

Instance Method Details

#loginObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ubiquitously/reddit.rb', line 4

def 
  return true if logged_in?
  
  page = agent.get("http://www.reddit.com/")
  form = page.form_with(:action => "http://www.reddit.com/post/login")
  form["user"]   = username
  form["passwd"] = password
  page = form.submit
  
  @logged_in = (page.title =~ /login or register/i).nil?
  
  unless @logged_in
    raise AuthenticationError.new("Invalid username or password for #{service_name.titleize}")
  end
  
  @logged_in
end