Git Product home page Git Product logo

oembed_provider_engine's Introduction

OembedProviderEngine

Turns your rails app into an oembed provider

About

Oembed is an open format for embedding media from third-party providers. This gem is a mountable engine that turns your rails 3 app into an oembed provider allowing oembed consumers to easily embed your media resources into their site.

Usage

Installation

Add the following to your Gemfile:

gem "oembed_provider_engine"

Provider Settings

Add a config/initializers/oembed_provider.rb file to configure your provider settings:

OembedProviderEngine::OembedProvider.provider_name = "Example Provider"
OembedProviderEngine::OembedProvider.provider_url  = "http://example.com"

If a controller doesn’t map to model name as per tablize convention, map it like this:

OembedProviderEngine::OembedProvider.controller_model_maps = { 'example' => 'FooBar' }

Providable Model

To declare your model providable, include the following:

include OembedProvider::OembedProvidable
# the first argument is the oembed type, that is one of :rich, :link, :photo, or :video
oembed_providable_as :rich

Your model has to provide methods to give what oembed_provider expects for your oembed type. Those methods need to make sure that request parameters maxheight and maxwidth are obeyed, see oembed specs for details.

If the methods have names different from the respective oembed attributes, you need to match them here:

# data for the oembed attribute 'title' is provided by a method named 'label'
oembed_providable_as :link, title: :label

You can also override the provider settings from the initializer:

oembed_providable_as :link, provider_name: 'Example'

Discovery

If you want to allow for oembed discovery, you can use the helper function from this engine to add links to the HTML head:

<%= oembed_provider_links %>

Routing

The engine adds a route /oembed to your app, which is your oembed api endpoint. By default, it returns json, but it may as well return xml or json-p. Following the oembed specs, a request parameter format can be used to specify the requested format (xml or json). If you add request parameters variable or callback, json-p is returned instead of json. The engine also provides the additional endpoints /oembed.xml and /oembed.json which return the respective format.

Security

The current implementation directly accesses your application’s model to fetch the data for the response. This may bypass your applicaton’s authorization and expose non-public data via oembed if your model does not take this into account!

TODO

  • proper handling of unauthorized

  • migrate from shoulda to rspec

  • caching

  • allow for custom, additional fields in the response

Contribute

Feel free to fork the project and send us pull requests.

Credits

This gem is heavily based upon the rails 2 gem oembed-provider originally developed by Walter McGinnis for kete.

Authors

Kerstin Puschke, Hinnerk Altenburg, George Avramidis and Ömür Özkir

You can find out more about our work on our dev blog.

Contributors

Thanks to all who have made contributions to this gem as well as its rails 2 predecessor.

Copyright © 2012 XING AG

Released under the MIT license. For full details see MIT-LICENSE included in this distribution.

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.