Class: Ubiquitously::Newsvine::Post
Instance Attribute Summary
#captcha, #categories, #description, #downvotes, #extension, #format, #image, #kind, #must_be_unique, #privacy, #rating, #remote, #service_id, #service_url, #slug, #source, #source_url, #state, #status, #tags, #title, #token, #upvotes, #url, #user, #vote
Class Method Summary
collapse
Instance Method Summary
collapse
#access_token, #initialize
included
included
included
included
Methods inherited from Base
#apply, #debug?
included, override
Class Method Details
.find(options = {}) ⇒ Object
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
|
# File 'lib/ubiquitously/services/newsvine.rb', line 43
def find(options = {})
records = []
user = options[:user]
user_url = "http://#{user.username_for(self)}.newsvine.com"
html = Nokogiri::HTML(open(user_url).read)
urls = url_permutations(options[:url])
html.css(".quickpost").each do |node|
title = node.css("h1").first.text rescue nil
url = node.css("a.external").first["href"] rescue nil
description = node.xpath("p").first.text rescue nil
service_url = node.css("h1 a").first["href"] rescue nil
tags = []
node.css(".tags a").each do |tag|
tags << tag.text
end
record = new(
:title => title,
:url => url,
:description => description,
:tags => tags,
:service_url => service_url,
:user => user
)
return record if urls.include?(record.url)
records << record
end
options[:url] ? nil : records
end
|
Instance Method Details
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ubiquitously/services/newsvine.rb', line 20
def create
page = agent.get("http://www.newsvine.com/_tools/seed")
form = page.form_with(:action => "http://www.newsvine.com/_action/tools/saveLink")
form["url"] = token[:url]
form["headline"] = token[:title]
form.radiobuttons_with(:name => "newsType").each do |button|
button.check if button.value == "x"
end
form.field_with(:name => "categoryTag").options.each do |option|
option.select if option.value == "technology"
end
form["blurb"] = token[:description]
form["tags"] = token[:tags]
unless debug?
page = form.submit
end
true
end
|
16
17
18
|
# File 'lib/ubiquitously/services/newsvine.rb', line 16
def tokenize
super.merge(:tags => tags.taggify(" ", ", "))
end
|