summaryrefslogtreecommitdiff
path: root/users/lib/webfinger/user_presenter.rb
blob: 8288bff774c2b8ca06698345f3bb980aa14cc70f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Webfinger::UserPresenter
  include Rails.application.routes.url_helpers
  attr_accessor :subject

  def initialize(subject, request)
    @subject = subject
    @request = request
  end

  def email_identifier
    "#{@subject.username}@#{@request.host}"
  end

  def key
    if @subject.public_key.present?
      Base64.encode64(@subject.public_key.to_s)
    end
  end

  def links
    links = {}
    links[:public_key] = { type: 'PGP', href: key } if key
    return links
  end

  def to_json(options)
    {
      subject: "acct:#{email_identifier}",
      aliases: [ user_url(@subject, :host => @request.host) ],
      links:   links
    }.to_json(options)
  end

end