Class: Ubiquitously::Facebook::Account

Inherits:
Service::Account show all
Defined in:
lib/ubiquitously/services/facebook.rb

Instance Attribute Summary

Attributes inherited from Service::Account

#credentials, #ip, #logged_in, #password, #user, #username

Instance Method Summary collapse

Methods inherited from Service::Account

#access_token, #agent, #cookies?, #credentials?, #initialize

Methods included from Account::Authorizable

included

Methods included from Account::Loggable

included

Methods included from Account::Restful

included

Methods inherited from Base

#apply, #debug?

Methods included from SubclassableCallbacks

included, override

Constructor Details

This class inherits a constructor from Ubiquitously::Service::Account

Instance Method Details

#loginObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ubiquitously/services/facebook.rb', line 6

def 
  had_cookies = cookies?
  url = "http://localhost:4567/"
  authorize_url = FacebookToken.authorize(url)
  page = agent.get(authorize_url, [], url)
  
  # only login if we don't have cookies
  unless had_cookies
    form = page.forms.detect { |form| form.form_node["id"] == "login_form" }
    form["email"] = username
    form["pass"] = password
    begin
      page = form.submit
    rescue Exception => e
      puts e.inspect
    end
  end
  
  location = URI.parse(page.response.to_hash["location"].to_a.first)
  code = Rack::Utils.parse_query(location.query)["code"]
  
  # do something with the oauth token, save it in the cookie?
  self.credentials = FacebookToken.access(:secret => code, :callback_url => url)
  
  authorize!(page.uri !~ /http:\/\/login\.facebook\.com\/login\.php/i)
end