FEATURE: add support for reddit posts with image type (#399)

FEATURE: add support for reddit posts with image type (#399)

diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb
index 7a17175..398ad84 100644
--- a/lib/onebox/engine.rb
+++ b/lib/onebox/engine.rb
@@ -186,3 +186,4 @@ require_relative "engine/instagram_onebox"
 require_relative "engine/gitlab_blob_onebox"
 require_relative "engine/google_photos_onebox"
 require_relative "engine/kaltura_onebox"
+require_relative "engine/reddit_image_onebox"
diff --git a/lib/onebox/engine/reddit_image_onebox.rb b/lib/onebox/engine/reddit_image_onebox.rb
new file mode 100644
index 0000000..42fcc75
--- /dev/null
+++ b/lib/onebox/engine/reddit_image_onebox.rb
@@ -0,0 +1,34 @@
+module Onebox
+  module Engine
+    class RedditImageOnebox
+      include Engine
+      include StandardEmbed
+
+      matches_regexp(/^https?:\/\/(www\.)?reddit\.com/)
+
+      def to_html
+        if raw[:type] == "image"
+          <<-HTML
+            <aside class="onebox reddit">
+              <header class="source">
+                <img src="#{raw[:favicon]}" class="site-icon" width="16" height="16">
+                <a href="#{raw[:url]}" target="_blank" rel="nofollow noopener">#{raw[:site_name]}</a>
+              </header>
+              <article class="onebox-body">
+                <h3><a href="#{raw[:url]}" target="_blank" rel="nofollow noopener">#{raw[:title]}</a></h3>
+                <div class="scale-images">
+                  <img src="#{raw[:image]}" class="scale-image"/>
+                </div>
+                <div class="description"><p>#{raw[:description]}</p></div>
+              </article>
+            </aside>
+          HTML
+        else
+          html = Onebox::Engine::WhitelistedGenericOnebox.new(@url, @cache, @timeout).to_html
+          return if Onebox::Helpers.blank?(html)
+          html
+        end
+      end
+    end
+  end
+end
diff --git a/spec/fixtures/reddit_image.response b/spec/fixtures/reddit_image.response
new file mode 100644
index 0000000..b8158ea
--- /dev/null
+++ b/spec/fixtures/reddit_image.response
@@ -0,0 +1,416 @@
+<html lang="en" data-ember-extension="1">
+<head>
+    <link href="//c.aaxads.com/aax.js?pub=AAX763KC6&amp;hst=www.reddit.com&amp;ver=1.2" rel="preload" as="script">
+    <link href="//c.amazon-adsystem.com/aax2/apstag.js" rel="preload" as="script">
+    <link href="//www.googletagservices.com/tag/js/gpt.js" rel="preload" as="script">
+    <title>Literally nothing black edition : colors</title>
+    <meta charset="utf8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="description" content="r/colors: “Mere color, unspoiled by meaning, and unallied with definite form, can speak to the soul in a thousand different ways. ”
+― Oscar Wilde">
+    <link rel="canonical" href="https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition/">
+    <meta property="og:ttl" content="600">
+    <meta property="og:site_name" content="reddit">
+    <meta property="twitter:site" content="@reddit">
+    <meta property="twitter:card" content="summary">
+    <meta property="og:title" content="r/colors - Literally nothing black edition">
+    <meta property="twitter:title" content="r/colors - Literally nothing black edition">
+    <meta property="og:type" content="image">
+    <meta property="og:url" content="https://www.reddit.com/r/colors/comments/b4d5xm/literally_nothing_black_edition/">
+    <meta property="og:description" content="4 votes and 1 comment so far on Reddit">
+    <meta property="og:image" content="https://preview.redd.it/vsg59iw0srn21.jpg?auto=webp&amp;s=e19452b85c0aa8e3563cb1006a36eb914abfdec7">
+    <meta property="og:image:width" content="3024">
+    <meta property="og:image:height" content="4032">
+    <meta property="twitter:image" content="https://preview.redd.it/vsg59iw0srn21.jpg?auto=webp&amp;s=e19452b85c0aa8e3563cb1006a36eb914abfdec7">
+    <link rel="apple-touch-icon" sizes="57x57" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-57x57.png">
+    <link rel="apple-touch-icon" sizes="60x60" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-60x60.png">
+    <link rel="apple-touch-icon" sizes="72x72" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-72x72.png">
+    <link rel="apple-touch-icon" sizes="76x76" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-76x76.png">
+    <link rel="apple-touch-icon" sizes="114x114" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-114x114.png">
+    <link rel="apple-touch-icon" sizes="120x120" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-120x120.png">
+    <link rel="apple-touch-icon" sizes="144x144" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-144x144.png">
+    <link rel="apple-touch-icon" sizes="152x152" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-152x152.png">
+    <link rel="apple-touch-icon" sizes="180x180" href="https://www.redditstatic.com/desktop2x/img/favicon/apple-icon-180x180.png">
+    <link rel="icon" type="image/png" sizes="192x192" href="https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png">
+    <link rel="icon" type="image/png" sizes="32x32" href="https://www.redditstatic.com/desktop2x/img/favicon/favicon-32x32.png">
+    <link rel="icon" type="image/png" sizes="96x96" href="https://www.redditstatic.com/desktop2x/img/favicon/favicon-96x96.png">
+    <link rel="icon" type="image/png" sizes="16x16" href="https://www.redditstatic.com/desktop2x/img/favicon/favicon-16x16.png">
+    <link rel="manifest" href="https://www.redditstatic.com/desktop2x/img/favicon/manifest.json">
+    <meta name="msapplication-TileColor" content="#ffffff">
+    <meta name="msapplication-TileImage" content="https://www.redditstatic.com/desktop2x/img/favicon/ms-icon-144x144.png">
+    <meta name="theme-color" content="#ffffff">
+    <meta name="jsapi">
+<body>
+    <iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="0" width="0" id="aax_prefetch_frame" sandbox="allow-same-origin allow-forms allow-popups allow-scripts allow-pointer-lock allow-popups-to-escape-sandbox" src="https://redditad.com/display.html?&amp;_otarOg=https%3A%2F%2Fwww.reddit.com&amp;_cpub=AAX763KC6&amp;_csvr=2019032812_578&amp;_cgdpr=1&amp;_cgdprconsent=0" name="{&quot;fid&quot;:1,&quot;type&quot;:&quot;prefetch_frame&quot;}" style="display: none !important;"></iframe>
+    <iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="0" width="0" id="cok_aax" src="https://c.aaxads.com/aacxs.php?&amp;yvVbqf=1&amp;fv=1&amp;ke=1&amp;fy=37&amp;qghf=1&amp;flg=AAX763KC6&amp;suylg=33%2C38%2C41%2C51%2C55%2C80%2C82%2C89%2C90%2C97%2C109%2C113%2C114%2C117%2C122%2C141%2C145%2C155%2C157%2C161%2C167%2C172%2C3004&amp;uwlph=75&amp;kwwsv=1&amp;gdpr=1&amp;gdprconsent=0" style="display: none !important;"></iframe>
+    <iframe marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="0" width="0" id="aax_if_detect" src="https://aaxdetect.com/detect.html?&amp;pub=AAX763KC6&amp;svr=2019032812_578&amp;gdpr=1&amp;gdprconsent=0&amp;dn=https%3A%2F%2Fwww.reddit.com" style="display: none !important;"></iframe>
+    <script>
+        __perfMark('app_html_start');
+    </script>
+    <div id="2x-container">
+        <div class="xvmxia-0 PrKco">
+            <div tabindex="-1">
+                <div class="_1gsAk1ihQliBnDybgyjghy" id="SHORTCUT_FOCUSABLE_DIV" tabindex="-1">
+                    <div class="SubredditVars-r-colors">
+                        <header class="_2GyPfdsi-MbQFyHRECo9GO cx1ohrUAq6ARaXTX2u8YN  s4rdgu3-0 eAICLF s1ipn2bl-0 dPRCBc" data-redditstyle="true">
+                            <div class="_2vkeRJojnV7cb9pMlPHy7d">
+                                <div class="_3dnbqz69WJTFCss8wl7Wlk"><span class="s1dqr9jy-0 imyGpC">Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts</span>
+                                    <a aria-label="Home" class="_30BbATRhFv3V83DHNDjJAO" href="/">

[... diff too long, it was truncated ...]

GitHub sha: 8e8185f4