FEATURE: Onebox for Embed Motoko (#19293)

This commit is contained in:
Ryan Vandersmith 2022-12-16 07:59:40 -07:00 committed by GitHub
parent 2d628c80a1
commit e6439e89cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -211,3 +211,4 @@ require_relative "engine/reddit_media_onebox"
require_relative "engine/google_drive_onebox"
require_relative "engine/facebook_media_onebox"
require_relative "engine/hackernews_onebox"
require_relative "engine/motoko_onebox"

View File

@ -0,0 +1,28 @@
# frozen_string_literal: true
module Onebox
module Engine
class MotokoOnebox
include Engine
include StandardEmbed
matches_regexp(/^https?:\/\/embed\.smartcontracts\.org\/?.*/)
requires_iframe_origins "https://embed.smartcontracts.org"
always_https
def to_html
get_oembed.html
end
def placeholder_html
::Onebox::Helpers.generic_placeholder_html
end
protected
def get_oembed_url
"https://embed.smartcontracts.org/api/onebox?url=#{url}"
end
end
end
end

View File

@ -0,0 +1,16 @@
# frozen_string_literal: true
RSpec.describe Onebox::Engine::MotokoOnebox do
before do
body = '{"version":"1.0","provider_name":"Embed Motoko","provider_url":"https://embed.smartcontracts.org","type":"rich","width":800,"height":500,"html":"<iframe src=\"https://embed.smartcontracts.org\" width=\"800\" height=\"500\" style=\"border:0\" />"}'
stub_request(:get, "https://embed.smartcontracts.org/api/onebox?url=https://embed.smartcontracts.org")
.to_return(status: 200, body: body, headers: {})
end
it "returns the expected iframe markup" do
expect(Onebox.preview('https://embed.smartcontracts.org').to_s.chomp).to include(
'<iframe src="https://embed.smartcontracts.org" width="800" height="500" style="border:0"'
)
end
end