Class: Reddit::Liked
Instance Attribute Summary
Attributes inherited from Site
#posts
Instance Method Summary
collapse
Methods inherited from Site
#ask_for_credentials, #balance, #credentials, #credentials=, #identifier, #imported_links, #initialize, #save!, #to_s, #undo_import!
Constructor Details
This class inherits a constructor from Site
Instance Method Details
#date(post) ⇒ Object
46
47
48
|
# File 'lib/reddit.rb', line 46
def date(post)
post["created_utc"]
end
|
#name ⇒ Object
12
13
14
|
# File 'lib/reddit.rb', line 12
def name
"reddit"
end
|
#to_post(data) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/reddit.rb', line 36
def to_post(data)
Post.new({
"url" => data["url"].gsub("&", "&"), "description" => data["title"],
"tags" => ["via:reddit", data["subreddit"]].join(" "),
"replace" => "yes",
"dt" => Time.at(data["created_utc"]).strftime("%Y-%m-%dT%H:%M:%SZ")
})
end
|
#update! ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/reddit.rb', line 16
def update!
puts "Updating Reddit"
balance
results = []
new_results = nil
after = nil
i = 0
url = "/user/#{(credentials["username"] || credentials["user"]).strip}/liked/.json"
puts "fetching data from #{url}"
while !(new_results = merge_results(Reddit.get(url, :query => {"after" => after})["data"]["children"].map{|x| x["data"]})).empty?
puts "fetching reddit page #{i}"
results += new_results
after = new_results[-1]["name"]
i += 1
end
results.map{ |update| to_post(update) }
end
|