Class: Fbapp::Drivers::Mechanize
- Inherits:
-
Base
- Object
- Base
- Fbapp::Drivers::Mechanize
show all
- Defined in:
- lib/fbapp/drivers/mechanize.rb
Defined Under Namespace
Classes: App
Instance Method Summary
collapse
Methods inherited from Base
#get_or_cache_credentials
Instance Method Details
#browser ⇒ Object
42
43
44
|
# File 'lib/fbapp/drivers/mechanize.rb', line 42
def browser
@browser ||= ::Mechanize.new
end
|
#fetch_apps(page) ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/fbapp/drivers/mechanize.rb', line 58
def fetch_apps(page)
page.search("#dev_app_list a").collect do |a|
id = a.parent["id"].split("_").first
name = a.text
App.new(id, name)
end
end
|
#list ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'lib/fbapp/drivers/mechanize.rb', line 9
def list
login
page = browser.get("http://www.facebook.com/developers/apps.php")
apps = fetch_apps(page)
apps.each do |app|
puts " * %s %s" % [app.app_id, app.name]
end
end
|
#login ⇒ Object
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/fbapp/drivers/mechanize.rb', line 46
def login
email, pass = get_or_cache_credentials
page = browser.get("http://www.facebook.com")
form = page.forms.first
form.email = email
form.pass = pass
browser.submit(form)
end
|
#show(appname) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/fbapp/drivers/mechanize.rb', line 19
def show(appname)
login
page = browser.get("http://www.facebook.com/developers/apps.php")
id = begin
apps = fetch_apps(page)
apps.find { |a| a.name == appname || a.app_id == appname }.app_id
end
dl = page.search("##{id}_info .dev_application_info dl")
titles, values = dl.search("dt"), dl.search("dd")
titles = titles.to_a.map { |t| t.text }
values = values.to_a.map { |v| v.text }
puts "Settings for #{appname}:"
settings = Hash[ titles.zip(values) ]
titles.sort.each do |title|
puts "* #{title.ljust(19)} : #{settings[title]}"
end
end
|