DEV: Replace custom Onebox symbolize_keys implementation with ActiveSupport (#23828)

We have a custom implementation of #symbolize_keys in our Onebox helpers. This is likely a legacy from when Onebox was a standalone gem. This change replaces all usages with either #deep_symbolize_keys from ActiveSupport, or appropriate option to the JSON parser gem used.
This commit is contained in:
Ted Johansson
2023-10-09 09:32:09 +02:00
committed by GitHub
parent c970cbeac4
commit b2a5f5802a
8 changed files with 7 additions and 18 deletions

View File

@@ -76,7 +76,7 @@ module Onebox
script = page.at_css('script[type="application/ld+json"]')
if json_string = script&.text
@og_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(json_string))
@og_data = ::MultiJson.load(json_string, symbolize_keys: true)
else
@og_data = {}
end

View File

@@ -53,7 +53,7 @@ module Onebox
rescue StandardError
"{}"
end
oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
oembed_data = ::MultiJson.load(response, symbolize_keys: true)
imgur_data_id = Nokogiri.HTML(oembed_data[:html]).xpath("//blockquote").attr("data-id")
imgur_data_id.to_s[%r{a/}]
end

View File

@@ -34,7 +34,7 @@ module Onebox
def oembed_data
response = Onebox::Helpers.fetch_response("https://vimeo.com/api/oembed.json?url=#{url}")
@oembed_data = Onebox::Helpers.symbolize_keys(::MultiJson.load(response))
@oembed_data = ::MultiJson.load(response, symbolize_keys: true)
rescue StandardError
"{}"
end