Class: Onebox::Engine::AmazonOnebox
Constant Summary
DEFAULT
Instance Attribute Summary
#errors, #timeout, #uri
Instance Method Summary
collapse
#layout, max_text, #to_html
all_iframe_origins, engines, included, #initialize, #options, #options=, origins_to_regexes, #placeholder_html, #to_html
Instance Method Details
#http_params ⇒ Object
44
45
46
47
48
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 44
def http_params
if @options && @options[:user_agent]
{ 'User-Agent' => @options[:user_agent] }
end
end
|
#tld ⇒ Object
40
41
42
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 40
def tld
@tld ||= @@matcher.match(@url)["tld"]
end
|
#url ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 16
def url
@raw ||= nil
if body_cacher&.respond_to?('cache_response_body?')
if body_cacher.cache_response_body?(uri.to_s) && body_cacher.cached_response_body_exists?(uri.to_s)
@raw ||= Onebox::Helpers.fetch_html_doc(@url, http_params, body_cacher)
end
end
if @raw
canonical_link = @raw.at('//link[@rel="canonical"]/@href')
return canonical_link.to_s if canonical_link
end
if match && match[:id]
return "https://www.amazon.#{tld}/dp/#{Onebox::Helpers.uri_encode(match[:id])}"
end
@url
end
|