All Projects → ruby-oembed → Ruby Oembed

ruby-oembed / Ruby Oembed

Licence: mit
oEmbed for Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Ruby Oembed

n65
An assembler for the 6502 microprocessor written in Ruby
Stars: ✭ 12 (-95.86%)
Mutual labels:  rubygem
gettext i18n rails js
Extends gettext_i18n_rails making your .PO files available to client side javascript as JSON
Stars: ✭ 28 (-90.34%)
Mutual labels:  rubygem
Tty Markdown
Convert a markdown document or text into a terminal friendly output.
Stars: ✭ 275 (-5.17%)
Mutual labels:  rubygem
npmdc
ruby gem to check for missed NPM dependencies
Stars: ✭ 38 (-86.9%)
Mutual labels:  rubygem
git-status-all
Get the status of all git repositories in a directory
Stars: ✭ 32 (-88.97%)
Mutual labels:  rubygem
benchmark-malloc
Trace memory allocations and collect stats
Stars: ✭ 18 (-93.79%)
Mutual labels:  rubygem
ruby-stream-api
Ruby Stream API. Inspired by Java 8's Stream API.
Stars: ✭ 21 (-92.76%)
Mutual labels:  rubygem
Webinspector
Ruby gem to inspect completely a web page. It scrapes a given URL, and returns you its meta, links, images more.
Stars: ✭ 288 (-0.69%)
Mutual labels:  rubygem
jquery-datatables
Jquery datatables ruby gems for assets pipeline
Stars: ✭ 73 (-74.83%)
Mutual labels:  rubygem
espressione
Espressione is a Ruby community-driven common regular expression patterns gem
Stars: ✭ 13 (-95.52%)
Mutual labels:  rubygem
capistrano-docker-compose
Docker Compose specific tasks for Capistrano
Stars: ✭ 17 (-94.14%)
Mutual labels:  rubygem
Hunspell
Ruby wrapper for the famous spell checker library hunspell.
Stars: ✭ 34 (-88.28%)
Mutual labels:  rubygem
nlp-pure
Natural language processing algorithms implemented in pure Ruby with minimal dependencies
Stars: ✭ 19 (-93.45%)
Mutual labels:  rubygem
strings-truncation
Truncate strings with fullwidth characters and ANSI codes.
Stars: ✭ 45 (-84.48%)
Mutual labels:  rubygem
Tty Logger
A readable, structured and beautiful logging for the terminal
Stars: ✭ 280 (-3.45%)
Mutual labels:  rubygem
glimmer-dsl-swt
Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
Stars: ✭ 53 (-81.72%)
Mutual labels:  rubygem
workbook
simple framework for containing spreadsheet like data
Stars: ✭ 13 (-95.52%)
Mutual labels:  rubygem
Docx
a ruby library/gem for interacting with .docx files
Stars: ✭ 288 (-0.69%)
Mutual labels:  rubygem
Dry Configurable
A simple mixin to make Ruby classes configurable
Stars: ✭ 280 (-3.45%)
Mutual labels:  rubygem
shortuuid.rb
Convert UUIDs & numbers into space efficient and URL-safe Base62 strings, or any other alphabet.
Stars: ✭ 38 (-86.9%)
Mutual labels:  rubygem

ruby-oembed

Gem Travis branch Code Climate Coveralls Maintenance

An oEmbed consumer library written in Ruby, letting you easily get embeddable HTML representations of supported web pages, based on their URLs. See oembed.com for more about the protocol.

Installation

gem install ruby-oembed

Get Started

Built-in Providers

The easiest way to use this library is to make use of the built-in providers.

OEmbed::Providers.register_all
resource = OEmbed::Providers.get('http://www.youtube.com/watch?v=2BYXBC8WQ5k')
resource.video? #=> true
resource.thumbnail_url #=> "http://i3.ytimg.com/vi/2BYXBC8WQ5k/hqdefault.jpg"
resource.html #=> <<-HTML
  <object width="425" height="344">
    <param name="movie" value="http://www.youtube.com/v/2BYXBC8WQ5k?fs=1"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="http://www.youtube.com/v/2BYXBC8WQ5k?fs=1" type="application/x-shockwave-flash" width="425" height="344" allowscriptaccess="always" allowfullscreen="true"></embed>
  </object>
HTML

Providers requiring an access token

Some built-in providers require authorization in order to work. These providers won't be registered unless an access token is provided. You can either pass access tokens to the register_app method.

OEmbed::Providers.register_all(access_tokens: { facebook: @my_facebook_token })

Or you can provide access tokens via environment variable

ENV['OEMBED_FACEBOOK_TOKEN'] #=> 'my-access-token'
OEmbed::Providers.register_all

Currently supported access tokens

access_token environment variable Associated Providers
:facebook OEMBED_FACEBOOK_TOKEN FacebookPost, FacebookVideo, Instagram

Custom Providers

If you'd like to use a provider that isn't included in the library, it's easy to create one. Just provide the oEmbed API endpoint and URL scheme(s).

my_provider = OEmbed::Provider.new("http://my.cool-service.com/api/oembed_endpoint.{format}")
my_provider << "http://*.cool-service.com/image/*"
my_provider << "http://*.cool-service.com/video/*"

You can then use your new custom provider or you can register it along with the rest of the built-in providers.

resource = my_provider.get("http://a.cool-service.com/video/1") #=> OEmbed::Response
resource.provider.name #=> "My Cool Service"

OEmbed::Providers.register(my_provider)
resource = OEmbed::Providers.get("http://a.cool-service.com/video/2") #=> OEmbed::Response

Fallback Providers

Last but not least, ruby-oembed supports Noembed, Embedly, provider discovery. The first two are provider aggregators. Each supports a wide array of websites ranging from Amazon.com to xkcd. The later is part of the oEmbed specification that allows websites to advertise support for the oEmbed protocol.

OEmbed::Providers.register_fallback(
  OEmbed::ProviderDiscovery,
  OEmbed::Providers::Noembed
)
OEmbed::Providers.get('https://www.xkcd.com/802/') #=> OEmbed::Response

Formatters

This library works wonderfully on its own, but can get a speed boost by using 3rd party libraries to parse oEmbed data. To use a 3rd party Formatter, just be sure to require the library before ruby-oembed (or include them in your Gemfile before ruby-oembed).

require 'json'
require 'xmlsimple'
require 'oembed'

OEmbed::Formatter::JSON.backend #=> OEmbed::Formatter::JSON::Backends::JSONGem
OEmbed::Formatter::XML.backend  #=> OEmbed::Formatter::XML::Backends::XmlSimple

The following, optional, backends are currently supported:

Lend a Hand

Note: Work is under way on a v1.0 of ruby-oembed. If you'd like to contribute, take a look at the rubocop branch!

Code for the ruby-oembed library is hosted on GitHub.

# Get the code.
git clone git://github.com/ruby-oembed/ruby-oembed.git
cd ruby-oembed
# Install all development-related gems.
gem install bundler
bundle install
# Run the tests.
bundle exec rake
# or run the test continually
bundle exec guard

If you encounter any bug, feel free to create an Issue.

We gladly accept pull requests! Just fork the library and commit your changes along with relevant tests. Once you're happy with the changes, send a pull request.

We do our best to keep our tests green

Contributors

Thanks to all who have made contributions to this gem, both large and small.

License

This code is free to use under the terms of the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].