discourse/lib/oneboxer/apple_app_onebox.rb

38 lines
676 B
Ruby
Raw Normal View History

2013-02-05 14:16:51 -05:00
require_dependency 'oneboxer/handlebars_onebox'
module Oneboxer
class AppleAppOnebox < HandlebarsOnebox
matcher /^https?:\/\/itunes\.apple\.com\/.+$/
favicon 'apple.png'
# Don't masquerade as mobile
def http_params
{}
end
def template
template_path('simple_onebox')
end
def parse(data)
2013-02-12 09:46:45 -05:00
html_doc = Nokogiri::HTML(data)
2013-02-05 14:16:51 -05:00
result = {}
2013-02-12 09:46:45 -05:00
m = html_doc.at("h1")
2013-02-05 14:16:51 -05:00
result[:title] = m.inner_text if m
2013-02-12 09:46:45 -05:00
m = html_doc.at("h4 ~ p")
2013-02-05 14:16:51 -05:00
result[:text] = m.inner_text[0..MAX_TEXT] if m
2013-02-12 09:46:45 -05:00
m = html_doc.at(".product img.artwork")
2013-02-05 14:16:51 -05:00
result[:image] = m['src'] if m
result
end
end
end