Commit 22c644c2 authored by Tamas Laszlo Fabian's avatar Tamas Laszlo Fabian Committed by Jonne Haß
Browse files

Replaced opengraph with opengraph_parser

Code style fixes
parent 6e4c1fe3
......@@ -59,12 +59,12 @@ gem 'messagebus_ruby_api', '1.0.3'
# Parsing
gem 'nokogiri', '1.6.0'
gem 'rails_autolink', '1.1.0'
gem 'redcarpet', '3.0.0'
gem 'roxml', '3.1.6'
gem 'ruby-oembed', '0.8.8'
gem 'opengraph', '0.0.4'
gem 'nokogiri', '1.6.0'
gem 'rails_autolink', '1.1.0'
gem 'redcarpet', '3.0.0'
gem 'roxml', '3.1.6'
gem 'ruby-oembed', '0.8.8'
gem 'opengraph_parser', '0.2.3'
# Please remove when migrating to Rails 4
......
......@@ -249,10 +249,9 @@ GEM
omniauth-twitter (1.0.0)
multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
opengraph (0.0.4)
hashie
nokogiri (~> 1.5.0)
rest-client (~> 1.6.0)
opengraph_parser (0.2.3)
addressable
nokogiri
orm_adapter (0.4.0)
polyglot (0.3.3)
pry (0.9.12.2)
......@@ -326,8 +325,6 @@ GEM
redis-namespace (1.3.0)
redis (~> 3.0.0)
remotipart (1.2.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rmagick (2.13.2)
roxml (3.1.6)
activesupport (>= 2.3.0)
......@@ -470,7 +467,7 @@ DEPENDENCIES
omniauth-facebook (= 1.4.1)
omniauth-tumblr (= 1.1)
omniauth-twitter (= 1.0.0)
opengraph (= 0.0.4)
opengraph_parser (= 0.2.3)
rack-cors (= 0.2.8)
rack-google-analytics (= 0.11.0)
rack-piwik (= 0.2.2)
......
......@@ -22,28 +22,24 @@ class OpenGraphCache < ActiveRecord::Base
end
def self.find_or_create_by_url(url)
cache = OpenGraphCache.find_or_initialize_by_url(url)
return cache if cache.persisted?
cache.fetch_and_save_opengraph_data!
return cache if cache.persisted?
return nil
cache = OpenGraphCache.find_or_initialize_by_url(url)
cache.fetch_and_save_opengraph_data! unless cache.persisted?
cache if cache.persisted?
end
def fetch_and_save_opengraph_data!
begin
response = OpenGraph.fetch(self.url)
if !response
return
end
rescue => e
# noop
else
self.title = response.title
self.ob_type = response.type
self.image = response.image
self.url = response.url
self.description = response.description
self.save
response = OpenGraph.new(self.url)
if response.blank? || response.type.blank?
return
end
rescue
# noop
else
self.title = response.title
self.ob_type = response.type
self.image = response.images[0]
self.url = response.url
self.description = response.description
self.save
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment