Skip to content

Instantly share code, notes, and snippets.

@xdite
Created December 29, 2013 07:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xdite/8168404 to your computer and use it in GitHub Desktop.
Save xdite/8168404 to your computer and use it in GitHub Desktop.
class Link < ActiveRecord::Base
scope :recent, order("id DESC")
belongs_to :post
belongs_to :user
belongs_to :group
after_create :update_info
def update_info
delay.update_from_embedly
end
def update_from_embedly
link = self
urls = [url]
embedly_api = Embedly::API.new(:key => Setting.embedly_key)
embedly_objs = embedly_api.oembed(:urls => urls)
embedly_obj = embedly_objs[0]
response_data = embedly_obj.marshal_dump
link.title = response_data[:title]
link.link_type = response_data[:type]
link.author_name = response_data[:author_name]
link.author_url = response_data[:author_url]
link.provider_name = response_data[:provider_name]
link.provider_url = response_data[:provider_url]
link.description = response_data[:description]
link.thumbnail_url = response_data[:thumbnail_url]
link.thumbnail_width = response_data[:thumbnail_width]
link.thumbnail_height = response_data[:thumbnail_height]
link.html = response_data[:html]
link.width = response_data[:width]
link.height = response_data[:height]
link.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment