This ruby gem allow you to fetch data that follows the opengraph protocol, and lets you fetch data from custom metatags also.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install open_graphy
Firstly require the gem using:
To fetch opengraph data from a URL use:
movie = .("https://www.rottentomatoes.com/m/coffee_and_cigarettes/")
The fetch method returns an object with methods defined that can be used to access the data retrieved. A is also defined so you can check the existence of data before using it.
movie.title #=> "Coffee and Cigarettes" movie.image? #=> true movie.image #=> "https://resizing.flixster.com/9l1s-frU7dhkYqr0V-C0AlDpJuU=/740x290/v1.bjs3MDg4NTg7ajsxNzA2MzsxMjAwOzEyODA7NzIw" movie.type #=> "video.movie"
By default the gem is set to look for og metatags. To fetch data from custom metatags you can configure the gem, the example below shows a typical configuration.
. do |config| config. = ["og:", "custom:tag:",] end
When fetching data the default useragent is
OpenGraphyBot, the example below shows a custom user agent being set.
. do |config| config.user_agent = 'DataBot/0.6' end
Copyright (c) 2016 OnTheBeach Ltd. See LICENSE.txt for further details.
- Fork it ( https://github.com/[my-github-username]/open_graphy/fork )
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request