facebook_wall is a simple library that fetches the latest wall-posts for a Facebook page without having to log in - wall posts are taken from the page’s RSS feed. The markup in posts is filtered to help ensure standards-compliance and prevent errors when inserted into your own Web pages.
facebook_wall was written and tested on Ruby 1.9.2 but is likely to work on other versions. It requires no 3rd-party libraries - it uses the open-uri and RSS libs from the Standard Library.
Using Bundler:
gem 'facebook_wall'
or:
gem 'facebook_wall', :git => 'git://github.com/archaichorizon/ruby-facebook-wall.git'
The following example prints the latest wall-post from Archaic Horizon’s Facebook page.
require 'facebook_wall' facebook_wall_posts = FacebookWall::posts_by 260041833284 latest_wall_post = facebook_wall_posts.first puts latest_wall_post.description
FacebookWall::posts_by
returns an Array
containing instances of FacebookWall::Post
. FacebookWall::Post
decorates RSS::Rss::Channel::Item
, which means you can easily access all sub-elements of item
s published in a page’s feed. For example:
post.title # => A title automatically generated by Facebook post.link # => The URL of the wall post post.description # => The content of the wall post post.pubDate # => The date the post was published post.author # => The author of the post
The library applies two filters to each item in the feed:
-
FacebookWall::FeedEntryFilters::LinkRewriter
completely rewrites HTML links in items, removing superfluous attributes added by Facebook. -
FacebookWall::FeedEntryFilters::Paragraphizer
wraps ‘plain’ paragraphs withP
tags to create semantically-correct HTML.
You can insert your own filters into the chain by adding subclasses of FacebookWall::FeedEntryFilters::FeedEntryFilter
to the FacebookWall::FeedEntryFilters
module. The following filter, for example, would append the word “foo” to the description of each item.
module FacebookWall module FeedEntryFilters class CustomFilter < FeedEntryFilter def apply!(feed_entry) feed_entry.description << 'foo' end end end end