Module: OpenGraph
- Defined in:
- lib/opengraph.rb
Defined Under Namespace
Classes: Object
Constant Summary collapse
- TYPES =
{ 'activity' => %w(activity sport), 'business' => %w(bar company cafe hotel restaurant), 'group' => %w(cause sports_league sports_team), 'organization' => %w(band government non_profit school university), 'person' => %w(actor athlete author director musician politician public_figure), 'place' => %w(city country landmark state_province), 'product' => %w(album book drink food game movie product song tv_show), 'website' => %w(blog website) }
Class Method Summary collapse
-
.fetch(uri) ⇒ Object
Fetch Open Graph data from the specified URI.
- .parse(html) ⇒ Object
Class Method Details
.fetch(uri) ⇒ Object
Fetch Open Graph data from the specified URI. Makes an HTTP GET request and returns an OpenGraph::Object if there is data to be found or false
if there isn’t.
9 10 11 12 13 |
# File 'lib/opengraph.rb', line 9 def self.fetch(uri) parse(RestClient.get(uri).body) rescue RestClient::Exception, SocketError false end |
.parse(html) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/opengraph.rb', line 15 def self.parse(html) doc = Nokogiri::HTML.parse(html) page = OpenGraph::Object.new doc.css('meta').each do |m| if m.attribute('property') && m.attribute('property').to_s.match(/^og:(.+)$/i) page[$1.gsub('-','_')] = m.attribute('content').to_s end end return false unless page.valid? page end |