1

I am extremely new to rails and am trying to use embedly. Is there a tutorial that walks through it step by step? Im sure its not very difficult I just need to little of hand holding since I am just trying to get into this. Any help is greatly appreciated!

Thanks.

Alex
  • 317
  • 3
  • 14

2 Answers2

2

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.

  1. You have to add the gem first and bundle
    gem 'embedly', '~> 1.9.1' (what ever current version)

  2. 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
  1. 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.

Luis Menjivar
  • 777
  • 4
  • 10
1

Have a look at the following URLS, it should make your job easier.

https://github.com/embedly/embedly-ruby

http://blog.enbake.com/embedly-integration-in-rails/

coderhs
  • 4,357
  • 1
  • 16
  • 25