Class: Onebox::Engine::AmazonOnebox
Instance Attribute Summary
#errors, #options, #timeout, #uri
Instance Method Summary
collapse
#layout, max_text
all_iframe_origins, engines, included, #initialize, origins_to_regexes
Instance Method Details
#http_params ⇒ Object
46
47
48
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 46
def http_params
{ "User-Agent" => @options[:user_agent] } if @options && @options[:user_agent]
end
|
#placeholder_html ⇒ Object
59
60
61
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 59
def placeholder_html
to_html(true)
end
|
#tld ⇒ Object
42
43
44
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 42
def tld
@tld ||= @@matcher.match(@url)["tld"]
end
|
#to_html(ignore_errors = false) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 50
def to_html(ignore_errors = false)
unless ignore_errors
verified_data return "" unless errors.empty?
end
super()
end
|
#url ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 18
def url
@raw ||= nil
if !@raw && has_cached_body
@raw = Onebox::Helpers.fetch_html_doc(@url, http_params, body_cacher)
end
if @raw
canonical_link = @raw.at('//link[@rel="canonical"]/@href')
return canonical_link.to_s if canonical_link
end
if match && match[:id]
id =
Addressable::URI.encode_component(match[:id], Addressable::URI::CharacterClasses::PATH)
return "https://www.amazon.#{tld}/dp/#{id}"
end
@url
end
|
#verified_data ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/onebox/engine/amazon_onebox.rb', line 63
def verified_data
@verified_data ||=
begin
result = data
required_tags = %i[title description]
required_tags.each do |tag|
if result[tag].blank?
errors[tag] ||= []
errors[tag] << "is blank"
end
end
result
end
@verified_data
end
|