facebook Clutch Top custom software development companies

Onebox Ruby gem for turning URLs into website previews

Onebox Ruby gem for turning URLs into website previews
Average rating: 0
(0 votes)

Thanks! You’ve rated this material!

There are plenty of useful Ruby gems for all tastes and needs. As Ruby on Rails agency, we use most of them. And today we’ll add one more gem to the collection. How about Onebox Ruby gem for turning URLs into website previews? It’s great if you want to make your application convert URLs into rich previews for display.

Onebox is a library for turning media URLs into simple HTML previews of the resource.

It’s very simple in use. First, make sure the library is required. Then pass a link to the library’s interface. From here you either call Onebox::Preview#to_s or just pass the object to a string. In addition, you can set your own options with the interface.

The Onebox library is supported on all supported versions of Ruby, this means you must be on Ruby 2.3 or above version.

To add support for a new URL, you need:

  1. Check if the site supports oEmbed or Open Graph. If it does, you can get away with just whitelisting the URL in Onebox::Engine::WhitelistedGenericOnebox If the site does not support open standards, you can create a new engine.
  2. Create a new engine
  3. Create new spec using FakeWeb
  4. Create new mustache template
  5. Create new fixture from HTML response for your FakeWeb request
  6. Require in Engine module]

That’s a short version of how it works. To know more please visit here.

And please take a look at a set of interesting Ruby gems that you can use to solve specific design problems in your code. Dry-rb is composed of over 18 Ruby gems that can work together or by themselves.

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

*By submitting this form you agree with our Privacy Policy.

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111