summaryrefslogtreecommitdiff
path: root/users/lib/webfinger/user_presenter.rb
blob: 8184c52eefec64c000e1ad99356b0918104e9dca (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
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
    Base64.encode64(@subject.public_key.to_s)
  end

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

end