diff options
author | Jenkins <jenkins@jenkins.ninjawedding.org> | 2017-12-13 18:17:16 +0000 |
---|---|---|
committer | Jenkins <jenkins@jenkins.ninjawedding.org> | 2017-12-13 18:17:16 +0000 |
commit | 82236a37039043d134efb3ddbdd2a3e04e714e2c (patch) | |
tree | c00cd712a172ac3d5865e94bc505590fa211ecd5 /app/lib | |
parent | 65d083338debc256360fd6052ec43b98c442320c (diff) | |
parent | 72314d26aeef0b225401d3f0ad97ea948c66f423 (diff) |
Merge remote-tracking branch 'tootsuite/master' into glitchsoc/master
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/provider_discovery.rb | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/app/lib/provider_discovery.rb b/app/lib/provider_discovery.rb index bcc4ed500..04ba38101 100644 --- a/app/lib/provider_discovery.rb +++ b/app/lib/provider_discovery.rb @@ -2,13 +2,26 @@ class ProviderDiscovery < OEmbed::ProviderDiscovery class << self + def get(url, **options) + provider = discover_provider(url, options) + + options.delete(:html) + + provider.get(url, options) + end + def discover_provider(url, **options) - res = Request.new(:get, url).perform format = options[:format] - raise OEmbed::NotFound, url if res.code != 200 || res.mime_type != 'text/html' + if options[:html] + html = Nokogiri::HTML(options[:html]) + else + res = Request.new(:get, url).perform + + raise OEmbed::NotFound, url if res.code != 200 || res.mime_type != 'text/html' - html = Nokogiri::HTML(res.to_s) + html = Nokogiri::HTML(res.to_s) + end if format.nil? || format == :json provider_endpoint ||= html.at_xpath('//link[@type="application/json+oembed"]')&.attribute('href')&.value |