kog: A Ruby implementation of The Open Graph Protocol by Facebook
As I am sure many of you have heard Facebook announced their schema to assist with building the semantic web: The Open Graph Protocol. And while Facebook clearly acknowledges they have not done anything particularly new or innovative with it, I think for many simply hearing the concepts and techniques spoken again by a social networking giant signaled the timing is right and we should start to see some real results this time around. So, with all that energy, I drew up my version of the protocol as a ruby implementation to further reinforce and validate my interests in Ruby (again). I’ve been sitting on this code a little while expecting to divine more features for it. However, rather than sitting on it any longer waiting around for the code rot, I thought it best to simply unleash it upon the world complete with rSpec coverage and a single Cucumber feature: Kestrel Open Graph (kog).
To install simply perform:
# Installation of kog sudo gem install kog
Using kog is very simple as illustrated below:
require 'rubygems'
require 'kog'
# Parse a resource and getting the resource
obj = OpenGraph::Parser.parse('http://www.rottentomatoes.com/m/office_space/')
puts obj.class # => OpenGraph::Object
# The object
puts obj.inspect # => #<OpenGraph::Object:0x101b01060 @image="http://images.rottentomatoes.com/images/movie/custom/aa/1087856aa.jpg", @title="Office Space", @url="http://www.rottentomatoes.com/m/office_space/", @site_name="Rotten Tomatoes", @type="movie">
# Accessors
puts obj.type # => movie
puts obj.type?('movie').inspect # => true
puts obj.type?('dog').inspect # => false
That’s it! Now wasn’t that easy?




