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


4
5
6
7
# File 'app/presenters/o_embed_presenter.rb', line 4

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

Class Method Details

.id_from_url(url) ⇒ Object


28
29
30
# File 'app/presenters/o_embed_presenter.rb', line 28

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

Instance Method Details

#as_json(opts = {}) ⇒ Object


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

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


44
45
46
# File 'app/presenters/o_embed_presenter.rb', line 44

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

#post_authorObject


36
37
38
# File 'app/presenters/o_embed_presenter.rb', line 36

def 
  @post.author_name
end

#post_author_urlObject


40
41
42
# File 'app/presenters/o_embed_presenter.rb', line 40

def 
 Rails.application.routes.url_helpers.person_url(@post.author, :host => AppConfig.pod_uri.host)
end

#post_titleObject


32
33
34
# File 'app/presenters/o_embed_presenter.rb', line 32

def post_title
  post_page_title(@post)
end

#to_json(opts = {}) ⇒ Object


9
10
11
# File 'app/presenters/o_embed_presenter.rb', line 9

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