Class: Omnom::Source::Instagram::Default
- Inherits:
-
Base
- Object
- Base
- Omnom::Source::Instagram::Default
show all
- Defined in:
- lib/omnom/source/instagram/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
|
# File 'lib/omnom/source/instagram/default.rb', line 9
def after_initialize
@login_page_url = "#{@url}accounts/login/"
end
|
#authenticate ⇒ Object
13
14
15
16
17
18
19
20
21
|
# File 'lib/omnom/source/instagram/default.rb', line 13
def authenticate
login_page = @agent.get(@login_page_url)
@page = login_page.form_with(id: 'login-form') do |form|
form.username = config.web_auth_username
form.password = config.web_auth_password
end.submit
@page = @agent.get(@url) if @page.uri.to_s != @url
raise 'Unable to log into Instagram' if @page.uri.to_s != @url
end
|
#get_raw_posts ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/omnom/source/instagram/default.rb', line 23
def get_raw_posts
@page.search('script').each do |script|
script = script.text
if script =~ /window\._jscalls\s+=/m
cxt = V8::Context.new
cxt['window'] = {}
cxt.eval(script)
return cxt['window']['_jscalls'][2][2].first['props']['moreQuery']['initial']['feed']['media']['nodes']
end
end
end
|
#post_attributes(node) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/omnom/source/instagram/default.rb', line 35
def post_attributes(node)
url = "http://instagram.com/p/#{node['code']}/"
image_url = node['display_src']
{
title: node['caption'].present? ? node['caption'] : node['owner']['username'],
description: node['location'].present? ? node['location']['name'] : nil,
guid: node['id'],
url: url,
published_at: Time.at(node['date']),
thumbnail_url: image_url,
author_name: node['owner']['username'],
author_url: "http://instagram.com/#{node['owner']['username']}",
comments_count: node['comments']['count'],
comments_url: url,
other: {
likes_count: node['likes']['count'],
location: node['location'].nil? ? nil : Hash[node['location'].to_a],
images: [{
image_url: image_url,
page_url: url
}]
}
}
end
|