mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 07:03:44 +08:00
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:
parent
9a3f18f9bc
commit
3eac47443f
33
lib/onebox/engine/audio_com_onebox.rb
Normal file
33
lib/onebox/engine/audio_com_onebox.rb
Normal 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
|
1
spec/fixtures/onebox/audio_com_audio_oembed.response
vendored
Normal file
1
spec/fixtures/onebox/audio_com_audio_oembed.response
vendored
Normal 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}
|
1
spec/fixtures/onebox/audio_com_collection_oembed.response
vendored
Normal file
1
spec/fixtures/onebox/audio_com_collection_oembed.response
vendored
Normal 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}
|
23
spec/lib/onebox/engine/audio_com_onebox_spec.rb
Normal file
23
spec/lib/onebox/engine/audio_com_onebox_spec.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user