I am not sure how you want to use it.
In any case this could help you get started.
Let me know if you get stuck somewhere.
You have to add the gem first and bundle
gem 'embedly', '~> 1.9.1' (what ever current version)
The following code declares a method called display which you can use in your views.
Notes
*You have to sign up to embedly and get an API key.
*I recommend you hide your secret key.
*You could put the following code in a model file or probably other
places but for the sake of simplicity put the code under the app/helpers folder
Put the following code in:
app/helpers/application_helper.rb
require 'embedly'
require 'json'
def display(url)
embedly_api = Embedly::API.new(key: THIS IS WHERE YOUR API KEY GOES)
obj = embedly_api.oembed :url => url
(obj.first.html).html_safe
end
- Put this in your views:
for example app/views/welcome/index.html.erb
<%= display("http://vimeo.com/18150336") %>
Go to:
http://embed.ly/docs/explore/oembed?url=http%3A%2F%2Fvimeo.com%2F18150336
It will show you what embedly can retrieve from that particular url in this case "http://vimeo.com/18150336".
If you want to retrieve the title, change :
(obj.first.html).html_safe to (obj.first.title).html_safe
If you want to retrieve the thumbnail, change:
(obj.first.html).html_safe to (obj.first.thumbnail_url).html_safe
If you want to retrieve the favicon, change :
(obj.first.html).html_safe to (obj.first.favicon_url).html_safe
If you want to retrieve the description, change :
(obj.first.html).html_safe to (obj.first.description).html_safe
Note how code is wrapped in ().html_safe
you could also do raw.()
If you don't do this the embedded code will be shown as a string.