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'
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
# Don't masquerade as mobile
|
|
|
|
def http_params
|
|
|
|
{}
|
|
|
|
end
|
|
|
|
|
|
|
|
def template
|
|
|
|
template_path('simple_onebox')
|
|
|
|
end
|
2013-02-25 11:42:20 -05:00
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
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
|