FEATURE: Add audio.com onebox provider (#22936)

* Audio.com provider added to onebox
* added specs for audio.com onebox provider
This commit is contained in:
Roman Agilov 2023-08-08 09:55:04 +03:00 committed by GitHub
parent 9a3f18f9bc
commit 3eac47443f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 58 additions and 0 deletions

View File

@ -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)
"<img src='#{oembed.thumbnail_url}' #{oembed.title_attr}>"
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

View File

@ -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":"<iframe src=\"https://audio.com/embed/audio/1773123508340882?theme=image\" width=\"600\" height=\"204\" style=\"border-radius: 6px; border: none; height: 204px; width: 600px;\"></iframe>","width":600,"height":204}

View File

@ -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":"<iframe src=\"https://audio.com/embed/collection/1773124246389900?theme=image\" width=\"600\" height=\"696\" style=\"border-radius: 6px; border: none; height: 696px; width: 600px;\" allowtransparency=\"true\"></iframe>","width":600,"height":696}

View File

@ -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{<iframe src="https://audio\.com/embed/audio/1773123508340882})
end
it "has the iframe with the correct collection" do
stub_request(
:get,
"https://api.audio.com/oembed?url=https://audio.com/agilov/collections/discourse-test-collection",
).to_return(status: 200, body: onebox_response("audio_com_collection_oembed"))
expect(
Onebox.preview("https://audio.com/agilov/collections/discourse-test-collection").to_s,
).to match(%r{<iframe src="https://audio\.com/embed/collection/1773124246389900})
end
end