DEV: Make GoogleDocsOnebox use StandardEmbed (#475)

DEV: Make GoogleDocsOnebox use StandardEmbed (#475)

Closes #427

Co-authored-by: Matt Vasquez mattvasquez@gmail.com

diff --git a/lib/onebox/engine/google_docs_onebox.rb b/lib/onebox/engine/google_docs_onebox.rb
index be1ce63..cc7872a 100644
--- a/lib/onebox/engine/google_docs_onebox.rb
+++ b/lib/onebox/engine/google_docs_onebox.rb
@@ -4,6 +4,7 @@ module Onebox
   module Engine
     class GoogleDocsOnebox
       include Engine
+      include StandardEmbed
       include LayoutSupport
 
       SUPPORTED_ENDPOINTS = %w(spreadsheets document forms presentation)
@@ -20,12 +21,19 @@ module Onebox
       private
 
       def data
+        og_data = get_opengraph
         short_type = SHORT_TYPES[match[:endpoint].to_sym]
 
+        description = if Onebox::Helpers.blank?(og_data.description)
+          "This #{short_type.to_s.chop.capitalize} is private"
+        else
+          Onebox::Helpers.truncate(og_data.description, 250)
+        end
+
         {
           link: link,
-          title: og_data[:title] || "Google #{short_type.to_s.capitalize}",
-          description: Onebox::Helpers.truncate(og_data[:description], 250) || "This #{short_type.to_s.chop.capitalize} is private",
+          title: og_data.title || "Google #{short_type.to_s.capitalize}",
+          description: description,
           type: short_type
         }
       end
@@ -33,24 +41,6 @@ module Onebox
       def match
         @match ||= @url.match(@@matcher)
       end
-
-      def og_data
-        return @og_data if defined?(@og_data)
-
-        response = Onebox::Helpers.fetch_response(url, redirect_limit: 10) rescue nil
-        html = Nokogiri::HTML(response)
-        @og_data = {}
-
-        html.css('meta').each do |m|
-          if m.attribute('property')&.to_s&.match(/^og:/i)
-            m_content = m.attribute('content').to_s.strip
-            m_property = m.attribute('property').to_s.gsub('og:', '')
-            @og_data[m_property.to_sym] = m_content
-          end
-        end
-
-        @og_data
-      end
     end
   end
 end

GitHub sha: 71698bd5

This commit appears in #475 which was approved by gschlager. It was merged by CvX.