app/services/prezi.rb
class Prezi
DOMAIN = 'prezi.com'.freeze
URL = "https://#{DOMAIN}".freeze
def self.frame(code)
"<iframe src=\"#{URL}/embed/#{code}/?bgcolor=ffffff&
lock_to_path=0&autoplay=0&autohide_ctrls=0#\"
allowfullscreen=\"\" mozallowfullscreen=\"\"
webkitallowfullscreen=\"\"></iframe>"
end
def self.extract(url)
begin
code = url.split('/')[3]
record = MultiJson.load(
URI.parse("#{URL}/api/embed/?id=#{code}").open
)
rescue OpenURI::HTTPError
record = nil
end
fields(record)
end
def self.fields(record)
return unless record
return if record['error_code']
presentation = record['presentation']
{ title: presentation['title'], code: presentation['oid'],
thumbnail: presentation['thumb_url'],
description: presentation['description'] }
end
end