Sha256: 39df4e3201f09e6ba3a5b1897e4711dfa3d5cd593fe645d2c1ed6cdb946aa225

Contents?: true

Size: 1.08 KB

Versions: 6

Compression:

Stored size: 1.08 KB

Contents

class Link < ActiveRecord::Base
  include SocialStream::Models::Object

  validates_presence_of :url

  attr_accessor :loaded

  before_create :check_loaded

  define_index do
    indexes title
    indexes description
    indexes url

    has created_at
  end

  def fill linkser_object
    self.title = linkser_object.title if linkser_object.title
    self.description = linkser_object.description if linkser_object.description
    self.url = linkser_object.last_url
    r = linkser_object.resource
    if r and r.type and r.url      
      self.callback_url = r.url
    end
    if linkser_object.ogp and linkser_object.ogp.image
      self.image = linkser_object.ogp.image
    elsif linkser_object.images and linkser_object.images.first
      self.image = linkser_object.images.first.url
    end
  end

  def check_loaded
    if !self.loaded.eql? "true" and self.title.nil? and self.description.nil? and self.image.nil?
      begin
        o = Linkser.parse self.url, {:max_images => 1}
        if o.is_a? Linkser::Objects::HTML
          self.fill o
        end
      rescue
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
social_stream-0.15.8 linkser/app/models/link.rb
social_stream-0.15.7 linkser/app/models/link.rb
social_stream-0.15.6 linkser/app/models/link.rb
social_stream-linkser-0.0.6 app/models/link.rb
social_stream-0.15.5 linkser/app/models/link.rb
social_stream-linkser-0.0.5 app/models/link.rb