diff --git a/lib/onebox/engine.rb b/lib/onebox/engine.rb index 1b2448dc37d..cdd3adc2451 100644 --- a/lib/onebox/engine.rb +++ b/lib/onebox/engine.rb @@ -171,7 +171,7 @@ require_relative "engine/imgur_onebox" require_relative "engine/pastebin_onebox" require_relative "engine/slides_onebox" require_relative "engine/xkcd_onebox" -require_relative "engine/giphy_onebox" +require_relative "engine/animated_image_onebox" require_relative "engine/gfycat_onebox" require_relative "engine/typeform_onebox" require_relative "engine/vimeo_onebox" diff --git a/lib/onebox/engine/animated_image_onebox.rb b/lib/onebox/engine/animated_image_onebox.rb new file mode 100644 index 00000000000..6ef2fe478de --- /dev/null +++ b/lib/onebox/engine/animated_image_onebox.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Onebox + module Engine + class AnimatedImageOnebox + include Engine + include StandardEmbed + + matches_regexp(/^https?:\/\/.*(giphy\.com|gph\.is|tenor\.com)\//) + always_https + + def to_html + og = get_opengraph + "" + end + end + end +end diff --git a/lib/onebox/engine/giphy_onebox.rb b/lib/onebox/engine/giphy_onebox.rb deleted file mode 100644 index 569f423451d..00000000000 --- a/lib/onebox/engine/giphy_onebox.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module Onebox - module Engine - class GiphyOnebox - include Engine - include StandardEmbed - - matches_regexp(/^https?:\/\/(giphy\.com\/gifs|gph\.is)\//) - always_https - - def to_html - oembed = get_oembed - - <<-HTML - - - - HTML - end - end - end -end diff --git a/spec/fixtures/onebox/giphy.response b/spec/fixtures/onebox/giphy.response new file mode 100644 index 00000000000..f21f475a77a --- /dev/null +++ b/spec/fixtures/onebox/giphy.response @@ -0,0 +1,335 @@ + + + + + + + + + + Happy So Excited GIF - Find & Share on GIPHY + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+
+ + +
+
+ +
+ + + + +
+ + + + + + + + +
+ +
+
+ + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/onebox/tenor.response b/spec/fixtures/onebox/tenor.response new file mode 100644 index 00000000000..66312c6cbea --- /dev/null +++ b/spec/fixtures/onebox/tenor.response @@ -0,0 +1,3 @@ + +Dance Happy GIF - Dance Happy Snoopy - Discover & Share GIFs

Dance Happy GIF

Dance Happy GIF - Dance Happy Snoopy GIFs
CAPTION

Share URL



Embed

Details

File Size1667KB
Duration1.800 sec
Dimensions498x476
Created10/6/2019, 7:27:50 PM
\ No newline at end of file diff --git a/spec/lib/onebox/engine/animated_image_onebox_spec.rb b/spec/lib/onebox/engine/animated_image_onebox_spec.rb new file mode 100644 index 00000000000..7b4f610f291 --- /dev/null +++ b/spec/lib/onebox/engine/animated_image_onebox_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require "rails_helper" + +describe Onebox::Engine::AnimatedImageOnebox do + let(:giphy) { "http://gph.is/15bRbWf" } + let(:tenor) { "https://tenor.com/bb3fQ.gif" } + + before do + @previous_options = Onebox.options.to_h + Onebox.options = { redirect_limit: 0 } + stub_request(:get, giphy).to_return(status: 200, body: onebox_response("giphy")) + stub_request(:get, tenor).to_return(status: 200, body: onebox_response("tenor")) + end + + after do + Onebox.options = @previous_options + end + + it "works for giphy short URLs" do + html = described_class.new(giphy).to_html + expect(html).to include("img") + expect(html).to include("class='animated onebox'") + end + + it "works for tenor URLs" do + html = described_class.new(tenor).to_html + expect(html).to include("img") + expect(html).to include("class='animated onebox'") + end +end