Created
December 27, 2013 05:40
-
-
Save cenrak/8143007 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AIO | |
require 'nokogiri' | |
require 'open-uri' | |
class R | |
class << self | |
def class | |
self | |
end | |
def get_latest(user) | |
class_name = self.name.split('::')[1].downcase | |
page_url = 'http://arabia.io/u/' + user + '/' + class_name + 's' | |
page = Nokogiri::HTML(open(page_url)) | |
query = '//div[@class="' + class_name + '_title"]/h2/a' | |
items = page.search(query) | |
latest_item = items.first | |
case self.name | |
when 'AIO::Post' | |
latest_item.values.first[/\d+/] | |
when 'AIO::Comment' | |
latest_item.values.first[/comment_\d+/][/\d+/] | |
end | |
end | |
end | |
end | |
class Post < R; end | |
class Comment < R; end | |
class << self | |
def latest_for(user) | |
[ AIO::Post.get_latest(user), AIO::Comment.get_latest(user) ] | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment