GithubHelp home page GithubHelp logo

levoleague / ruby-oembed Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ruby-oembed/ruby-oembed

0.0 4.0 0.0 1.54 MB

oEmbed for Ruby

Home Page: http://oembed.com/

License: MIT License

Ruby 100.00%

ruby-oembed's Introduction

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

Providers

Get information about a URL via an OEmbed::Provider. This library comes with many Providers built right in, to make your life easy.

resource = OEmbed::Providers::Youtube.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

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/*"
resource = my_provider.get("http://a.cool-service.com/video/1") #=> OEmbed::Response
resource.provider.name #=> "My Cool Service"

To use multiple Providers at once, simply register them.

OEmbed::Providers.register(OEmbed::Providers::Youtube, my_provider)
resource = OEmbed::Providers.get("http://www.youtube.com/watch?v=2BYXBC8WQ5k") #=> OEmbed::Response
resource.type #=> "video"
resource.provider.name #=> "Youtube"

Last but not least, ruby-oembed supports both oohEmbed and Embedly. These services are provider aggregators. Each supports a wide array of websites ranging from Amazon.com to xkcd.

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.

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.

ruby-oembed's People

Contributors

bradleypriest avatar cryptic-mystic avatar flaburgan avatar florianguenther avatar francois2metz avatar graaff avatar hmans avatar hypomodern avatar javan avatar jhass avatar judofyr avatar kpricorn avatar kyleslattery avatar metavida avatar nogweii avatar philippbosch avatar planetcohen avatar ramsey avatar raven24 avatar satori avatar slowernet avatar strax avatar taf2 avatar thomsbg avatar voidfiles avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.