Skip to content

Instantly share code, notes, and snippets.

@cenrak
Created December 27, 2013 05:40
Show Gist options
  • Save cenrak/8143007 to your computer and use it in GitHub Desktop.
Save cenrak/8143007 to your computer and use it in GitHub Desktop.
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