diff --git a/lib/onebox/engine/audio_com_onebox.rb b/lib/onebox/engine/audio_com_onebox.rb new file mode 100644 index 00000000000..394cab24b26 --- /dev/null +++ b/lib/onebox/engine/audio_com_onebox.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +module Onebox + module Engine + class AudioComOnebox + include Engine + include StandardEmbed + + matches_regexp(%r{^https?://audio\.com}) + requires_iframe_origins "https://audio.com" + always_https + + def to_html + oembed = get_oembed + oembed.html.gsub("visual=true", "visual=false") + end + + def placeholder_html + oembed = get_oembed + return if Onebox::Helpers.blank?(oembed.thumbnail_url) + "" + end + + protected + + def get_oembed_url + oembed_url = "https://api.audio.com/oembed?url=#{url}" + oembed_url += "&maxheight=228" unless url["/collections/"] + oembed_url + end + end + end +end diff --git a/spec/fixtures/onebox/audio_com_audio_oembed.response b/spec/fixtures/onebox/audio_com_audio_oembed.response new file mode 100644 index 00000000000..cf628d9ed75 --- /dev/null +++ b/spec/fixtures/onebox/audio_com_audio_oembed.response @@ -0,0 +1 @@ +{"type":"rich","version":1,"title":"Discourse onebox test audio","author_name":"Roman Agilov","author_url":"https://audio.com/agilov","provider_name":"audio.com","provider_url":"https://audio.com","cache_age":432000,"html":"","width":600,"height":204} diff --git a/spec/fixtures/onebox/audio_com_collection_oembed.response b/spec/fixtures/onebox/audio_com_collection_oembed.response new file mode 100644 index 00000000000..d7dbc0a6f28 --- /dev/null +++ b/spec/fixtures/onebox/audio_com_collection_oembed.response @@ -0,0 +1 @@ +{"type":"rich","version":1,"title":"Discourse test collection","author_name":"Roman Agilov","author_url":"https://audio.com/agilov","provider_name":"audio.com","provider_url":"https://audio.com","cache_age":432000,"html":"","width":600,"height":696} diff --git a/spec/lib/onebox/engine/audio_com_onebox_spec.rb b/spec/lib/onebox/engine/audio_com_onebox_spec.rb new file mode 100644 index 00000000000..3147b26164f --- /dev/null +++ b/spec/lib/onebox/engine/audio_com_onebox_spec.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +RSpec.describe Onebox::Engine::AudioComOnebox do + it "has the iframe with the correct audio" do + stub_request( + :get, + "https://api.audio.com/oembed?maxheight=228&url=https://audio.com/agilov/audio/discourse-onebox-test-audio", + ).to_return(status: 200, body: onebox_response("audio_com_audio_oembed")) + expect( + Onebox.preview("https://audio.com/agilov/audio/discourse-onebox-test-audio").to_s, + ).to match(%r{