Class: OEmbedPresenter

Inherits:
Object
  • Object
show all
Includes:
PostsHelper
Defined in:
app/presenters/o_embed_presenter.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PostsHelper

#post_iframe_url, #post_page_title

Constructor Details

#initialize(post, opts = {}) ⇒ OEmbedPresenter

Returns a new instance of OEmbedPresenter.


6
7
8
9
# File 'app/presenters/o_embed_presenter.rb', line 6

def initialize(post, opts = {})
  @post = post
  @opts = opts
end

Class Method Details

.id_from_url(url) ⇒ Object


30
31
32
# File 'app/presenters/o_embed_presenter.rb', line 30

def self.id_from_url(url)
  URI.parse(url).path.gsub(%r{\/posts\/|\/p\/}, '')
end

Instance Method Details

#as_json(opts = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/presenters/o_embed_presenter.rb', line 15

def as_json(opts={})
  {
    :provider_name => "Diaspora",
    :provider_url => AppConfig.pod_uri.to_s,
    :type => 'rich',
    :version => '1.0',
    :title => post_title,
    :author_name => ,
    :author_url => ,
    :width => @opts.fetch(:maxwidth, 516),
    :height => @opts.fetch(:maxheight, 320),
    :html => iframe_html
  }
end

#iframe_htmlObject


46
47
48
# File 'app/presenters/o_embed_presenter.rb', line 46

def iframe_html
  post_iframe_url(@post.id, :height => @opts[:maxheight], :width => @opts[:maxwidth])
end

#post_authorObject


38
39
40
# File 'app/presenters/o_embed_presenter.rb', line 38

def 
  @post.author_name
end

#post_author_urlObject


42
43
44
# File 'app/presenters/o_embed_presenter.rb', line 42

def 
  AppConfig.url_to(Rails.application.routes.url_helpers.person_path(@post.author))
end

#post_titleObject


34
35
36
# File 'app/presenters/o_embed_presenter.rb', line 34

def post_title
  post_page_title(@post)
end

#to_json(opts = {}) ⇒ Object


11
12
13
# File 'app/presenters/o_embed_presenter.rb', line 11

def to_json(opts={})
  as_json(opts).to_json
end