Class: Omnom::Source::Facebook::Default
- Inherits:
-
Base
- Object
- Base
- Omnom::Source::Facebook::Default
show all
- Defined in:
- lib/omnom/source/facebook/default.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #feed_key, #key, #options, #settings, #source_id
Instance Method Summary
collapse
Methods inherited from Base
config, configure, cron, every, feed_url, full_key, guid_namespace, icon, icon_from_url, inherited, #initialize, key, required_config, required_options, #update, url
#html_to_text
Instance Method Details
#after_initialize ⇒ Object
9
10
11
12
|
# File 'lib/omnom/source/facebook/default.rb', line 9
def after_initialize
@home_page_url = 'https://www.facebook.com/'
@login_page_url = @home_page_url
end
|
#authenticate ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/omnom/source/facebook/default.rb', line 14
def authenticate
login_page = @agent.get(@login_page_url)
@page = login_page.form_with(id: 'login_form') do |form|
form.email = config.web_auth_email
form.pass = config.web_auth_password
end.submit
@page = @agent.get(@home_page_url) if @page.uri.to_s != @home_page_url
raise 'Unable to log into Facebook' if @page.uri.to_s != @home_page_url
end
|
#get_raw_posts ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/omnom/source/facebook/default.rb', line 24
def get_raw_posts
= (@page)
raise 'Unable to read the Facebook stream' if .blank?
raw_posts = .search('li.uiUnifiedStory')
raise 'Unable to find posts in the Facebook stream' if raw_posts.blank?
raw_posts
end
|
#post_attributes(node) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/omnom/source/facebook/default.rb', line 32
def post_attributes(node)
author_link = node.find('.actorName > a')
author_link ||= node.find('.uiStreamHeadline .passiveName')
return nil if author_link.blank?
author_name = author_link.text
author_url = author_link.attr('href')
post_link = node.find('.uiStreamSource > a')
if post_link.present? && post_link.attr('href') != '#'
url = post_link.url
else
url = author_url
end
title = node.search('[role=article] > .uiStreamHeadline').text
description_node = node.search('[role=article] > .userContentWrapper > .messageBody')
if title == author_name
title = description_node.text
description = nil
else
description = description_node.inner_html
end
description = nil if title == description_node.text
data = node.attr('data-ft')
guid = JSON.parse(data)['mf_story_key']
attributes = {
title: title,
description: description,
guid: guid,
url: url || author_url,
published_at: Time.at(node.find('.uiStreamSource abbr[data-utime]').attr('data-utime').to_i).utc,
thumbnail_url: node.find('.actorPhoto > img').attr('src'),
author_name: author_name,
author_url: author_url
}
photos_container = node.search('.photoRedesign')
if photos_container.present?
attributes[:other] ||= {}
photos = node.search('a.uiPhotoThumb')
photos = node.search('.photoRedesignLink') if photos.blank?
attributes[:other][:images] = photos.collect do |photo|
{
page_url: photo.attr('href'),
image_url: photo.find('img').attr('src'),
}
end
attributes[:thumbnail_url] = attributes[:other][:images].first[:image_url] if attributes[:other][:images].present?
end
attributes
end
|