basic oembed provider set up... too tried to finish this now

This commit is contained in:
Maxwell Salzberg 2012-04-17 23:14:45 -07:00
parent a307b60dd2
commit 31172a9959
3 changed files with 51 additions and 1 deletions

View file

@ -20,6 +20,6 @@ module PostsHelper
def post_iframe_url(post_id, opts={}) def post_iframe_url(post_id, opts={})
opts[:width] ||= 516 opts[:width] ||= 516
opts[:height] ||= 315 opts[:height] ||= 315
"<iframe src='#{post_url(post_id)}' width='#{opts[:width]}px' height='#{opts[:height]}px' frameBorder='0'></iframe>".html_safe "<iframe src='#{Rails.application.routes.url_helpers.post_url(post_id)}' width='#{opts[:width]}px' height='#{opts[:height]}px' frameBorder='0'></iframe>".html_safe
end end
end end

View file

@ -0,0 +1,44 @@
class OEmbedPresenter
include PostsHelper
def initialize(post, opts = {})
@post = post
@opts = opts
end
def to_json(opts={})
as_json(opts).to_json
end
def as_json(opts)
{
:provider_name => "Diaspora",
:provider_url => AppConfig[:pod_url],
:version => '1.0',
:title => post_title,
:author_name => post_author,
:author_url => post_author_url,
:width => @opts.fetch(:height, 516),
:height => @opts.fetch(:width, 320),
:html => iframe_html
}
end
private
def post_title
@post.text
end
def post_author
@post.author.name
end
def post_author_url
Rails.application.routes.url_helpers.person_url(@post.author)
end
def iframe_html
post_iframe_url(@post.id)
end
end

View file

@ -0,0 +1,6 @@
require 'spec_helper'
describe OEmbedPresenter do
it 'works' do
OEmbedPresenter.new(Factory(:status_message)).to_json.should_not be_nil
end
end