Created
December 29, 2013 07:45
-
-
Save xdite/8168404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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