Skip to content
Extraits de code Groupes Projets
Valider 22c644c2 rédigé par Tamas Laszlo Fabian's avatar Tamas Laszlo Fabian Validation de Jonne Haß
Parcourir les fichiers

Replaced opengraph with opengraph_parser

Code style fixes
parent 6e4c1fe3
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -59,12 +59,12 @@ gem 'messagebus_ruby_api', '1.0.3' ...@@ -59,12 +59,12 @@ gem 'messagebus_ruby_api', '1.0.3'
# Parsing # Parsing
gem 'nokogiri', '1.6.0' gem 'nokogiri', '1.6.0'
gem 'rails_autolink', '1.1.0' gem 'rails_autolink', '1.1.0'
gem 'redcarpet', '3.0.0' gem 'redcarpet', '3.0.0'
gem 'roxml', '3.1.6' gem 'roxml', '3.1.6'
gem 'ruby-oembed', '0.8.8' gem 'ruby-oembed', '0.8.8'
gem 'opengraph', '0.0.4' gem 'opengraph_parser', '0.2.3'
# Please remove when migrating to Rails 4 # Please remove when migrating to Rails 4
......
...@@ -249,10 +249,9 @@ GEM ...@@ -249,10 +249,9 @@ GEM
omniauth-twitter (1.0.0) omniauth-twitter (1.0.0)
multi_json (~> 1.3) multi_json (~> 1.3)
omniauth-oauth (~> 1.0) omniauth-oauth (~> 1.0)
opengraph (0.0.4) opengraph_parser (0.2.3)
hashie addressable
nokogiri (~> 1.5.0) nokogiri
rest-client (~> 1.6.0)
orm_adapter (0.4.0) orm_adapter (0.4.0)
polyglot (0.3.3) polyglot (0.3.3)
pry (0.9.12.2) pry (0.9.12.2)
...@@ -326,8 +325,6 @@ GEM ...@@ -326,8 +325,6 @@ GEM
redis-namespace (1.3.0) redis-namespace (1.3.0)
redis (~> 3.0.0) redis (~> 3.0.0)
remotipart (1.2.1) remotipart (1.2.1)
rest-client (1.6.7)
mime-types (>= 1.16)
rmagick (2.13.2) rmagick (2.13.2)
roxml (3.1.6) roxml (3.1.6)
activesupport (>= 2.3.0) activesupport (>= 2.3.0)
...@@ -470,7 +467,7 @@ DEPENDENCIES ...@@ -470,7 +467,7 @@ DEPENDENCIES
omniauth-facebook (= 1.4.1) omniauth-facebook (= 1.4.1)
omniauth-tumblr (= 1.1) omniauth-tumblr (= 1.1)
omniauth-twitter (= 1.0.0) omniauth-twitter (= 1.0.0)
opengraph (= 0.0.4) opengraph_parser (= 0.2.3)
rack-cors (= 0.2.8) rack-cors (= 0.2.8)
rack-google-analytics (= 0.11.0) rack-google-analytics (= 0.11.0)
rack-piwik (= 0.2.2) rack-piwik (= 0.2.2)
......
...@@ -22,28 +22,24 @@ class OpenGraphCache < ActiveRecord::Base ...@@ -22,28 +22,24 @@ class OpenGraphCache < ActiveRecord::Base
end end
def self.find_or_create_by_url(url) def self.find_or_create_by_url(url)
cache = OpenGraphCache.find_or_initialize_by_url(url) cache = OpenGraphCache.find_or_initialize_by_url(url)
return cache if cache.persisted? cache.fetch_and_save_opengraph_data! unless cache.persisted?
cache.fetch_and_save_opengraph_data! cache if cache.persisted?
return cache if cache.persisted?
return nil
end end
def fetch_and_save_opengraph_data! def fetch_and_save_opengraph_data!
begin response = OpenGraph.new(self.url)
response = OpenGraph.fetch(self.url) if response.blank? || response.type.blank?
if !response return
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
end 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
end end
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter